chore: refactors files path

This commit is contained in:
raphael 2024-11-27 14:02:45 +01:00
parent ac5a285ed4
commit 3c7792eba9
5 changed files with 30 additions and 26 deletions

6
app.c
View File

@ -1,6 +1,6 @@
#include "pengers.h"
#include "hand.c"
#include "coin.c"
#include "out/pengers.h"
#include "out/hand.c"
#include "out/coin.c"
#define GREEN 0xff00ff00
#define RED 0xff0000ff

View File

@ -1,7 +1,8 @@
#!/bin/bash
if [[ "$1" == "clear" ]]; then
rm -vfr museum.c pengers.h hand.c app.wasm png2c app.wat index.html
rm -vfr out/*
touch out/.gitkeep
exit
fi;
@ -21,39 +22,41 @@ fi
#set -xe
clang png2c.c -o png2c -lm
mkdir -p museum.c
rm -f museum.c/*
clang png2c.c -o out/png2c -lm
mkdir -p out/museum.c
rm -f out/museum.c/*
pengers_html=$'\n'
pengers_include=$'\n'
id=0
for p in $(ls static/museum/); do
file=$(echo $p | sed "s/\.png$//g")
./png2c "static/museum/"$p $id > museum.c/$file.c
./out/png2c "static/museum/"$p $id > out/museum.c/$file.c
pengers_html+=$' <img src="static/museum/'$p'" class="penger-img" penger-id="'$id'"></img>\n'
pengers_include+='#include "museum.c/'$file$'.c"\n'
((id=id+1))
done
echo "int pengers_height[$id];" > pengers.h
echo "int pengers_width[$id];" >> pengers.h
echo "unsigned int *pengers_img[$id];" >> pengers.h
echo "$pengers_include" >> pengers.h
echo "void pengers_init(void) {" >> pengers.h
echo "int pengers_height[$id];" > out/pengers.h
echo "int pengers_width[$id];" >> out/pengers.h
echo "unsigned int *pengers_img[$id];" >> out/pengers.h
echo "$pengers_include" >> out/pengers.h
echo "void pengers_init(void) {" >> out/pengers.h
((id=id-1))
for i in $(seq 0 $id); do
echo " penger_init_$i();" >> pengers.h;
echo " penger_init_$i();" >> out/pengers.h;
done
echo "}" >> pengers.h
echo "}" >> out/pengers.h
echo -e "$pengers_html" > pengers_image.html.temp
sed -e '/<!-- penger images src -->/rpengers_image.html.temp' index.html.template > index.html
sed -e '/<!-- penger images src -->/rpengers_image.html.temp' templates/index.html.template > out/index.html
rm pengers_image.html.temp
./out/png2c "static/assets/hand.png" > out/hand.c
./out/png2c "static/assets/coin.png" > out/coin.c
clang -O3 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o $f.wasm $a
clang -O3 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o out/$f.wasm $a
wasm2wat $f.wasm > $f.wat
wasm2wat out/$f.wasm > out/$f.wat
cp templates/leaderboard.json.template out/leaderboard.json

View File

@ -175,7 +175,7 @@ function make_environment(...envs) {
});
}
const { instance } = await WebAssembly.instantiateStreaming(fetch("./app.wasm"), {
const { instance } = await WebAssembly.instantiateStreaming(fetch("./out/app.wasm"), {
"env": make_environment({
// importer les fonctions dans le wasm
'random': Math.random,

View File

@ -1,6 +1,6 @@
const fs = require('fs');
var leaderboard = JSON.parse(fs.readFileSync("leaderboard.json"));
var leaderboard = JSON.parse(fs.readFileSync("out/leaderboard.json"));
leaderboard.today = [
{name: 'none', value: '0'},
{name: 'none', value: '0'},
@ -8,4 +8,4 @@ leaderboard.today = [
{name: 'none', value: '0'},
{name: 'none', value: '0'}
];
fs.writeFile('leaderboard.json', JSON.stringify(leaderboard), ()=>{});
fs.writeFile('out/leaderboard.json', JSON.stringify(leaderboard), ()=>{});

View File

@ -46,6 +46,7 @@ function send_new_map()
});
setTimeout(send_new_map, map_every_ms);
}
setTimeout(send_new_map, map_every_ms);
function send_map(socket)
{
@ -55,14 +56,14 @@ function send_map(socket)
const requestListener = function (req, res) {
var url = req.url;
if (url == "/" || url == "/index.html") {
if (url == "/") {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(fs.readFileSync("./index.html"));
res.end(fs.readFileSync("./out/index.html"));
return;
}
if (url == "/app.wasm") {
if (url == "/out/app.wasm") {
res.setHeader("Content-Type", "application/wasm");
res.writeHead(200);
res.end(fs.readFileSync("." + url));
@ -108,7 +109,7 @@ http_server.listen(HTTP_PORT, () => {
});
var maps = JSON.parse(fs.readFileSync("maps.json"));
var leaderboard = JSON.parse(fs.readFileSync("leaderboard.json"));
var leaderboard = JSON.parse(fs.readFileSync("out/leaderboard.json"));
const ws_server = new ws.Server({ port: WS_PORT });
@ -172,7 +173,7 @@ ws_server.on('connection', (socket) => {
leaderboard.total.pop();
}
if (update_leaderboard) {
fs.writeFile('leaderboard.json', JSON.stringify(leaderboard), ()=>{});
fs.writeFile('out/leaderboard.json', JSON.stringify(leaderboard), ()=>{});
sockets.forEach((s) => {
s.send('{"name": "leaderboard", "value": '+JSON.stringify(leaderboard)+'}');
});