maptool icon indicating copy to clipboard operation
maptool copied to clipboard

[Feature]: Bulk operation for loading a table

Open kwvanderlinde opened this issue 2 months ago • 2 comments

Describe the Problem

Updating large tables one item at a time can be extremely slow. This is largely because table state has to be synced to the server on every change. But when updating entries in a tight loop, I'm not actually interested in all those syncs and would instead like to update the table once, with one server sync at the end.

The Solution you'd like

Add a macro function loadTable(table, data). The data parameter is a JSON array of data to add to the table as rows. Each row is represented as a JSON array with these elements:

  • 0 (int): The lower range of the row's roll
  • 1 (int): The upper range of the row's roll
  • 2 (string): The value of the roll
  • 3 (string): The asset URL to use as the image of the roll.

Existing data would not be overwritten. If that is needed, the clearTable() function should be called first.

Alternatives that you've considered.

No response

Additional Context

I pulled this from Az's PR #4770 for #4769.

kwvanderlinde avatar Oct 17 '25 20:10 kwvanderlinde

As mentioned, I pulled this concept for loadTable() directly out of a PR. I would suggest the following changes though:

  • Name it something like addTableEntries() to make it clear that this won't overwrite existing entries, only add new ones.
  • Allow the rows to have 2, 3, or 4 elements, since the value and image are both optional. Would also need to explicitly support json.null or perhaps empty strings for the 3rd and 4th elements in case one or the other needs to be provided.

Otherwise, I think the original concept was pretty solid.

kwvanderlinde avatar Oct 18 '25 00:10 kwvanderlinde

I agree that addTableEntries() is a better name since loadTable() can be read as extractive.

On the potential for additional elements... Would be nice if they could be more flexible. Like maybe sound or video assets... or additional images... without having to resort to using hacks to shoehorn them in. ;)

FullBleed avatar Oct 18 '25 03:10 FullBleed