// ingest-sheet.js // Copyright (C) 2024 DTP Technologies, LLC // All Rights Reserved "use strict"; const xml2js = require("xml2js"); const fs = require("fs"); /* * A program to convert sheet.xml to sheet.json for use as input to the DTP Game * Engine built into Sites to implement the Playable model. */ (async () => { try { const xmlData = await fs.promises.readFile(process.argv[2]); const parser = new xml2js.Parser(); const json = await parser.parseStringPromise(xmlData); await fs.promises.writeFile( "sheet-raw.json", JSON.stringify(json, null, 2) ); const sheet = {}; for (const record of json.TextureAtlas.SubTexture) { const texture = record.$; sheet[texture.name] = { x: texture.x, y: texture.y, w: texture.width, h: texture.height, }; } await fs.promises.writeFile("sheet.json", JSON.stringify(sheet, null, 2)); } catch (error) { console.log(error); } })();