Added in all the other characters (testing)
This commit is contained in:
@ -4,8 +4,19 @@
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(tool_vn_character DEP_NAME IN OUT)
|
||||
add_custom_target(${DEP_NAME}
|
||||
COMMAND node ${TOOLS_DIR}/vn/character-sheet-generator.js --assets="${ASSETS_DIR}" --root="${ROOT_DIR}" --in="${IN}" --out="${OUT}"
|
||||
COMMENT "Adding VN Character ${DEP_NAME}"
|
||||
add_custom_command(
|
||||
OUTPUT ${TEMP_DIR}/vn/${DEP_NAME}.c ${TEMP_DIR}/vn/${DEP_NAME}.h
|
||||
COMMAND node ${TOOLS_DIR}/vn/character-sheet-generator.js --assets="${ASSETS_DIR}" --root="${ROOT_DIR}" --temp="${TEMP_DIR}" --in="${IN}" --out="${OUT}" --dep="${DEP_NAME}"
|
||||
COMMENT "Generating VN Character ${DEP_NAME}"
|
||||
)
|
||||
|
||||
# target_sources(${PROJECT_NAME}
|
||||
# PRIVATE
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DIR}/vn/${DEP_NAME}.c
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DIR}/vn/${DEP_NAME}.h
|
||||
# )
|
||||
# target_include_directories(${PROJECT_NAME}
|
||||
# PUBLIC
|
||||
# ${CMAKE_CURRENT_BINARY_DIR}/${TEMP_DIR}/vn/
|
||||
# )
|
||||
endfunction()
|
@ -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);
|
Reference in New Issue
Block a user