Added in all the other characters (testing)

This commit is contained in:
2021-11-02 08:33:58 -07:00
parent 0695f8c523
commit 6d6982c160
41 changed files with 532 additions and 279 deletions

View File

@ -8,17 +8,22 @@ const { mkdirp } = require('../utils/file');
// Parse Args
if(!args.root) throw new Error(`Missing root argument`);
if(!args.assets) throw new Error(`Missing assets argument`);
if(!args.temp) throw new Error(`Missing temp argument`);
if(!args.in) throw new Error(`Missing in argument`);
if(!args.out) throw new Error(`Missing out argument`);
if(!args.dep) throw new Error(`Missing dep argument`);
if(!args.in.endsWith('xml')) throw new Error(`Invalid in XML`);
if(!args.out.endsWith('png')) throw new Error(`Invalid out PNG`);
// Determine in and out.
const root = path.resolve(args.root);
const file = path.resolve(args.root, args.assets, args.in);
if(!fs.existsSync(file)) throw new Error(`Could not find ${file}`);
const outFile = path.resolve(args.assets, args.out);
if(fs.existsSync(outFile)) return;
const cOut = path.resolve(args.temp, 'vn', `${args.dep}.c`);
const hOut = path.resolve(args.temp, 'vn', `${args.dep}.h`);
if(!fs.existsSync(file)) throw new Error(`Could not find ${file}`);
if(fs.existsSync(outFile) && fs.existsSync(cOut) && fs.existsSync(hOut)) return;
// Load XML
const data = xml.xml2js(fs.readFileSync(file, 'utf-8'));
@ -49,6 +54,8 @@ const layers = character.elements
let columnsMax = 0;
let widthMax = 0;
let strLayers = ``;
layers.forEach((layer,row) => {
if(!layer.width || !layer.height || !layer.x || !layer.y) {
throw new Error(`Missing layer info`);
@ -86,9 +93,47 @@ const layers = character.elements
);
}
strLayers += `
vnCharacterLayerAdd(vnc, ${scan.length},
${baseImage.width}, ${y},
${layer.x}, ${layer.y},
${layer.width}, ${layer.height}
);
`;
y += layer.height;
}
mkdirp(outFile);
await imageWrite(out, outFile);
mkdirp(cOut);
let name = character.attributes.name || args.name || args.dep;
fs.writeFileSync(cOut, `
#include "${args.dep}.h"
void vnCharacter${name}Init(vncharacter_t *vnc, texture_t *texture) {
assetTextureLoad(texture, VN_CHARACTER_${name.toUpperCase()}_TEXTURE);
vnCharacterInit(vnc, texture);
// Base Layer
vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, ${baseImage.width}, ${baseImage.height});
// Layers
${strLayers}
}
`);
fs.writeFileSync(hOut, `
#pragma once
#include <libs.h>
#include <vn/vncharacter.h>
#include <display/texture.h>
#include <file/asset.h>
#define VN_CHARACTER_${name.toUpperCase()}_TEXTURE "${args.out}"
void vnCharacter${name}Init(vncharacter_t *vnc, texture_t *texture);
`);
})().catch(console.error);