diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/ingest-sheet.js b/ingest-sheet.js new file mode 100644 index 0000000..f4b2058 --- /dev/null +++ b/ingest-sheet.js @@ -0,0 +1,39 @@ +// 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); + } +})(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5c8ac1c --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "xmlconv", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "packageManager": "pnpm@9.1.0+sha512.67f5879916a9293e5cf059c23853d571beaf4f753c707f40cb22bed5fb1578c6aad3b6c4107ccb3ba0b35be003eb621a16471ac836c87beb53f9d54bb4612724", + "dependencies": { + "xml2js": "^0.6.2" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..c9de7a3 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,37 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + xml2js: + specifier: ^0.6.2 + version: 0.6.2 + +packages: + + sax@1.4.1: + resolution: {integrity: sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==} + + xml2js@0.6.2: + resolution: {integrity: sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==} + engines: {node: '>=4.0.0'} + + xmlbuilder@11.0.1: + resolution: {integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==} + engines: {node: '>=4.0'} + +snapshots: + + sax@1.4.1: {} + + xml2js@0.6.2: + dependencies: + sax: 1.4.1 + xmlbuilder: 11.0.1 + + xmlbuilder@11.0.1: {} diff --git a/test/sheet.xml b/test/sheet.xml new file mode 100644 index 0000000..71e1ccf --- /dev/null +++ b/test/sheet.xml @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file