saving my place

main
Elijah Voigt 1 year ago
parent f8ce9b41b2
commit f65d2eea63

@ -1,11 +1,11 @@
[unstable] # [unstable]
codegen-backend = true # codegen-backend = true
[profile.dev] # [profile.dev]
codegen-backend = "cranelift" # codegen-backend = "cranelift"
[profile.dev.package."*"] # [profile.dev.package."*"]
codegen-backend = "llvm" # codegen-backend = "llvm"
# for Linux # for Linux
[target.x86_64-unknown-linux-gnu] [target.x86_64-unknown-linux-gnu]

3
.gitignore vendored

@ -4,3 +4,6 @@
# Nix generated files # Nix generated files
.direnv/ .direnv/
result/ result/
# Web target
out/

99
Cargo.lock generated

@ -306,7 +306,6 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6a01cd51a5cd310e4e7aa6e1560b1aabf29efc6a095a01e6daa8bf0a19f1fea" checksum = "b6a01cd51a5cd310e4e7aa6e1560b1aabf29efc6a095a01e6daa8bf0a19f1fea"
dependencies = [ dependencies = [
"bevy_dylib",
"bevy_internal", "bevy_internal",
] ]
@ -525,15 +524,6 @@ dependencies = [
"sysinfo", "sysinfo",
] ]
[[package]]
name = "bevy_dylib"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b0c60e568493ac23c001d22f47b99818efe1e992253e2ab3fdb69603b2aa1c"
dependencies = [
"bevy_internal",
]
[[package]] [[package]]
name = "bevy_ecs" name = "bevy_ecs"
version = "0.15.0" version = "0.15.0"
@ -1409,9 +1399,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.2" version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
@ -1912,15 +1902,15 @@ dependencies = [
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.2.0" version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]] [[package]]
name = "fdeflate" name = "fdeflate"
version = "0.3.6" version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07c6f4c64c1d33a3111c4466f7365ebdcc37c5bd1ea0d62aae2e3d722aacbedb" checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
dependencies = [ dependencies = [
"simd-adler32", "simd-adler32",
] ]
@ -2418,11 +2408,10 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.74" version = "0.3.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9"
dependencies = [ dependencies = [
"once_cell",
"wasm-bindgen", "wasm-bindgen",
] ]
@ -2471,9 +2460,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.167" version = "0.2.168"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d"
[[package]] [[package]]
name = "libloading" name = "libloading"
@ -2499,7 +2488,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"libc", "libc",
"redox_syscall 0.5.7", "redox_syscall 0.5.8",
] ]
[[package]] [[package]]
@ -3096,7 +3085,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall 0.5.7", "redox_syscall 0.5.8",
"smallvec", "smallvec",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
@ -3170,9 +3159,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]] [[package]]
name = "png" name = "png"
version = "0.17.14" version = "0.17.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0" checksum = "b67582bd5b65bdff614270e2ea89a1cf15bef71245cc1e5f7ea126977144211d"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"crc32fast", "crc32fast",
@ -3349,9 +3338,9 @@ dependencies = [
[[package]] [[package]]
name = "read-fonts" name = "read-fonts"
version = "0.22.5" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a04b892cb6f91951f144c33321843790c8574c825aafdb16d815fd7183b5229" checksum = "69aacb76b5c29acfb7f90155d39759a29496aebb49395830e928a9703d2eec2f"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"font-types", "font-types",
@ -3374,9 +3363,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.5.7" version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
@ -3468,15 +3457,15 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.41" version = "0.38.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -3528,9 +3517,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "self_cell" name = "self_cell"
version = "1.0.4" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe"
[[package]] [[package]]
name = "send_wrapper" name = "send_wrapper"
@ -3540,18 +3529,18 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.215" version = "1.0.216"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.215" version = "1.0.216"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3575,6 +3564,7 @@ name = "set"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"wasm-bindgen",
] ]
[[package]] [[package]]
@ -4026,9 +4016,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.97" version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@ -4037,9 +4027,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.97" version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
@ -4052,22 +4042,21 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.47" version = "0.4.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
"once_cell",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
] ]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.97" version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -4075,9 +4064,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.97" version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4088,15 +4077,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.97" version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.74" version = "0.3.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -4697,9 +4686,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
[[package]] [[package]]
name = "xml-rs" name = "xml-rs"
version = "0.8.23" version = "0.8.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432"
[[package]] [[package]]
name = "yazi" name = "yazi"

@ -4,7 +4,8 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bevy = { package = "bevy", version = "0.15"} wasm-bindgen = { version = "= 0.2.95" }
bevy = "0.15"
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1
@ -12,5 +13,7 @@ opt-level = 1
[profile.dev.package."*"] [profile.dev.package."*"]
opt-level = 3 opt-level = 3
[features] [profile.release]
default = ["bevy/dynamic_linking"] lto = true
codegen-units = 1
opt-level = 'z' # 's'

@ -0,0 +1,35 @@
ifeq ($(PROFILE),release)
RELEASE = --release
PROFILE = release
else
PROFILE = debug
endif
target/x86_64-unknown-linux-gnu/$(PROFILE)/set: src/*
cargo build --target x86_64-unknown-linux-gnu --features bevy/dynamic_linking $(RELEASE)
target/wasm32-unknown-unknown/$(PROFILE)/set.wasm: src/*
cargo build --target wasm32-unknown-unknown $(RELEASE)
out/$(PROFILE)/set.js: target/wasm32-unknown-unknown/$(PROFILE)/set.wasm
wasm-bindgen --no-typescript --target web --out-dir "./out/$(PROFILE)" ./target/wasm32-unknown-unknown/$(PROFILE)/set.wasm
out/$(PROFILE)/assets:
rm -rf ./out/$(PROFILE)/assets
cp -r ./assets ./out/$(PROFILE)/
out/$(PROFILE)/index.html:
cp index.html ./out/$(PROFILE)/index.html
native/build: target/x86_64-unknown-linux-gnu/$(PROFILE)/set
native/run: native/build
cargo run --target x86_64-unknown-linux-gnu --features bevy/dynamic_linking $(RELEASE)
web/build: out/$(PROFILE)/set.js out/$(PROFILE)/assets out/$(PROFILE)/index.html
web/serve: web/build
cd ./out/$(PROFILE)/; simple-http-server
clean:
rm ./target/*/*/set*

@ -28,10 +28,10 @@
]; ];
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
libxkbcommon libxkbcommon
(rust-bin.selectLatestNightlyWith (rust-bin.stable.latest.default.override {
(toolchain: toolchain.default.override { extensions = [ "rust-src" "clippy" ];
extensions = [ "rust-src" "clippy" "rustc-codegen-cranelift-preview"]; targets = [ "x86_64-unknown-linux-gnu" "wasm32-unknown-unknown" ];
})) })
]; ];
all_deps = with pkgs; [ all_deps = with pkgs; [
cargo-flamegraph cargo-flamegraph
@ -39,6 +39,9 @@
nixpkgs-fmt nixpkgs-fmt
cmake cmake
rx rx
wasm-pack
wasm-bindgen-cli
simple-http-server
] ++ buildInputs ++ nativeBuildInputs; ] ++ buildInputs ++ nativeBuildInputs;
in in
rec { rec {

@ -0,0 +1,27 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<style>
body {
background: linear-gradient(
135deg,
white 0%,
white 49%,
black 49%,
black 51%,
white 51%,
white 100%
) repeat;
background-size: 20px 20px;
}
canvas {
background-color: white;
}
</style>
<title>s e t</title>
</head>
<script type="module">
import init from './set.js'
init()
</script>
</html>

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "nightly" channel = "stable"
components = [ "rust-src", "clippy", "rustc-codegen-cranelift-preview"]; components = [ "rust-src", "clippy", "rustc-codegen-cranelift-preview"];

@ -6,7 +6,7 @@ pub struct BootPlugin;
impl Plugin for BootPlugin { impl Plugin for BootPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, (boot::load, boot::start_setup).chain()); app.add_systems(Startup, (load, start_setup).chain());
} }
} }

@ -1,4 +1,4 @@
use bevy::prelude::*; use bevy::{color::palettes::css::BLACK, prelude::*, window::WindowResized};
use crate::deck::Card; use crate::deck::Card;
@ -8,6 +8,7 @@ pub struct DebugPlugin;
impl Plugin for DebugPlugin { impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_observer(track_card_info) app.add_observer(track_card_info)
.add_systems(Update, update_window_info)
.add_systems(Startup, init_ui); .add_systems(Startup, init_ui);
} }
} }
@ -15,6 +16,9 @@ impl Plugin for DebugPlugin {
#[derive(Component)] #[derive(Component)]
pub(crate) struct DebugText; pub(crate) struct DebugText;
#[derive(Component)]
pub(crate) struct WindowInfoText;
fn init_ui(mut commands: Commands) { fn init_ui(mut commands: Commands) {
commands commands
.spawn(( .spawn((
@ -32,6 +36,45 @@ fn init_ui(mut commands: Commands) {
PickingBehavior::IGNORE, PickingBehavior::IGNORE,
)); ));
}); });
commands
.spawn((
Node {
position_type: PositionType::Absolute,
top: Val::Px(0.0),
right: Val::Px(0.0),
..default()
},
BackgroundColor(BLACK.into()),
GlobalZIndex(1),
))
.with_children(|parent| {
parent
.spawn(Button)
.with_children(|parent| {
parent.spawn((
Text("-".into()),
TextFont {
font_size: 60.0,
..default()
},
));
})
.observe(decrease_scale_ratio);
parent
.spawn(Button)
.with_children(|parent| {
parent.spawn((
Text("+".into()),
TextFont {
font_size: 60.0,
..default()
},
));
})
.observe(increase_scale_ratio);
parent.spawn((Text("????x????".to_string()), WindowInfoText));
});
} }
fn track_card_info( fn track_card_info(
@ -71,3 +114,42 @@ pub(crate) fn hide_debug_card(
*v = Visibility::Hidden; *v = Visibility::Hidden;
}); });
} }
fn update_window_info(
mut events: EventReader<WindowResized>,
windows: Query<&mut Window>,
mut infos: Query<&mut Text, With<WindowInfoText>>,
) {
events.read().for_each(|_| {
info!("Window resized");
let window = windows.single();
let width = window.resolution.width();
let height = window.resolution.height();
let scale_factor = window.resolution.scale_factor();
let mut info = infos.single_mut();
info.0 = format!("{:.0}x{:.0} ({:.03})", width, height, scale_factor,);
});
}
fn increase_scale_ratio(
_trigger: Trigger<Pointer<Click>>,
// TODO: Move window scale factor out to non-debug system
mut windows: Query<&mut Window>,
) {
info!("increase scale ratio");
let mut window = windows.single_mut();
let current = window.scale_factor();
window.resolution.set_scale_factor(current + 0.05);
}
fn decrease_scale_ratio(
_trigger: Trigger<Pointer<Click>>,
// TODO: Move window scale factor out to non-debug system
mut windows: Query<&mut Window>,
) {
info!("decrease scale ratio");
let mut window = windows.single_mut();
let current = window.scale_factor();
window.resolution.set_scale_factor(current - 0.05);
}

@ -9,8 +9,20 @@ mod view;
use bevy::prelude::*; use bevy::prelude::*;
fn main() { fn main() {
let primary_window = Some(Window {
// web: fill the window
fit_canvas_to_parent: true,
..default()
});
App::new() App::new()
.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) .add_plugins(
DefaultPlugins
.set(ImagePlugin::default_nearest())
.set(WindowPlugin {
primary_window,
..default()
}),
)
.add_plugins(( .add_plugins((
view::ViewPlugin, view::ViewPlugin,
deck::DeckPlugin, deck::DeckPlugin,
@ -18,7 +30,7 @@ fn main() {
setup::SetupPlugin, setup::SetupPlugin,
play::PlayPlugin, play::PlayPlugin,
menu::MenuPlugin, menu::MenuPlugin,
debug::DebugPlugin, // debug::DebugPlugin,
)) ))
.init_state::<GameState>() .init_state::<GameState>()
.run(); .run();

@ -1,10 +1,12 @@
use bevy::{ use bevy::{
color::palettes::css::{BLACK, GREEN, INDIGO, ORANGE, PURPLE, RED, TEAL}, color::palettes::css::{BLACK, WHITE},
prelude::*, prelude::*,
}; };
use crate::{ use crate::{
play::check_for_sets, boot,
deck::{Card, Deck, ItemColor, ItemNumber, ItemPattern, ItemShape},
play::{check_for_sets, check_set},
view::{button_set_state, ViewState}, view::{button_set_state, ViewState},
}; };
@ -18,70 +20,126 @@ impl Plugin for MenuPlugin {
( (
setup, setup,
setup_about, setup_about,
setup_how_to_play, setup_how_to_play.after(boot::load),
setup_deck, setup_deck,
setup_sets, setup_sets,
setup_set_check_button,
), ),
); );
} }
} }
fn button_builder(node: Node) -> (Button, BackgroundColor, Node, BorderColor) {
(
Button,
BackgroundColor(BLACK.with_alpha(0.9).into()),
Node {
padding: UiRect::all(Val::Px(10.)),
margin: UiRect::top(Val::Px(25.)),
border: UiRect::all(Val::Px(1.0)),
..node
},
BorderColor(WHITE.into()),
)
}
fn setup(mut commands: Commands) { fn setup(mut commands: Commands) {
commands commands
.spawn((ViewState::Menu, Node::default())) .spawn((
ViewState::Menu,
Node {
position_type: PositionType::Absolute,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..default()
},
))
.with_children(|parent| {
parent
.spawn(Node {
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
..default()
})
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Play".to_string())); parent.spawn(Text("Play".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::Play)); .observe(button_set_state(ViewState::Play));
parent parent
.spawn((Button, BackgroundColor(ORANGE.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("About".to_string())); parent.spawn(Text("About".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::About)); .observe(button_set_state(ViewState::About));
parent parent
.spawn((Button, BackgroundColor(PURPLE.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("How to Play".to_string())); parent.spawn(Text("How to Play".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::HowToPlay)); .observe(button_set_state(ViewState::HowToPlay));
#[cfg(not(target_arch = "wasm32"))]
parent parent
.spawn((Button, BackgroundColor(RED.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Quit".to_string())); parent.spawn(Text("Quit".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(quit_button); .observe(quit_button);
}); });
});
commands commands
.spawn((ViewState::Play, Node::default())) .spawn((ViewState::Play, Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()), GlobalZIndex(1))) .spawn((button_builder(Node::default()), GlobalZIndex(1)))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Menu".to_string())); parent.spawn(Text("Menu".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::Menu)); .observe(button_set_state(ViewState::Menu));
/*
parent parent
.spawn((Button, BackgroundColor(INDIGO.into()), GlobalZIndex(1))) .spawn((button_builder(Node::default()), GlobalZIndex(1)))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Deck".to_string())); parent.spawn(Text("Deck".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::Deck)); .observe(button_set_state(ViewState::Deck));
*/
/*
parent parent
.spawn((Button, BackgroundColor(ORANGE.into()), GlobalZIndex(1))) .spawn((button_builder(Node::default()), GlobalZIndex(1)))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Sets".to_string())); parent.spawn(Text("Sets".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(button_set_state(ViewState::Sets)); .observe(button_set_state(ViewState::Sets));
*/
parent parent
.spawn((Button, BackgroundColor(GREEN.into()), GlobalZIndex(1))) .spawn((button_builder(Node::default()), GlobalZIndex(1)))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Help!".to_string())); parent.spawn(Text("Help!".to_string()));
}) })
.observe(button_hover_on)
.observe(button_hover_off)
.observe(check_for_sets); .observe(check_for_sets);
}); });
} }
@ -91,33 +149,151 @@ fn setup_about(mut commands: Commands) {
.spawn((ViewState::About, Node::default())) .spawn((ViewState::About, Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Menu".to_string())); parent.spawn(Text("Menu".to_string()));
}) })
.observe(button_set_state(ViewState::Menu)); .observe(button_set_state(ViewState::Menu));
parent.spawn((
Text("This is the about page".to_string()),
BackgroundColor(BLACK.into()),
));
}); });
} }
fn setup_how_to_play(mut commands: Commands) { fn setup_how_to_play(mut commands: Commands, deck: Res<Deck>) {
commands commands
.spawn((ViewState::HowToPlay, Node::default())) .spawn((
ViewState::HowToPlay,
Node {
position_type: PositionType::Absolute,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
..default()
},
))
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()))) .spawn(button_builder(Node {
position_type: PositionType::Absolute,
top: Val::Px(0.0),
left: Val::Px(0.0),
..default()
}))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Menu".to_string())); parent.spawn(Text("Menu".to_string()));
}) })
.observe(button_set_state(ViewState::Menu)); .observe(button_set_state(ViewState::Menu));
parent.spawn((Node {
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
..default()
},
BackgroundColor(BLACK.with_alpha(0.9).into()),
)).with_children(|parent| {
let most_matching = (
Card {
color: ItemColor::Red,
shape: ItemShape::Squiggle,
number: ItemNumber::One,
pattern: ItemPattern::Solid,
},
Card {
color: ItemColor::Red,
shape: ItemShape::Squiggle,
number: ItemNumber::Two,
pattern: ItemPattern::Solid,
},
Card {
color: ItemColor::Red,
shape: ItemShape::Squiggle,
number: ItemNumber::Three,
pattern: ItemPattern::Solid,
}
);
let most_not_matching = (
Card {
color: ItemColor::Green,
shape: ItemShape::Oval,
number: ItemNumber::Three,
pattern: ItemPattern::Solid,
},
Card {
color: ItemColor::Purple,
shape: ItemShape::Squiggle,
number: ItemNumber::Three,
pattern: ItemPattern::Striped,
},
Card {
color: ItemColor::Red,
shape: ItemShape::Diamond,
number: ItemNumber::Three,
pattern: ItemPattern::Open,
}
);
let not_valid = (
Card {
color: ItemColor::Purple,
shape: ItemShape::Oval,
number: ItemNumber::Three,
pattern: ItemPattern::Striped,
},
Card {
color: ItemColor::Purple,
shape: ItemShape::Oval,
number: ItemNumber::Two,
pattern: ItemPattern::Striped,
},
Card {
color: ItemColor::Purple,
shape: ItemShape::Oval,
number: ItemNumber::Three,
pattern: ItemPattern::Open,
}
);
[
("Find groups of 3 cards", None),
("All cards in a set must match or differ in their traits: Color, Number, Shading, and Shape.", None),
("For example all agree on Color, Shading, and Shape but not Number...", Some(most_matching)),
("...or all agree on Number but not Color, Number, Shading, and Shape...", Some(most_not_matching)),
("...but never partial agreement on a trait...", Some(not_valid)),
("When in doubt, click the 'Help!' button to get an assist", None),
]
.iter()
.for_each(|(t, example)| {
parent.spawn((
Node {
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
..default()
},
)).with_children(|parent| {
parent.spawn((
Node {
margin: UiRect::all(Val::Px(5.0)),
padding: UiRect::all(Val::Px(5.0)),
..default()
},
Text(t.to_string()),
));
if let Some((a, b, c)) = example {
[a, b, c].iter().for_each(|x| {
let sprite = deck.cards.get(*x).unwrap();
parent.spawn(( parent.spawn((
Text("This is the how to play page".to_string()), Node {
BackgroundColor(BLACK.into()), height: Val::Px(100.0),
..default()
},
ImageNode {
image: sprite.image.clone(),
texture_atlas: sprite.texture_atlas.clone(),
..default()
}
)); ));
}); });
};
});
});
});
});
} }
fn setup_deck(mut commands: Commands) { fn setup_deck(mut commands: Commands) {
@ -125,7 +301,7 @@ fn setup_deck(mut commands: Commands) {
.spawn((ViewState::Deck, Node::default())) .spawn((ViewState::Deck, Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Back".to_string())); parent.spawn(Text("Back".to_string()));
}) })
@ -138,7 +314,7 @@ fn setup_sets(mut commands: Commands) {
.spawn((ViewState::Sets, Node::default())) .spawn((ViewState::Sets, Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn((Button, BackgroundColor(TEAL.into()))) .spawn(button_builder(Node::default()))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(Text("Back".to_string())); parent.spawn(Text("Back".to_string()));
}) })
@ -146,6 +322,40 @@ fn setup_sets(mut commands: Commands) {
}); });
} }
pub(crate) fn setup_set_check_button(mut commands: Commands) {
commands
.spawn((
Node {
width: Val::Percent(100.0),
position_type: PositionType::Absolute,
top: Val::Px(0.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..default()
},
Visibility::default(),
ViewState::Play,
))
.with_children(|parent| {
parent
.spawn(button_builder(Node::default()))
.with_children(|parent| {
parent.spawn(Text("Set!".to_string()));
})
.observe(check_set);
});
}
fn quit_button(_trigger: Trigger<Pointer<Click>>, mut exit_event: EventWriter<AppExit>) { fn quit_button(_trigger: Trigger<Pointer<Click>>, mut exit_event: EventWriter<AppExit>) {
exit_event.send(AppExit::Success); exit_event.send(AppExit::Success);
} }
fn button_hover_on(trigger: Trigger<Pointer<Over>>, mut query: Query<&mut BackgroundColor>) {
let mut background_color = query.get_mut(trigger.entity()).unwrap();
background_color.0.set_alpha(1.0);
}
fn button_hover_off(trigger: Trigger<Pointer<Out>>, mut query: Query<&mut BackgroundColor>) {
let mut background_color = query.get_mut(trigger.entity()).unwrap();
background_color.0.set_alpha(0.9);
}

@ -189,11 +189,11 @@ pub(crate) fn place_card(
query.get_mut(trigger.entity()).unwrap(); query.get_mut(trigger.entity()).unwrap();
// Set it's transform based on it's placement // Set it's transform based on it's placement
let CARD_SIZE = [100.0, 160.0]; let card_size = [100.0, 160.0];
let offset = Vec2::new(CARD_SIZE[0] * 4.0, CARD_SIZE[1] * 4.0) / 2.5; let offset = Vec2::new(card_size[0] * 4.0, card_size[1] * 4.0) / 2.5;
transform.translation = Vec3::new( transform.translation = Vec3::new(
((*x as f32) * CARD_SIZE[0]) - offset.x, ((*x as f32) * card_size[0]) - offset.x,
((*y as f32) * CARD_SIZE[1]) - offset.y, ((*y as f32) * card_size[1]) - offset.y,
0.0, 0.0,
); );

@ -1,5 +1,5 @@
use crate::{deck::*, *}; use crate::{deck::*, *};
use bevy::{color::palettes::css::TEAL, prelude::*}; use bevy::prelude::*;
use view::ViewState; use view::ViewState;
pub struct SetupPlugin; pub struct SetupPlugin;
@ -8,14 +8,7 @@ impl Plugin for SetupPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems( app.add_systems(
OnEnter(GameState::Setup), OnEnter(GameState::Setup),
( (setup_background, setup_cards, setup_camera, start_play).chain(),
setup_background,
setup_cards,
setup_set_check_button,
setup_camera,
start_play,
)
.chain(),
); );
} }
} }
@ -75,29 +68,6 @@ pub(crate) fn setup_background(
)); ));
} }
pub(crate) fn setup_set_check_button(mut commands: Commands) {
commands
.spawn((
Node {
width: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..default()
},
Visibility::default(),
ViewState::Play,
BackgroundColor(Color::BLACK.into()),
))
.with_children(|parent| {
parent
.spawn((Button, BackgroundColor(TEAL.into())))
.with_children(|parent| {
parent.spawn(Text("Set!?".to_string()));
})
.observe(play::check_set);
});
}
/// Finish the setup state by progressing to the play state /// Finish the setup state by progressing to the play state
pub(crate) fn start_play( pub(crate) fn start_play(
mut game_state: ResMut<NextState<GameState>>, mut game_state: ResMut<NextState<GameState>>,

@ -1,4 +1,4 @@
use bevy::{prelude::*, state::state::FreelyMutableState}; use bevy::{prelude::*, state::state::FreelyMutableState, window::WindowResized};
/// Deck and Cards /// Deck and Cards
pub struct ViewPlugin; pub struct ViewPlugin;
@ -6,6 +6,7 @@ pub struct ViewPlugin;
impl Plugin for ViewPlugin { impl Plugin for ViewPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.init_state::<ViewState>() app.init_state::<ViewState>()
.add_systems(Update, update_window_info)
.add_systems(Update, state_monitor); .add_systems(Update, state_monitor);
} }
} }
@ -47,3 +48,21 @@ fn state_monitor(
}); });
}); });
} }
fn update_window_info(mut events: EventReader<WindowResized>, mut _windows: Query<&mut Window>) {
events
.read()
.for_each(|WindowResized { height, width, .. }| {
info!("Window resized {} {}", height, width);
let new_scale_factor = {
let height_ratio = 800.0 / height;
let width_ratio = 500.0 / width;
height_ratio.min(width_ratio)
};
// let window = windows.single_mut();
// window.resolution.set_scale_factor(new_scale_factor);
info!("Proposed scale factor: {:?}", new_scale_factor);
});
}

@ -11,3 +11,10 @@ TODO:
* Menu * Menu
* About/Credits * About/Credits
* How To Play * How To Play
Exclude for now:
* deck
* sets
Exclude in wasm:
* quit

Loading…
Cancel
Save