chore: refactors files path
This commit is contained in:
parent
ac5a285ed4
commit
3c7792eba9
6
app.c
6
app.c
|
@ -1,6 +1,6 @@
|
||||||
#include "pengers.h"
|
#include "out/pengers.h"
|
||||||
#include "hand.c"
|
#include "out/hand.c"
|
||||||
#include "coin.c"
|
#include "out/coin.c"
|
||||||
|
|
||||||
#define GREEN 0xff00ff00
|
#define GREEN 0xff00ff00
|
||||||
#define RED 0xff0000ff
|
#define RED 0xff0000ff
|
||||||
|
|
33
build.sh
33
build.sh
|
@ -1,7 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ "$1" == "clear" ]]; then
|
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
|
exit
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
@ -21,39 +22,41 @@ fi
|
||||||
|
|
||||||
#set -xe
|
#set -xe
|
||||||
|
|
||||||
clang png2c.c -o png2c -lm
|
clang png2c.c -o out/png2c -lm
|
||||||
mkdir -p museum.c
|
mkdir -p out/museum.c
|
||||||
rm -f museum.c/*
|
rm -f out/museum.c/*
|
||||||
|
|
||||||
pengers_html=$'\n'
|
pengers_html=$'\n'
|
||||||
pengers_include=$'\n'
|
pengers_include=$'\n'
|
||||||
id=0
|
id=0
|
||||||
for p in $(ls static/museum/); do
|
for p in $(ls static/museum/); do
|
||||||
file=$(echo $p | sed "s/\.png$//g")
|
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_html+=$' <img src="static/museum/'$p'" class="penger-img" penger-id="'$id'"></img>\n'
|
||||||
pengers_include+='#include "museum.c/'$file$'.c"\n'
|
pengers_include+='#include "museum.c/'$file$'.c"\n'
|
||||||
((id=id+1))
|
((id=id+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "int pengers_height[$id];" > pengers.h
|
echo "int pengers_height[$id];" > out/pengers.h
|
||||||
echo "int pengers_width[$id];" >> pengers.h
|
echo "int pengers_width[$id];" >> out/pengers.h
|
||||||
echo "unsigned int *pengers_img[$id];" >> pengers.h
|
echo "unsigned int *pengers_img[$id];" >> out/pengers.h
|
||||||
echo "$pengers_include" >> pengers.h
|
echo "$pengers_include" >> out/pengers.h
|
||||||
echo "void pengers_init(void) {" >> pengers.h
|
echo "void pengers_init(void) {" >> out/pengers.h
|
||||||
((id=id-1))
|
((id=id-1))
|
||||||
for i in $(seq 0 $id); do
|
for i in $(seq 0 $id); do
|
||||||
echo " penger_init_$i();" >> pengers.h;
|
echo " penger_init_$i();" >> out/pengers.h;
|
||||||
done
|
done
|
||||||
echo "}" >> pengers.h
|
echo "}" >> out/pengers.h
|
||||||
|
|
||||||
echo -e "$pengers_html" > pengers_image.html.temp
|
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
|
rm pengers_image.html.temp
|
||||||
|
|
||||||
./out/png2c "static/assets/hand.png" > out/hand.c
|
./out/png2c "static/assets/hand.png" > out/hand.c
|
||||||
./out/png2c "static/assets/coin.png" > out/coin.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
|
2
load.js
2
load.js
|
@ -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({
|
"env": make_environment({
|
||||||
// importer les fonctions dans le wasm
|
// importer les fonctions dans le wasm
|
||||||
'random': Math.random,
|
'random': Math.random,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
var leaderboard = JSON.parse(fs.readFileSync("leaderboard.json"));
|
var leaderboard = JSON.parse(fs.readFileSync("out/leaderboard.json"));
|
||||||
leaderboard.today = [
|
leaderboard.today = [
|
||||||
{name: 'none', value: '0'},
|
{name: 'none', value: '0'},
|
||||||
{name: 'none', value: '0'},
|
{name: 'none', value: '0'},
|
||||||
|
@ -8,4 +8,4 @@ leaderboard.today = [
|
||||||
{name: 'none', value: '0'},
|
{name: 'none', value: '0'},
|
||||||
{name: 'none', value: '0'}
|
{name: 'none', value: '0'}
|
||||||
];
|
];
|
||||||
fs.writeFile('leaderboard.json', JSON.stringify(leaderboard), ()=>{});
|
fs.writeFile('out/leaderboard.json', JSON.stringify(leaderboard), ()=>{});
|
||||||
|
|
11
server.js
11
server.js
|
@ -46,6 +46,7 @@ function send_new_map()
|
||||||
});
|
});
|
||||||
setTimeout(send_new_map, map_every_ms);
|
setTimeout(send_new_map, map_every_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(send_new_map, map_every_ms);
|
setTimeout(send_new_map, map_every_ms);
|
||||||
function send_map(socket)
|
function send_map(socket)
|
||||||
{
|
{
|
||||||
|
@ -55,14 +56,14 @@ function send_map(socket)
|
||||||
const requestListener = function (req, res) {
|
const requestListener = function (req, res) {
|
||||||
var url = req.url;
|
var url = req.url;
|
||||||
|
|
||||||
if (url == "/" || url == "/index.html") {
|
if (url == "/") {
|
||||||
res.setHeader("Content-Type", "text/html");
|
res.setHeader("Content-Type", "text/html");
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(fs.readFileSync("./index.html"));
|
res.end(fs.readFileSync("./out/index.html"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url == "/app.wasm") {
|
if (url == "/out/app.wasm") {
|
||||||
res.setHeader("Content-Type", "application/wasm");
|
res.setHeader("Content-Type", "application/wasm");
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(fs.readFileSync("." + url));
|
res.end(fs.readFileSync("." + url));
|
||||||
|
@ -108,7 +109,7 @@ http_server.listen(HTTP_PORT, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
var maps = JSON.parse(fs.readFileSync("maps.json"));
|
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 });
|
const ws_server = new ws.Server({ port: WS_PORT });
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ ws_server.on('connection', (socket) => {
|
||||||
leaderboard.total.pop();
|
leaderboard.total.pop();
|
||||||
}
|
}
|
||||||
if (update_leaderboard) {
|
if (update_leaderboard) {
|
||||||
fs.writeFile('leaderboard.json', JSON.stringify(leaderboard), ()=>{});
|
fs.writeFile('out/leaderboard.json', JSON.stringify(leaderboard), ()=>{});
|
||||||
sockets.forEach((s) => {
|
sockets.forEach((s) => {
|
||||||
s.send('{"name": "leaderboard", "value": '+JSON.stringify(leaderboard)+'}');
|
s.send('{"name": "leaderboard", "value": '+JSON.stringify(leaderboard)+'}');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue