Changing LuaCustomChartTag::position to writable? Or?

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Changing LuaCustomChartTag::position to writable? Or?

Post by Schallfalke »

It seems LuaCustomChartTag::position is read-only?

https://lua-api.factorio.com/latest/Lua ... rtTag.html shows:

Code: Select all

class LuaCustomChartTag
...
position :: Position [R]	The position of this tag.
...
My use case is that I want to make a mod that auto-align chart tags to chunks, so the icons will tile nicely on the map.
So I can imagine of the following ways to achieve this:
  1. API allows write to "position". So I can simply change that on event "on_chart_tag_added".
  2. API adds a new event "on_pre_chart_tag_added", so I can modify that before it is read-only.
  3. Within event "on_chart_tag_added", I will clone the tag, modify the value, then use "force.add_chart_tag(surface, newtag)". Then destroy the "old" tag.
However, I am not so successful with that. Reasons are:
Method 3 has the problem of recursive calling... Using "force.add_chart_tag(surface, newtag)" will trigger another event "on_chart_tag_added". There seems to be no way to distinguish if the tag is created by script or by actual player clicking on map.
Method 1 and 2 both require API changes.

TL;DR
So if there are other workarounds, may I request either of these API changes:
  1. LuaCustomChartTag::position is also writable. (Thus [RW].)
  2. New event "on_pre_chart_tag_added", which is executed before a tag is really added to the map. Most importantly, "position" can be modified in this event.
Regards,
Schall

pleegwat
Filter Inserter
Filter Inserter
Posts: 255
Joined: Fri May 19, 2017 7:31 pm
Contact:

Re: Changing LuaCustomChartTag::position to writable? Or?

Post by pleegwat »

How about before replacing the new tag, check if it is already chunk-aligned?

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: Changing LuaCustomChartTag::position to writable? Or?

Post by Schallfalke »

pleegwat wrote:
Mon Jul 29, 2019 5:28 pm
How about before replacing the new tag, check if it is already chunk-aligned?
Let me show my code of method 3:

Code: Select all

  local area = { {npos.x - 0.1, npos.y - 0.1}, {npos.x + 0.1, npos.y + 0.1} }
  if next(force.find_chart_tags(surface, area)) == nil then
    force.add_chart_tag(surface, newtag)
    tag.destroy()
  end
If position is the only thing to modify, this above check works.
BUT if I want to other changes (like appending to text with coordinates "(xxx,yyy)", the above checks will also skip those "accurately clicked" tags. So users will find some tags are lacking that text info.

Post Reply

Return to “Modding interface requests”