Update ItemGenerator.lua

This commit is contained in:
Tiger Wang 2020-08-19 20:48:15 +01:00
parent dfa2f3687c
commit 77ee79d35c

View File

@ -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
if true then
writeItems(registry)
else
writeGlobalPalette(registry)
io.write("\n\n")
writeReverseGlobalPalette(registry)
local function writeReverseSerializer(registry)
for itemName in spairs(registry) do
io.write("{ \"", itemName, "\", Statistic::", makeTitleCase(itemName), " },\n")
end
end
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)