saltyhotdog / BattletechIssueTracker

Public issue tracker to communicate with modders and HBS.
MIT License
6 stars 0 forks source link

Replace enums to use defs directly #12

Open Morphyum opened 6 years ago

Morphyum commented 6 years ago

Describe the location in the code your suggestion is about For example Battletech.Factions also relevant for AmmoTypes and many more defs that use Enums in code.

What is your suggestion for this code For the modding community the enums are a big problem, since we cant change those at runtime, this prevents us from creating new factions, ammo types and much more.

If at all possible it would be much better for us if those enums would be replaced to use the defs directly. Therefore making it possible to add our own.

janxious commented 6 years ago

I imagine the beginning of this process (for ammo) would start at the bottom and work up. So Ammunition Type gets its own defs: https://github.com/saltyhotdog/BattletechSLN/commit/678db31cb694930c06f6bd3e6fb88576e559d4fa

We replace Normal/Special with JSONs, they might look like:

{
    "Description": {
        "Id" : "AmmunitionTypeDef_Normal",
        "Name" : "Normal",
        "Details" : "Just plain ammo",
        "Icon" : null,
        "Cost" : 0,
        "Rarity" : 0,
        "Purchaseable" : false
    }
}

Then we go back through the various places that reference it and update the Type fields to be AmmoTypeDefID, and in the case of normal ammos (all?), we add AmmunitionTypeDef_Normal. That's the easy one.

AmmoCategory is on the surface about the same, but immediately gets a lot trickier because specific enum values are referenced in a lot of places in the code. I don't know enough about how the BTech load time/hydration works, but it seems like in LoadComplete (which seemingly fires after JSON load), one could set some constants like (pseudocode):

class AmmoCategory
{
#…
  public static AmmoCategory CoolAmmoType;
#…
  public void LoadComplete()
  {
    if (this.descriptiondef.id == "CoolAmmoType")
    {
      AmmoCategory.CoolAmmoType = this;
    }
  }
}

I'm not super sure that will work, but for things like AMS/MG/etc., having a static accessor that one can compare against (might have to work on equality method, too) should patch over the places in code where enum values are used.

caardappel-hbs commented 6 years ago

This is in discussion between the core and tools teams, but is a large undertaking and removes some convenience for internal development. No promises, but you have been heard!

Morphyum commented 6 years ago

Thank you for listening :)

janxious commented 6 years ago

Thanks, @caardappel-hbs !