Updating the assets
This commit is contained in:
@ -20,7 +20,8 @@
|
||||
#define MENU_HOLD_DURATION 1.0
|
||||
|
||||
typedef struct {
|
||||
int32_t bruh;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} menuitem_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -7,8 +7,5 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"pngjs": "^6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"stitch": "node --max-heap-size=3840 ./tools/stitcher/index.js"
|
||||
}
|
||||
}
|
56
scripts/tools/characters/sprite-generator.js
Normal file
56
scripts/tools/characters/sprite-generator.js
Normal file
@ -0,0 +1,56 @@
|
||||
const path = require('path');
|
||||
const { imageCreate, imageWrite, imageLoad, imageCopy } = require('./../../utils/image');
|
||||
const fs =require('fs');
|
||||
|
||||
// Where to crop
|
||||
const FACE_AREA = { x: 367, y: 256, width: 280, height: 280 };
|
||||
|
||||
// Where the images are stored
|
||||
const IMAGES_ROOT = path.join(...[
|
||||
'.',
|
||||
'assets',
|
||||
'characters',
|
||||
'penny',
|
||||
'sprites'
|
||||
]);
|
||||
|
||||
// Which image directories to crop
|
||||
const IMAGES_DIRECTORIES = [ 'eyebrows', 'eyes', 'mouths' ];
|
||||
|
||||
(async () => {
|
||||
// Load the base
|
||||
const base = await imageLoad(path.join(IMAGES_ROOT, 'dealer.png'));
|
||||
|
||||
let columnsMax = 0;
|
||||
for(let row = 0; row < IMAGES_DIRECTORIES.length; row++) {
|
||||
const dir = path.join(IMAGES_ROOT, IMAGES_DIRECTORIES[row]);
|
||||
const scan = fs.readdirSync(dir);
|
||||
columnsMax = Math.max(scan.length, columnsMax);
|
||||
}
|
||||
|
||||
// Create the output buffer
|
||||
const out = imageCreate(base.width+(columnsMax*FACE_AREA.width), base.height);
|
||||
|
||||
// Copy the base
|
||||
imageCopy(out, base, 0, 0);
|
||||
|
||||
// Now begin copying the children, row is defined by the directory
|
||||
for(let row = 0; row < IMAGES_DIRECTORIES.length; row++) {
|
||||
const dir = path.join(IMAGES_ROOT, IMAGES_DIRECTORIES[row]);
|
||||
const scan = fs.readdirSync(dir);
|
||||
|
||||
// Column defined by the file index
|
||||
for(let col = 0; col < scan.length; col++) {
|
||||
const img = await imageLoad(path.join(dir, scan[col]));
|
||||
console.log('Copying', scan[col]);
|
||||
|
||||
imageCopy(out, img,
|
||||
base.width+(col*FACE_AREA.width), FACE_AREA.height*row,
|
||||
FACE_AREA
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await imageWrite(out, path.join(IMAGES_ROOT, 'sheet.png'));
|
||||
})().catch(console.error);
|
103
scripts/utils/image.js
Normal file
103
scripts/utils/image.js
Normal file
@ -0,0 +1,103 @@
|
||||
const { PNG } = require("pngjs");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/**
|
||||
* Loads an image into memory.
|
||||
* @param image Image to load
|
||||
* @returns A promise that resolves to the loaded image.
|
||||
*/
|
||||
const imageLoad = (image) => new Promise(resolve => {
|
||||
fs.createReadStream(image)
|
||||
.pipe(new PNG({ filterType: 4 }))
|
||||
.on("parsed", function () {
|
||||
// Normalize
|
||||
const pixels = [];
|
||||
for(let y = 0; y < this.height; y++) {
|
||||
for(let x = 0; x < this.width; x++) {
|
||||
const idx = (this.width * y + x) << 2;
|
||||
const r = this.data[idx];
|
||||
const g = this.data[idx + 1];
|
||||
const b = this.data[idx + 2];
|
||||
const a = this.data[idx + 3];
|
||||
|
||||
pixels.push({ r, g, b, a });
|
||||
}
|
||||
}
|
||||
resolve({ pixels, width: this.width, height: this.height });
|
||||
})
|
||||
;
|
||||
});
|
||||
|
||||
/**
|
||||
* Writes an image to an output file.
|
||||
* @param image Image to write.
|
||||
* @param file File to write to.
|
||||
* @returns A promise that, when resolved, has saved the image.
|
||||
*/
|
||||
const imageWrite = (image, file) => new Promise(resolve => {
|
||||
const png = new PNG({ width: image.width, height: image.height });
|
||||
png.width = image.width;
|
||||
png.height = image.height;
|
||||
|
||||
for(let y = 0; y < image.height; y++) {
|
||||
for(let x = 0; x < image.width; x++) {
|
||||
const i = (image.width * y + x);
|
||||
const idx = i << 2;
|
||||
|
||||
const pixel = image.pixels[i];
|
||||
png.data[idx] = pixel.r;
|
||||
png.data[idx + 1] = pixel.g;
|
||||
png.data[idx + 2] = pixel.b;
|
||||
png.data[idx + 3] = pixel.a;
|
||||
}
|
||||
}
|
||||
|
||||
png.pack().pipe(fs.createWriteStream(file))
|
||||
.on('close', () => resolve(true))
|
||||
;
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a blank image
|
||||
* @param width Width of the image.
|
||||
* @param height Height of the image.
|
||||
* @param fill Optional pixel to fill with, defaults to 0,0,0,0
|
||||
* @returns The newly created image.
|
||||
*/
|
||||
const imageCreate = (width, height, pixel) => {
|
||||
if(!pixel || !pixel.r) pixel = { r:0, g:0, b:0, a:0 };
|
||||
const pixels = [];
|
||||
for(let i = 0; i < width * height; i++) pixels.push({ ...pixel });
|
||||
return { pixels, width, height };
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies an area of a source image into a target image.
|
||||
* @param target Target image to copy into.
|
||||
* @param source Source image to copy from.
|
||||
* @param tx Target X position to copy into
|
||||
* @param ty Target Y position to copy into
|
||||
* @param sub Optional source area to use, defined as { x, y, width, height }.
|
||||
*/
|
||||
const imageCopy = (target, source, tx, ty, sub) => {
|
||||
if(!sub) sub = { x: 0, y: 0, width: source.width, height: source.height };
|
||||
|
||||
for(let x = sub.x; x < sub.x+sub.width; x++) {
|
||||
for(let y = sub.y; y < sub.y+sub.height; y++) {
|
||||
let absX = x - sub.x + tx;
|
||||
let absY = y - sub.y + ty;
|
||||
if(absX > target.width || absY > target.height) continue;
|
||||
let ti = absY * target.width + absX;
|
||||
let si = y * source.width + x;
|
||||
target.pixels[ti] = { ...source.pixels[si] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
imageWrite,
|
||||
imageCreate,
|
||||
imageLoad,
|
||||
imageCopy
|
||||
}
|
@ -9,9 +9,6 @@
|
||||
|
||||
#include "../physics/vector.h"
|
||||
|
||||
primitive_t primitive;
|
||||
texture_t texture;
|
||||
|
||||
bool gameInit(game_t *game) {
|
||||
// Init the engine and the rendering pipeline
|
||||
engineInit(&game->engine, game);
|
||||
|
@ -7,14 +7,14 @@
|
||||
#include "pokergameassets.h"
|
||||
|
||||
bool pokerGameAssetsInit(pokergameassets_t *assets) {
|
||||
assetFontLoad(&assets->font, "fonts/opensans/OpenSans-Bold.ttf");
|
||||
assetShaderLoad(&assets->shader,
|
||||
"shaders/textured.vert", "shaders/textured.frag"
|
||||
);
|
||||
assetFontLoad(&assets->font, "fonts/opensans/OpenSans-Bold.ttf");
|
||||
languageInit(&assets->language, "locale/language/en-US.csv");
|
||||
assetTextureLoad(&assets->testTexture, "test_texture.png");
|
||||
assetTextureLoad(&assets->roomTexture, "textures/pub_skywall.png");
|
||||
|
||||
assetTextureLoad(&assets->roomTexture, "room.png");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ void pokerRenderRender(
|
||||
) {
|
||||
// Render the wall
|
||||
shaderUseTexture(&assets->shader, &assets->roomTexture);
|
||||
shaderUsePosition(&assets->shader, 0, 0, 0, 0,0,0);
|
||||
shaderUsePosition(&assets->shader, 0, 0, 0, 0,engine->time.current/3,0);
|
||||
primitiveDraw(&render->skywall, 0, -1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user