Unified way to specify sort order for data prototype iteration #305
Labels
data
Concerns adding new content
refactoring
This requires refactoring existing code
standardization
Concerns conventions that should be strongly followed in mods
It is very common to want to specify what order to iterate the entries in
data
with when usingdata[...]: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.The text was updated successfully, but these errors were encountered: