Compare commits

...

5 Commits

Author SHA1 Message Date
4a1f565f72 feat(wasm): add index.html 2025-06-17 11:48:01 -05:00
2ddf2611d9 ci: add wasm32 cargo flags 2025-06-17 11:47:52 -05:00
b3a3664578 feat: game loop 2025-06-17 11:47:43 -05:00
2b667bb6a2 ci: add deploy workflow + build script 2025-06-17 11:47:25 -05:00
9a88e71202 chore: .idea folder in .gitignore 2025-06-17 11:47:18 -05:00
8 changed files with 143 additions and 0 deletions

28
.cargo/config.toml Normal file
View File

@@ -0,0 +1,28 @@
[target.wasm32-unknown-emscripten]
rustflags = [
"-C",
"link-arg=-s",
"-C",
"link-arg=FULL_ES2",
"-C",
"link-arg=-s",
"-C",
"link-arg=FULL_ES3",
"-C",
"link-arg=-s",
"-C",
"link-arg=USE_SDL=2",
"-C",
"link-arg=-s",
"-C",
"link-arg=MAX_WEBGL_VERSION=2 ",
"-C",
"link-arg=-s",
"-C",
"link-arg=MIN_WEBGL_VERSION=2",
"-C",
"link-arg=-s",
"-C",
"link-arg=ERROR_ON_UNDEFINED_SYMBOLS=0", # for ignoring some egl symbols. needed for wgpu
]

28
.github/workflows/deploy.yaml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Github Pages
on: [push]
permissions:
contents: write
jobs:
build-github-pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2 # repo checkout
- uses: mymindstorm/setup-emsdk@v11 # setup emscripten toolchain
# with:
# version: 3.1.35
- uses: actions-rs/toolchain@v1 # get rust toolchain for wasm
with:
toolchain: stable
target: wasm32-unknown-emscripten
override: true
- name: Rust Cache # cache the rust build artefacts
uses: Swatinem/rust-cache@v1
- name: Build # build
run: ./build.sh
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target
.idea

10
build.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -eux
cargo build --target=wasm32-unknown-emscripten --release
mkdir -p dist
cp target/wasm32-unknown-emscripten/release/rust_sdl2_wasm.wasm dist
cp target/wasm32-unknown-emscripten/release/rust-sdl2-wasm.js dist
cp index.html dist

21
index.html Normal file
View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript">
const Module = {
canvas: (function () {
// this is how we provide a canvas to our sdl2
return document.getElementById("canvas");
})(),
preRun: [function () {
ENV.RUST_LOG = "info,wgpu=warn"
}]
};
</script>
<script src="rust-sdl2-wasm.js"></script>
</body>
</html>

0
src/board.rs Normal file
View File

44
src/constants.rs Normal file
View File

@@ -0,0 +1,44 @@
pub const BOARD_WIDTH: u32 = 28;
pub const BOARD_HEIGHT: u32 = 36;
pub const BLOCK_SIZE_24: u32 = 24;
pub const BLOCK_SIZE_32: u32 = 32;
pub const WINDOW_WIDTH: u32 = BLOCK_SIZE_24 * BOARD_WIDTH;
pub const WINDOW_HEIGHT: u32 = BLOCK_SIZE_24 * BOARD_HEIGHT;
pub const RAW_BOARD: &str = r###"
############################
#............##............#
#.####.#####.##.#####.####.#
#o####.#####.##.#####.####o#
#.####.#####.##.#####.####.#
#..........................#
#.####.##.########.##.####.#
#.####.##.########.##.####.#
#......##....##....##......#
######.##### ## #####.######
#.##### ## #####.#
#.## 1 ##.#
#.## ###==### ##.#
######.## # # ##.######
. #2 3 4 # .
######.## # # ##.######
#.## ######## ##.#
#.## ##.#
#.## ######## ##.#
######.## ######## ##.######
#............##............#
#.####.#####.##.#####.####.#
#.####.#####.##.#####.####.#
#o..##.......0 .......##..o#
###.##.##.########.##.##.###
###.##.##.########.##.##.###
#......##....##....##......#
#.##########.##.##########.#
#.##########.##.##########.#
#..........................#
############################
"###;

11
src/game.rs Normal file
View File

@@ -0,0 +1,11 @@
pub struct Game {}
impl Game {
pub fn new() -> Game {
Game {}
}
pub fn tick() {}
pub fn draw() {}
}