Make strings dynamically generated.

This commit is contained in:
2022-01-04 22:36:00 -08:00
parent 1cd4f76f50
commit d05252045a
10 changed files with 54 additions and 52 deletions

View File

@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');
const { arrayToString } = require('./util');
const FONT_CHARACTER_FIRST = 33;
@@ -10,18 +11,25 @@ const getCodeFrom = l => {
return cc - FONT_CHARACTER_FIRST + FONT_DATA_POSITION
}
const string2gb = (string, name) => {
const string2gb = (string, name, dirOut) => {
const letters = [];
for(let i = 0; i < string.length; i++) {
letters.push(getCodeFrom(string[i]));
}
out = '#include "libs.h"\n\n';
out += `#define STR_${name}_LENGTH ${string.length}\n`;
out += `extern const uint8_t STR_${name}_DATA[];\n\n\n`
out += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
let outH = '#include "libs.h"\n\n';
outH += `#define STR_${name}_LENGTH ${string.length}\n`;
outH += `extern const uint8_t STR_${name}_DATA[];`;
let outC = `#include "${name}.h"\n\n`;
outC += `const uint8_t STR_${name}_DATA[] = {\n` + arrayToString(letters) + `\n};`;
const fileH = path.join(dirOut, `${name}.h`);
const fileC = path.join(dirOut, `${name}.c`);
fs.writeFileSync('out.c', out);
fs.writeFileSync(fileH, outH);
fs.writeFileSync(fileC, outC);
return { fileH, fileC };
}
module.exports = {