Valheim-Modding / Jotunn

Jötunn, the Valheim Library.
https://valheim-modding.github.io/Jotunn/
MIT License
126 stars 40 forks source link

feat: prefab name helpers #397

Closed MSchmoecker closed 1 year ago

MSchmoecker commented 1 year ago

Adds name shortcuts from human-readable names to internal ids.

Helper Classes

Jotunn Config Changes

For example:

PieceConfig piece = new PieceConfig();
piece.Name = "$display_name";
piece.PieceTable = "Hammer";
piece.Category = "Misc";
piece.CraftingStation = "piece_workbench";

can also be written as:

PieceConfig piece = new PieceConfig();
piece.Name = "$display_name";
piece.PieceTable = PieceTables.Hammer;
piece.Category = PieceCategories.Misc;
piece.CraftingStation = CraftingStations.Workbench;

The names on Configs are resolved on set, thus:

piece.CraftingStation = CraftingStations.Workbench;
piece.CraftingStation = nameof(CraftingStations.Workbench);
piece.CraftingStation = "Workbench";
piece.CraftingStation = "piece_workbench";

all set piece.CraftingStation to "piece_workbench" internally. If a custom name is used, it will still be set and not changed.

BepInEx Config

Additionally, the helper provide GetAcceptableValueList() to create configs that are validated by existing names. This will create a human readable list of None, Workbench, Forge, Stonecutter, Cauldron, ArtisanTable, BlackForge, GaldrTable.

var stationConfig = Config.Bind("Section", "Key", nameof(CraftingStations.Workbench), new ConfigDescription("Description", CraftingStations.GetAcceptableValueList()));

Documentation

The documentation is not yet adapted, this will happen in a later PR.