Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustconf 2022 arcade patch #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions patchForArcade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const fs = require("fs");
const path = require("path");

function replaceCheck(original, search, replace) {
const result = original.replace(search, replace);
if (result === original) {
throw new Error(`Patch ${search} -> ${replace} failed.`);
}
return result;
}

function insertAfter(original, search, toInsert) {
const index = original.indexOf(search);

if (index === -1) {
throw new Error(`Patch failed for: ${toInsert}`);
}

const pos = index + search.length;
return original.substr(0, pos) + toInsert + original.substr(pos);
}

function main() {
const releaseHtmlPath = path.resolve(
__dirname,
"release/find-the-dogchicken-web.html"
);

let content = fs.readFileSync(releaseHtmlPath, { encoding: "utf-8" });

// X
content = replaceCheck(
content,
"(e[0].pressed||e[3].pressed||e[5].pressed||e[7].pressed)",
"(e[2].pressed||e[4].pressed)"
);

// Z
content = replaceCheck(
content,
"(e[1].pressed||e[2].pressed||e[4].pressed||e[6].pressed)",
"(e[1].pressed||e[3].pressed)"
);

// exit
content = replaceCheck(
content,
"e[9].pressed&&(this.showMenu=!0)",
"(e[5].pressed||e[10].pressed)&&(window.customExit())"
);

// exit script
content = insertAfter(
content,
"<body>",
"\n <script>window.customExit = () => { window.__TAURI_INVOKE__({ cmd: 'tauri', __tauriModule: 'Process', message: { cmd: 'exit', exitCode: 0 }}) }</script>\n"
);

fs.writeFileSync(releaseHtmlPath, content, { encoding: "utf-8" });

console.log("patchForArcade.js successful!");
}

main();
1 change: 1 addition & 0 deletions png2src.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/sh
w4 png2src --template png2src_template.txt --rust assets/objects.png > src/assets/objects_png.rs
w4 png2src --template png2src_template.txt --rust assets/controls.png > src/assets/controls_png.rs
1 change: 1 addition & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
cargo build --release
wasm-opt target/wasm32-unknown-unknown/release/cart.wasm -o target/wasm32-unknown-unknown/release/cart-opt.wasm -Oz --strip-dwarf --strip-producers --zero-filled-memory
w4 bundle target/wasm32-unknown-unknown/release/cart-opt.wasm --title "Find the DogChicken" --html release/find-the-dogchicken-web.html --windows release/find-the-dogchicken-win32.exe --linux release/find-the-dogchicken-linux
node patchForArcade.js

7 changes: 7 additions & 0 deletions src/assets/controls_png.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// controls_png
pub const CONTROLS_PNG_WIDTH: u32 = 96;
pub const CONTROLS_PNG_HEIGHT: u32 = 34;
pub const CONTROLS_PNG_FLAGS: u32 = 1; // BLIT_2BPP
#[rustfmt::skip]
pub const CONTROLS_PNG: [u8; 816] = [ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x3f,0xff,0xff,0x00,0x00,0xff,0xff,0xfc,0x00,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x15,0x55,0x4f,0xff,0xfc,0x55,0x55,0x3f,0xff,0xf1,0x55,0x54,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x55,0x55,0x53,0xff,0xf1,0x55,0x55,0x4f,0xff,0xc5,0x55,0x55,0x3f,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xf1,0x55,0x55,0x54,0xff,0xc5,0x55,0x55,0x53,0xff,0x15,0x55,0x55,0x4f,0xff,0xff,0xff,0xff,0xff,0xea,0xff,0xff,0xff,0xff,0xf1,0x6a,0xaa,0x55,0x3f,0xc5,0xa5,0x69,0x54,0xff,0x15,0x55,0x55,0x53,0xff,0xff,0xff,0xff,0xff,0xaa,0xbf,0xff,0xff,0xff,0xc5,0x55,0x6a,0x55,0x3f,0x15,0xa9,0xa9,0x54,0xfc,0x55,0x55,0x55,0x53,0xff,0xff,0xff,0xff,0xff,0xbb,0xbf,0xff,0xff,0xff,0xc5,0x55,0xa9,0x55,0x3f,0x15,0x6a,0xa5,0x54,0xfc,0x55,0x55,0x65,0x93,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xc5,0x56,0xa5,0x55,0x3f,0x15,0x5a,0x95,0x54,0xfc,0x55,0x55,0x55,0x93,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xc5,0x5a,0x95,0x55,0x3f,0x15,0x6a,0xa5,0x54,0xfc,0x6a,0x66,0x66,0xa3,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xc5,0x6a,0x55,0x55,0x3f,0x15,0xa9,0xa9,0x54,0xfc,0x66,0x66,0x65,0x93,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xc5,0x6a,0xaa,0x55,0x3f,0x15,0xa5,0x69,0x54,0xfc,0x6a,0x6a,0x65,0x93,0xff,0xff,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xc5,0x55,0x55,0x55,0x3f,0x15,0x55,0x55,0x54,0xfc,0x56,0x55,0x55,0x53,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x55,0x55,0x54,0xff,0xc5,0x55,0x55,0x53,0xff,0x16,0x55,0x55,0x4f,0xff,0xff,0xff,0xff,0xff,0x00,0x0f,0xff,0xff,0xff,0xf1,0x55,0x55,0x53,0xff,0xc5,0x55,0x55,0x4f,0xff,0x15,0x55,0x55,0x3f,0xff,0xff,0xff,0xff,0xfc,0x55,0x53,0xff,0xff,0xff,0xfc,0x15,0x55,0x0f,0xff,0xf0,0x55,0x54,0x3f,0xff,0xc1,0x55,0x50,0xff,0xff,0xff,0xfa,0xff,0xf1,0x55,0x53,0xff,0xeb,0xff,0xff,0xc0,0x00,0xff,0xff,0xff,0x00,0x03,0xff,0xff,0xfc,0x00,0x0f,0xff,0xff,0xff,0xeb,0xff,0xf1,0x55,0x53,0xff,0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xaa,0xaa,0xb1,0x55,0x53,0xaa,0xaa,0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xeb,0xff,0xf1,0x55,0x53,0xff,0xfa,0xff,0xff,0xff,0xff,0xf0,0x00,0x0f,0xff,0xff,0xc0,0x00,0x3f,0xff,0xff,0x00,0x00,0xff,0xfa,0xff,0xf1,0x55,0x53,0xff,0xeb,0xff,0xff,0xff,0xff,0xc5,0x55,0x53,0xff,0xff,0x15,0x55,0x4f,0xff,0xfc,0x55,0x55,0x3f,0xff,0xff,0xfc,0x55,0x4f,0xff,0xff,0xff,0xff,0xff,0xff,0x15,0x55,0x54,0xff,0xfc,0x55,0x55,0x53,0xff,0xf1,0x55,0x55,0x4f,0xff,0xff,0xff,0x00,0x3f,0xff,0xff,0xff,0xff,0xff,0xfc,0x55,0x55,0x55,0x3f,0xf1,0x55,0x55,0x54,0xff,0xc5,0x55,0x55,0x53,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x5a,0xaa,0x95,0x4f,0xf1,0x69,0x5a,0x55,0x3f,0xc5,0x55,0x55,0x54,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x55,0x5a,0x95,0x4f,0xc5,0x6a,0x6a,0x55,0x3f,0x15,0x55,0x55,0x54,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x55,0x6a,0x55,0x4f,0xc5,0x5a,0xa9,0x55,0x3f,0x15,0x55,0x59,0x64,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x55,0xa9,0x55,0x4f,0xc5,0x56,0xa5,0x55,0x3f,0x15,0x55,0x55,0x64,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x56,0xa5,0x55,0x4f,0xc5,0x5a,0xa9,0x55,0x3f,0x1a,0x99,0x99,0xa8,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xf1,0x5a,0x95,0x55,0x4f,0xc5,0x6a,0x6a,0x55,0x3f,0x19,0x99,0x99,0x64,0xff,0xff,0xff,0xbb,0xbf,0xff,0xff,0xff,0xff,0xff,0xf1,0x5a,0xaa,0x95,0x4f,0xc5,0x69,0x5a,0x55,0x3f,0x1a,0x9a,0x99,0x64,0xff,0xff,0xff,0xaa,0xbf,0xff,0xff,0xff,0xff,0xff,0xf1,0x55,0x55,0x55,0x4f,0xc5,0x55,0x55,0x55,0x3f,0x15,0x95,0x55,0x54,0xff,0xff,0xff,0xea,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x55,0x55,0x55,0x3f,0xf1,0x55,0x55,0x54,0xff,0xc5,0x95,0x55,0x53,0xff,0xff,0xff,0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x55,0x55,0x54,0xff,0xf1,0x55,0x55,0x53,0xff,0xc5,0x55,0x55,0x4f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x05,0x55,0x43,0xff,0xfc,0x15,0x55,0x0f,0xff,0xf0,0x55,0x54,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x3f,0xff,0xff,0xc0,0x00,0xff,0xff,0xff,0x00,0x03,0xff ];

1 change: 1 addition & 0 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod controls_png;
pub mod objects_png;
1 change: 1 addition & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl Input {
self.pressed & buttons != 0
}

#[allow(dead_code)]
pub fn pressed_any(&self) -> bool {
self.pressed != 0
}
Expand Down
10 changes: 7 additions & 3 deletions src/screens/ingame/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn draw_select_item_frame(color: u16, x: i32, y: i32) {
rect(x - 2, y - 2, ui::ITEM_WIDTH_PX + 4, ui::ITEM_HEIGHT_PX + 4);
}

fn draw_select_item(item: &Option<Item>, x: i32, y: i32) {
fn draw_select_item(item: &Option<Item>, x: i32, y: i32, is_left: bool) {
let color = match item {
Some(_) => 0x22,
None => 0x30,
Expand All @@ -31,6 +31,10 @@ fn draw_select_item(item: &Option<Item>, x: i32, y: i32) {

if let Some(item) = item {
ui::draw_item(*item, x, y);
} else if is_left {
ui::draw_text(" Z\nkey", x, y + 4);
} else {
ui::draw_text(" X\nkey", x, y + 4);
}
}

Expand Down Expand Up @@ -90,9 +94,9 @@ impl CombineUi {
}

pub fn draw(&self) {
draw_select_item(&self.left, 18, 16);
draw_select_item(&self.left, 18, 16, true);
ui::draw_text("+", 50, 16 + 8);
draw_select_item(&self.right, 66, 16);
draw_select_item(&self.right, 66, 16, false);
ui::draw_text("=", 100, 16 + 8);
draw_result_box(&self.result, 116, 16);
}
Expand Down
4 changes: 2 additions & 2 deletions src/screens/ingame/found_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
input::Input,
item::Item,
ui,
wasm4::{rect, DRAW_COLORS},
wasm4::{rect, BUTTON_1, BUTTON_2, DRAW_COLORS},
};

pub struct FoundPopup {
Expand All @@ -19,7 +19,7 @@ impl FoundPopup {
}

pub fn update(&mut self, input: &Input) {
if input.pressed_any() {
if input.pressed(BUTTON_1) || input.pressed(BUTTON_2) {
self.found_item = None;
}
}
Expand Down
27 changes: 20 additions & 7 deletions src/screens/intro.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use super::{ingame::IngameScreen, Screen};
use crate::{input::Input, item::Item, ui};
use crate::{
assets::controls_png::{
CONTROLS_PNG, CONTROLS_PNG_FLAGS, CONTROLS_PNG_HEIGHT, CONTROLS_PNG_WIDTH,
},
input::Input,
item::Item,
ui,
wasm4::BUTTON_1,
wasm4::{blit, BUTTON_2},
};

pub struct IntroScreen;

impl Screen for IntroScreen {
fn update(&mut self, input: &Input) -> Option<Box<dyn Screen + Send>> {
if input.pressed_any() {
if input.pressed(BUTTON_1) || input.pressed(BUTTON_2) {
return Some(Box::new(IngameScreen::new()));
}
None
Expand All @@ -15,13 +24,17 @@ impl Screen for IntroScreen {
ui::draw_text_top_center("Find the\nDogChicken", 80, 8);

ui::draw_item(Item::DogChicken, 80 - (ui::ITEM_WIDTH_PX as i32 / 2), 32);

ui::draw_text_top_center(
"Controls:\nZ: Select left\nX: Select right\n<>^v: Move cursor",
80,
80,
blit(
&CONTROLS_PNG,
(160 - (CONTROLS_PNG_WIDTH as i32)) / 2,
90,
CONTROLS_PNG_WIDTH,
CONTROLS_PNG_HEIGHT,
CONTROLS_PNG_FLAGS,
);

ui::draw_text_top_center("Controls:", 80, 80);

ui::draw_text_top_center("[Press Z/X\nto start]", 80, 140);
}
}
16 changes: 12 additions & 4 deletions src/screens/win.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use super::Screen;
use crate::{input::Input, item::Item, ui};
use super::{ingame::IngameScreen, Screen};
use crate::{
input::Input,
item::Item,
ui,
wasm4::{BUTTON_1, BUTTON_2},
};
use strum::IntoEnumIterator;

pub struct WinScreen {
Expand All @@ -17,14 +22,17 @@ impl WinScreen {
}

impl Screen for WinScreen {
fn update(&mut self, _input: &Input) -> Option<Box<dyn Screen + Send>> {
fn update(&mut self, input: &Input) -> Option<Box<dyn Screen + Send>> {
if input.pressed(BUTTON_1) && input.pressed(BUTTON_2) {
return Some(Box::new(IngameScreen::new()));
}
None
}

fn draw(&self) {
ui::draw_text_top_center("YOU FOUND\nTHE DOGCHICKEN!", 80, 32);
ui::draw_item(Item::DogChicken, 80 - (ui::ITEM_WIDTH_PX as i32 / 2), 64);
ui::draw_text_top_center("Thank you for\nplaying", 80, 110);
ui::draw_text_top_center("Thank you for\nplaying\n(Z+X to restart)", 80, 110);
ui::draw_text_bottom_left(
format!(
"<{}/{} found>",
Expand Down