Changing LuaCustomChartTag::position to writable? Or?

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: 278
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.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1765
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Allow writing to LuaCustomChartTag::position

Post by Pi-C »

Moving a LuaCustomChartTag around is easy for players (click on the tag, then on the button next to the trash-can icon), but impossible for mods:

Currently, if we want to move a LuaCustomChartTag, we cannot simply change its position because LuaCustomChartTag::position is a read-only value. Instead, we have to destroy the existing tag and recreate it on the new position. This is not really efficient, because the game has to deal with more objects and will also raise more events (on_chart_tag_removed and on_chart_tag_added vs. just on_chart_tag_modified).

As players are allowed to move a chart tag, I suppose the game must already have a way to modify the chart tag position. Could you make LuaCustomChartTag::position writable, please, so that mods can move chart tags as well?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Bilka
Factorio Staff
Factorio Staff
Posts: 3541
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post by Bilka »

Okay, added LuaCustomChartTag::position and surface write for 2.0.67.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Pi-C
Smart Inserter
Smart Inserter
Posts: 1765
Joined: Sun Oct 14, 2018 8:13 am
Contact:

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

Post by Pi-C »

Great news, thank you very much! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Post Reply

Return to “Implemented mod requests”