I hate my life

This commit is contained in:
2021-11-05 10:55:10 -07:00
parent 489c282022
commit b6cc69eef6
18 changed files with 524 additions and 88 deletions

View File

@ -6,9 +6,7 @@ const { args } = require('./../utils/args');
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.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`);
@ -16,14 +14,16 @@ 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);
const outFile = path.resolve(args.assets, args.out);
const file = path.resolve(args.in);
const outFile = path.resolve(args.out);
const cOut = path.resolve(args.temp, 'vn', `${args.dep}.c`);
const hOut = path.resolve(args.temp, 'vn', `${args.dep}.h`);
console.log(outFile);
// 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;
// if(fs.existsSync(outFile) && fs.existsSync(cOut) && fs.existsSync(hOut)) return;
if(fs.existsSync(outFile)) return;
// Load XML
const data = xml.xml2js(fs.readFileSync(file, 'utf-8'));
@ -31,7 +31,7 @@ const [ character ] = data.elements;
// Validate file.
if(!character.attributes.context) throw new Error(`Missing context`)
const dir = path.resolve(root, args.assets, character.attributes.context);
const dir = path.resolve(path.dirname(file), character.attributes.context);
// Parse base and layers
const base = character.elements.find(e => e.name == 'base').attributes;
@ -107,33 +107,33 @@ const layers = character.elements
mkdirp(outFile);
await imageWrite(out, outFile);
mkdirp(cOut);
let name = character.attributes.name || args.name || args.dep;
// mkdirp(cOut);
// fs.writeFileSync(cOut, `
// #include "${args.dep}.h"
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);
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});
// Base Layer
vnCharacterLayerAdd(vnc, 1, 0, 0, 0, 0, ${baseImage.width}, ${baseImage.height});
// // Layers
// ${strLayers}
// }
// `);
// Layers
${strLayers}
}
`);
// fs.writeFileSync(hOut, `
// #pragma once
// #include <libs.h>
// #include <vn/vncharacter.h>
// #include <display/texture.h>
// #include <file/asset.h>
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}"
// #define VN_CHARACTER_${name.toUpperCase()}_TEXTURE "${args.out}"
void vnCharacter${name}Init(vncharacter_t *vnc, texture_t *texture);
`);
// void vnCharacter${name}Init(vncharacter_t *vnc, texture_t *texture);
// `);
})().catch(console.error);