Skip to content

add field_map function#625

Merged
Jamiras merged 1 commit intomasterfrom
feature/field_map
Apr 4, 2026
Merged

add field_map function#625
Jamiras merged 1 commit intomasterfrom
feature/field_map

Conversation

@Jamiras
Copy link
Copy Markdown
Owner

@Jamiras Jamiras commented Mar 31, 2026

Allows iterating over fields of a class instance, providing a way to convert a psuedo-enum into a lookup for use in rich presence:

class LookupItem
{
    id = 0
    label = ""
}

class DifficultyEnum
{
    function current() => byte(0x1234)
    function is(d) => this.current() == d.id

    none = LookupItem(0, "")
    easy = LookupItem(1, "Easy")
    medium = LookupItem(2, "Medium")
    hard = LookupItem(3, "Hard")
}
Difficulty = DifficultyEnum()

rich_presence_display("{0}", 
    rich_presence_lookup("Difficulty", Difficulty.current(), field_map(Difficulty, (k, v) => { v.id : v.label }))
)

achievement("Something Hard", "Do something on hard", 5,
    Difficulty.is(Difficulty.hard) && do_something()
)

@Jamiras Jamiras added this to the 1.17.0 milestone Mar 31, 2026
@Jamiras Jamiras merged commit cb6a07d into master Apr 4, 2026
1 check passed
@Jamiras Jamiras deleted the feature/field_map branch April 4, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant