Cleanup generateobjects.lua and move it back into Enum generation

This commit is contained in:
hispidence 2022-09-13 21:22:21 +01:00
parent 691be5dfd7
commit 5f3ff0e056

View file

@ -1,36 +1,24 @@
local parseFile = require('xmllpegparser').parseFile local parseFile = require('xmllpegparser').parseFile
local enumName = "Objects.ObjID" local args = {...}
local enumIncludes = [==[ local helpStr = [[Usage: lua generateobjects.lua CATALOGPATH
#include "objectslist.h"
#include <unordered_map>
#include <string>
]==]
local srcFile = "P:\\Projects\\Tomb-Editor\\BuildRelease (x64)\\net6.0-windows\\Catalogs\\TrCatalog.xml" This tool reads the TrCatalog.xml file whose path is given as input and creates game_object_ids.h (which defines GAME_OBJECT_ID enum used by TEN) and ObjectIDs.h (which creates constants and documentation for the API).
local srcFileInv = "Enum generation\\inventoryslots"
local enumDesc = "Constants for object IDs."
local constantsDesc = "The following constants are inside ObjID."
local tableDesc = "Table of constants."
local outputFileList = [[P:\Projects\TombEngine\TombEngine\Objects\game_object_ids.h]] To work properly, this script must be in the folder TombEngine/Tools/Enum generation.]]
local outputFileIDs = [[P:\Projects\TombEngine\TombEngine\Scripting\Internal\TEN\Objects\ObjectIDs.h]]
local decl = "static const std::unordered_map<std::string, GAME_OBJECT_ID> kObjIDs {" if not args[1] or args[1] == "--help" then
local footer = [==[ print(helpStr)
}; return
]==] end
local enumFile = "objIDs.txt" local srcFile = args[1]
local enumFile2 = "inventorySlots"
local outputFile = "../../TombEngine/Scripting/Internal/TEN/Objects/ObjectIDs.h" local outputFileList = [[..\..\TombEngine\Objects\game_object_ids.h]]
local outputFileIDs = [[..\..\TombEngine\Scripting\Internal\TEN\Objects\ObjectIDs.h]]
local doc, err = parseFile(srcFile) local doc, err = parseFile(srcFile)
local theTab = doc.children[1] local theTab = doc.children[1]
for k, v in pairs(theTab) do print(k, v) end
print("")
print(next(theTab))
print(theTab)
local editorNames = {} local editorNames = {}
local engineNames = {} local engineNames = {}
@ -47,7 +35,6 @@ function printelem(path, index, e, prefix)
if not attrsMatch then if not attrsMatch then
attrsMatch = true attrsMatch = true
for k, v in pairs(tag.attrs) do for k, v in pairs(tag.attrs) do
print(k, v, e.attrs[k])
if e.attrs[k] ~= v then if e.attrs[k] ~= v then
attrsMatch = false attrsMatch = false
end end
@ -55,12 +42,10 @@ function printelem(path, index, e, prefix)
end end
if attrsMatch then if attrsMatch then
print(tag.name, "match")
if tag.process then if tag.process then
tag.process(e) tag.process(e)
else else
for i, child in pairs(e.children) do for i, child in pairs(e.children) do
print(i)
printelem(path, index+1, child, prefix) printelem(path, index+1, child, prefix)
end end
end end
@ -83,10 +68,6 @@ end
function printdoc(doc) function printdoc(doc)
local path = {{name = "xml"}, {name = "game", attrs = {id = "TombEngine"}}, {name="moveables"}, {name="moveable", process = getObject}} local path = {{name = "xml"}, {name = "game", attrs = {id = "TombEngine"}}, {name="moveables"}, {name="moveable", process = getObject}}
local path2 = {{name = "xml"}, {name = "game", attrs = {id = "TombEngine"}}, {name="sprite_sequences"}, {name="sprite_sequence", process = getObject}} local path2 = {{name = "xml"}, {name = "game", attrs = {id = "TombEngine"}}, {name="sprite_sequences"}, {name="sprite_sequence", process = getObject}}
for i, e in pairs(doc.entities) do
-- print(' ' .. e.name .. ": " .. e.value)
end
print("Data:")
for i, child in pairs(doc.children) do for i, child in pairs(doc.children) do
printelem(path, 1, child, ' ') printelem(path, 1, child, ' ')
printelem(path2, 1, child, ' ') printelem(path2, 1, child, ' ')
@ -94,18 +75,12 @@ function printdoc(doc)
end end
printdoc(doc) printdoc(doc)
for k, v in pairs(editorNames) do
print(k, v, engineNames[k])
end
print(maxID)
local namePairs = {} local namePairs = {}
for i = 0, maxID do for i = 0, maxID do
namePairs[i] = {editor = editorNames[i], engine = engineNames[i]} namePairs[i] = {editor = editorNames[i], engine = engineNames[i]}
local p = namePairs[i] local p = namePairs[i]
print(i, p.editor, p.engine)
end end
local objlistH = [====[#pragma once local objlistH = [====[#pragma once
@ -134,12 +109,13 @@ end
ID_NUMBER_OBJECTS ID_NUMBER_OBJECTS
}; };
]====] ]====]
print (objlistH)
local file = io.open(outputFileList, 'w') local file = io.open(outputFileList, 'w')
file:write(objlistH) file:write(objlistH)
io.close(file) io.close(file)
print("Written " .. outputFileList)
local objidsH = [=[#pragma once local objidsH = [=[#pragma once
@ -177,8 +153,6 @@ for i = 0, maxID do
end end
end end
-- TODO PICKUPS
--
objidsH = objidsH .. [=[ objidsH = objidsH .. [=[
Table of constants. Table of constants.
@table Members @table Members
@ -224,17 +198,4 @@ else
io.close(file) io.close(file)
end end
--TEN NAME, XML NAME print("Written " .. outputFileIDs)
--STEAM_EMITTER, removed
--HITMAN, CYBORG
--LARA_HAIR, HAIR
--BIGGUN_ANIMS, LARA_BIGGUN_ANIM
--BADDY_SILENCER1, GOON_SILENCER1
--BADDY_SILENCER2, GOON_SILENCER2
--BADDY_SILENCER3, GOON_SILENCER3
--LARA_DOPPELGANGER, DOPPELGANGER
--MOTOR_BOAT_FOAM_SPRITES, MOTORBOAT_FOAM_SPRITES,
--PC_LOAD_SAVE_ITEM, PC_SAVE_INV_ITEM
--OPEN_DIARY_ITEM, DIARY_OPEN
--LARA_FLARE_ANIM, FLARE_ANIM
--