loathers / TourGuide

Relay script for KoLmafia, for the web game Kingdom of Loathing. Gives advice on how to play.
The Unlicense
14 stars 17 forks source link

Collapse tiles to bottom of section #154

Closed plasticmacaroni closed 1 year ago

plasticmacaroni commented 1 year ago

Testing this functionality -- attempt is to move tiles to the bottom of each section when collapsed.

I've also added the solid border to the top of all tiles for now, otherwise, there's inconsistency when they're moved below.

plasticmacaroni commented 1 year ago

When uncollapsing a section, it is not brought back to the original position, which is probably functionality that users would expect. However, this would require tracking a tile's position with some variable, and as I understand it, tile order could change as context updates. Not sure what the best approach would be.

plasticmacaroni commented 1 year ago

Elements now get a data attribute that stores their original position, and are returned to that position in the overall list of tiles when uncollapsed. Still hunting for bugs with this implementation, but it was only 4 more lines of code.

plasticmacaroni commented 1 year ago

If items are removed from the tileset, the insert index can go out of bounds.

Working on a commit to insert either at the original position, or if it is past the total number of tiles, insert at the last possible position.

plasticmacaroni commented 1 year ago

Actually, I take that back. The insertBefore function does not throw an error if you try to insert before an index that does not exist. Instead, if the index provided is out of bounds, it will default to appending the element at the end of the parent element. When the tile is collapsed again, it stores a new data attribute pointing to its new location, as well.

It appears insertBefore works like this:

I can't find a way to throw an error even with constantly changing/disappearing tiles. The worst that could happen is that a tile could return to a position it wouldn't naturally occur at, with a slight offset, which doesn't seem like an issue to me.