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

Capture unrecognized fields #46

Open
laper32 opened this issue Nov 16, 2024 · 2 comments
Open

Capture unrecognized fields #46

laper32 opened this issue Nov 16, 2024 · 2 comments

Comments

@laper32
Copy link

laper32 commented Nov 16, 2024

This is quite something like [JsonExtensionData] in System.Text.Json.

Does Tomlet provide this feature?

@SamboyCoding
Copy link
Owner

No, there is no such functionality built-in. What's your use-case?

@laper32
Copy link
Author

laper32 commented Nov 20, 2024

Consider this toml below:

[npc_hero_phantom_assassin]
health = 500 # builtin
mana = 300 # builtin
strength = 20 # builtin
agility = 20 # builtin
intelligence = 20 # builtin
attack_damage = 50 # builtin
attack_speed = 100 # builtin
phantom_assassin_critial_strike_damage = [2.5, 3.5, 4.5] # hero based
phantom_assassin_critial_strike_rate = 0.17 # hero based

Consider code below:

(Using System.Text.Json for easier representation)

public class TomlGameNPC
{
    [JsonPropertyName("health")]
    int Health {get; set;}

    [JsonPropertyName("mana")]
    int Mana {get; set;}

    [JsonPropertyName("strange")]
    int Strange {get; set;}

    [JsonPropertyName("agility")]
    int Agility {get; set;}

    [JsonPropertyName("intelligence")]
    int Intelligence {get; set;}

    [JsonPropertyName("attack_damage")]
    int AttackDamage {get; set;}

    [JsonPropertyName("attack_speed")]
    int AttackSpeed {get; set;}

    [JsonExtensionData]
    Dictionary<string, JsonElement> Attributes { get; set; }
}

Now as you can see, phantom_assassin_critial_strike_damage and phantom_assassin_critial_strike_rate is not general Game NPC, so we need to put all of them into Attributes.

When I need to do something more (e.g.: set hero's ability field) for Phantom Assassin, I will read TomlGameNPC.Attributes to find out these attributes and set them.

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

No branches or pull requests

2 participants