From 77ee79d35c86f0911c47ddfade9261f98b964d9a Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 19 Aug 2020 20:48:15 +0100 Subject: Update ItemGenerator.lua --- Tools/BlockTypePaletteGenerator/ItemGenerator.lua | 33 ++++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Tools/BlockTypePaletteGenerator/ItemGenerator.lua b/Tools/BlockTypePaletteGenerator/ItemGenerator.lua index 5eff87603..8150b6837 100644 --- a/Tools/BlockTypePaletteGenerator/ItemGenerator.lua +++ b/Tools/BlockTypePaletteGenerator/ItemGenerator.lua @@ -197,26 +197,39 @@ local function writeItems(registry) io.write("\nenum class Statistic\n{\n", table.concat(names, ",\n"), "\n};") end -local function writeGlobalPalette(registry) - io.write("UInt32 FromItem(Statistic ID)\n{\nswitch (ID)\n{") +local function writeGlobalPalette(registry) + io.write("UInt32 From(const Statistic ID)\n{\nswitch (ID)\n{") for itemName, id in spairs(registry) do io.write("\ncase Statistic::", makeTitleCase(itemName), ": return ", id, ";") end - io.write("\ndefault: return 0;\n}\n}") + io.write("\ndefault: return -1;\n}\n}") end local function writeReverseGlobalPalette(registry) - io.write("Item ToStatistic(UInt32 ID)\n{\nswitch (ID)\n{") + io.write("Item ToStatistic(const UInt32 ID)\n{\nswitch (ID)\n{") for itemName, id in spairs(registry) do io.write("\ncase ", id, ": return Item::", makeTitleCase(itemName), ";") end io.write("\ndefault: return Statistic::Air;\n}\n}") end + +local function writeReverseSerializer(registry) + for itemName in spairs(registry) do + io.write("{ \"", itemName, "\", Statistic::", makeTitleCase(itemName), " },\n") + end +end -if true then - writeItems(registry) -else - writeGlobalPalette(registry) - io.write("\n\n") - writeReverseGlobalPalette(registry) +local function writeSerializer(registry) + io.write("const char * From(const Statistic ID)\n{\nswitch (ID)\n{") + for itemName in spairs(registry) do + io.write("\ncase Statistic::", makeTitleCase(itemName), ": return \"", itemName, "\";") + end end + +-- writeSerializer(registry) + +-- writeItems(registry) + +writeGlobalPalette(registry) +-- io.write("\n\n") +-- writeReverseGlobalPalette(registry) -- cgit v1.2.3