Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified way to specify sort order for data prototype iteration #305

Closed
Ruin0x11 opened this issue Apr 23, 2021 · 0 comments · Fixed by #357
Closed

Unified way to specify sort order for data prototype iteration #305

Ruin0x11 opened this issue Apr 23, 2021 · 0 comments · Fixed by #357
Labels
data Concerns adding new content refactoring This requires refactoring existing code standardization Concerns conventions that should be strongly followed in mods

Comments

@Ruin0x11
Copy link
Owner

Ruin0x11 commented Apr 23, 2021

It is very common to want to specify what order to iterate the entries in data with when using data[...]:iter(). Currently, any code that wants a custom sorting order has to sort the iterator themselves, because the order of iteration for :iter() is undefined.

A very common pattern is to have an ordering field on the prototype, which is used by each sorting function. This was used to maintain vanilla compatibility where the sort order was based on a numeric ID.

I think the entries should be sorted by mod load order, and then this ordering field, for every possible data type. ordering would become a special prototype field like _id or _type available on all data types, because this concerns the :iter() function which is available for all possible data types. Generally when variants added new content like items, the numeric IDs would keep incrementing past the maximum ID of the last vanilla item, meaning the new items would always come after the vanilla items, so I think the mod load order for sorting is good as a default.

Also, ordering would be autopopulated based on the order of prototype addition if it's omitted.

@Ruin0x11 Ruin0x11 added refactoring This requires refactoring existing code standardization Concerns conventions that should be strongly followed in mods data Concerns adding new content labels Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data Concerns adding new content refactoring This requires refactoring existing code standardization Concerns conventions that should be strongly followed in mods
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant