Skip to content

Enum attrs bi-directional mapping #6

@vallode

Description

@vallode

Enum attributes can be access either via the key or the value of the corresponding enum, right now we are only using the value. This results in some annoying behaviour:

---@type tiletype
local ttype = dfhack.maps.getTileType(engraving.pos)
local tileattrs = df.tiletype.attrs[ttype] -- Cast as `unknown` even though this is a valid index.

The biggest issue is going to be figuring out how to do this without doubling the size of enums (again):

---@field FrozenRampTrackNEW { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }```

Would change into:

---@field FrozenRampTrackNEW { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }
---@field [677] { caption: "ice ramp track NEW", shape: "RAMP", material: "FROZEN_LIQUID", variant: "NONE", special: "TRACK", direction: "NEW" }

For enums with hundreds of attributes, it is less than ideal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions