Committing progres

This commit is contained in:
2022-01-06 09:22:49 -08:00
parent f339ce0713
commit 4ad29e981e
15 changed files with 74 additions and 320 deletions

View File

@@ -11,6 +11,9 @@ const DIR_GENERATED = path.resolve(DIR_BUILD, 'generated');
const DIR_OBJ = path.resolve(DIR_BUILD, 'obj');
const DIR_SRC = path.resolve('src');
const DIR_GBDK = path.resolve(process.env['GBDKDIR']);
const DIR_ASSETS = path.resolve('assets');
const DIR_IMAGES = path.resolve(DIR_ASSETS, 'images');
const FILE_OUT = path.resolve(DIR_BUILD, 'Penny.gb');
const FILE_LINKFILE = path.join(DIR_BUILD, `linkflile.lk`);
@@ -85,15 +88,21 @@ Object.entries(GAME_STRINGS).forEach(entry => {
compileC(fileC);
})
// Gen imagery
fs.readdirSync(DIR_IMAGES).forEach(img => {
const { fileC, fileH } = png2gb(
path.join(DIR_IMAGES, img), DIR_GENERATED,
path.basename(img, '.png').toUpperCase()
);
compileC(fileC);
})
// Get a list of sources and build each of them prior to linking.
const allSources = buildSourceFiles(DIR_SRC);
for(let i = 0; i < allSources.length; i++) {
compileC(allSources[i]);
}
// Gen imagery
// Generate a linkfile.
fs.writeFileSync(FILE_LINKFILE, compiledSources.map(cs=>{
return path.join(DIR_OBJ, cs);

View File

@@ -1,4 +1,5 @@
const PNG = require('pngjs').PNG;
const path = require('path');
const fs = require('fs');
const { arrayToString } = require('./util');
const {
@@ -15,8 +16,7 @@ const getPixelValue = (pixel) => {
throw new Error();
}
const png2gb = (fileIn, fileOut, name) => {
const png2gb = (fileIn, dirOut, name) => {
const data = fs.readFileSync(fileIn);
const png = PNG.sync.read(data);
@@ -66,16 +66,24 @@ const png2gb = (fileIn, fileOut, name) => {
bits.push(lowBits, highBits);
}
let out = '';
out += `#include "libs.h"\n\n`
out += `#define ${name}_IMAGE_WIDTH ${png.width}\n`;
out += `#define ${name}_IMAGE_HEIGHT ${png.height}\n`;
out += `#define ${name}_IMAGE_COLUMNS ${png.width / TILE_WIDTH}\n`;
out += `#define ${name}_IMAGE_ROWS ${png.height / TILE_HEIGHT}\n`;
out += `#define ${name}_IMAGE_TILES ${columns * rows}\n`;
out += `\nconst uint8_t ${name}_IMAGE[] = {\n${arrayToSTring(bits)}};`;
let outH = '';
outH += `#include "libs.h"\n\n`
outH += `#define ${name}_IMAGE_WIDTH ${png.width}\n`;
outH += `#define ${name}_IMAGE_HEIGHT ${png.height}\n`;
outH += `#define ${name}_IMAGE_COLUMNS ${png.width / TILE_WIDTH}\n`;
outH += `#define ${name}_IMAGE_ROWS ${png.height / TILE_HEIGHT}\n`;
outH += `#define ${name}_IMAGE_TILES ${columns * rows}\n`;
outH += `extern const uint8_t ${name}_IMAGE[];`;
fs.writeFileSync(fileOut, out);
let outC = `#include "${name}.h"\n`;
outC += `\nconst uint8_t ${name}_IMAGE[] = {\n${arrayToString(bits)}};`;
const fileH = path.join(dirOut, name + '.h');
const fileC = path.join(dirOut, name + '.c');
fs.writeFileSync(fileH, outH);
fs.writeFileSync(fileC, outC);
return { fileH, fileC };
}
module.exports = {