Guide for the frontend code
As we prompted previously, the entire frontend project is located in `src/`, and the frontend of the rogoulike card game is located in `src/games/roguelike`.
`src/games/roguelike` has the following structure. These file names are self-explanation.
.
โโโ card.tsx
โโโ controller.tsx
โโโ death.tsx
โโโ images
โย ย โโโ cheems-monster-01.jpg
โย ย โโโ cheems-monster-02.jpg
โย ย โโโ cheems.jpg
โย ย โโโ d0.png
โย ย โโโ d1.png
โย ย โโโ d10.png
โย ย โโโ d11.png
โย ย โโโ d2.png
โย ย โโโ d3.png
โย ย โโโ d4.png
โย ย โโโ d5.png
โย ย โโโ d6.png
โย ย โโโ d7.png
โย ย โโโ d8.png
โย ย โโโ d9.png
โย ย โโโ gameover.png
โโโ js
โย ย โโโ config.js
โย ย โโโ game.js
โย ย โโโ gameplay.d.ts
โย ย โโโ gameplay_bg.js
โย ย โโโ gameplay_bg.wasm
โย ย โโโ gameplay_bg.wasm.d.ts
โย ย โโโ package.json
โโโ style.scss
โโโ tile.ts
Files in js dir were copied from the backend project.
In the `controller.tsx`, we can see:
import init, * as gameplay from "./js";
function initGame(l2account: number) {
(init as any)().then(() => {
console.log("setting instance");
console.log(gameplay);
gameplay.new_game();
gameplay.challenge_next_floor();
const stateStr = gameplay.state();
const state = JSON.parse(stateStr);
console.log(":state:", state);
setState(state);
dispatch(setMD5(ImageMD5));
dispatch(setLoaded(true));
//drawObjects(objects);
});
}
...
We import the exported facilities of the backend into the frontend project, naming it as `gameplay`, and later use this handle to call functions in wasm. Just like:
gameplay.new_game();
gameplay.challenge_next_floor();
in the above code snippet.
Once you get it, the thing will become clear to you. Other code is just ordinary typescript/tsx code, which is easy to study.
Last updated