Skip to content

Commit

Permalink
Analysis tool (#242)
Browse files Browse the repository at this point in the history
* analysis tool v1

* Styles analysis board, fixes ssr issues (#266)

---------

Co-authored-by: IongIer <[email protected]>
  • Loading branch information
PenguinWithATie and IongIer authored Jul 2, 2024
1 parent c6bedb2 commit a05a4c2
Show file tree
Hide file tree
Showing 21 changed files with 850 additions and 191 deletions.
51 changes: 47 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ diesel_migrations = { version = "2.1", features = ["postgres"]}
uuid = { version = "1.7", features = ["v4", "js", "serde"] }
nanoid = "0.4"
dotenvy = "0.15"
lazy_static = "1.4"
lazy_static = "1.5"
rand = "0.8"
rand_core = "0.6"
cookie = "0.18"
skillratings = "0.26"
chrono = { version = "0.4", features = ["serde"] }
leptix_primitives = {git ="https://github.com/leptix/leptix.git" }
leptix_primitives = { version = "0.2.0" }
tree-ds = {version = "0.1.4", features = ["serde", "auto_id"] }
bincode = { version = "1.3.3"}
base64 = { version = "0.22.1"}
# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
Expand Down
3 changes: 3 additions & 0 deletions apis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ uuid = { workspace = true }
wasm-bindgen = { workspace = true}
web-sys = { workspace = true }
leptix_primitives = {workspace = true}
tree-ds = {workspace = true}
bincode = {workspace = true}
base64 = {workspace = true}
[features]
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
Expand Down
1 change: 0 additions & 1 deletion apis/src/components/atoms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ pub mod svgs;
pub mod target;
pub mod title;
pub mod toggle_controls;
pub mod undo_button;
9 changes: 6 additions & 3 deletions apis/src/components/atoms/piece.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::common::{MoveConfirm, TileDesign, TileDots, TileRotation};
use crate::common::{PieceType, SvgPos};
use crate::pages::{analysis::InAnalysis, play::CurrentConfirm};
use crate::components::organisms::analysis::AnalysisSignal;
use crate::pages::play::CurrentConfirm;
use crate::providers::game_state::GameStateSignal;
use crate::providers::Config;
use hive_lib::{Bug, Piece, Position};
Expand Down Expand Up @@ -64,10 +65,12 @@ pub fn Piece(

let mut game_state = expect_context::<GameStateSignal>();
let current_confirm = expect_context::<CurrentConfirm>().0;
let in_analysis = use_context::<InAnalysis>().unwrap_or(InAnalysis(RwSignal::new(false)));
let analysis = use_context::<AnalysisSignal>()
.unwrap_or(AnalysisSignal(RwSignal::new(None)))
.0;
let onclick = move |evt: MouseEvent| {
evt.stop_propagation();
let in_analysis = in_analysis.0.get_untracked();
let in_analysis = analysis.get_untracked().is_some();
if in_analysis || game_state.is_move_allowed() {
match piece_type {
PieceType::Board => {
Expand Down
21 changes: 17 additions & 4 deletions apis/src/components/atoms/target.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::common::MoveConfirm;
use crate::common::SvgPos;
use crate::pages::{analysis::InAnalysis, play::CurrentConfirm};
use crate::components::organisms::analysis::AnalysisSignal;
use crate::pages::play::CurrentConfirm;
use crate::providers::game_state::GameStateSignal;
use hive_lib::Position;
use leptos::*;
Expand All @@ -14,18 +15,30 @@ pub fn Target(
let center = move || SvgPos::center_for_level(position, level());
let transform = move || format!("translate({},{})", center().0, center().1);
let mut game_state = expect_context::<GameStateSignal>();
let in_analysis = use_context::<InAnalysis>().unwrap_or(InAnalysis(RwSignal::new(false)));
let analysis = use_context::<AnalysisSignal>()
.unwrap_or(AnalysisSignal(RwSignal::new(None)))
.0;
let current_confirm = expect_context::<CurrentConfirm>().0;

// Select the target position and make a move if it's the correct mode
let onclick = move |_| {
let in_analysis = in_analysis.0.get_untracked();
let in_analysis = analysis.get().is_some();
if in_analysis || game_state.is_move_allowed() {
batch(move || {
game_state.set_target(position);
if current_confirm() == MoveConfirm::Single || in_analysis {
game_state.move_active();
}
analysis.update(|analysis| {
if let Some(analysis) = analysis {
let moves = game_state.signal.get_untracked().state.history.moves;
let last_move = moves.last().unwrap().clone();
if last_move.0 == "pass" {
//if move is pass, add prev move
analysis.add_node(moves[moves.len() - 2].clone());
}
analysis.add_node(last_move);
}
});
});
}
};
Expand Down
20 changes: 0 additions & 20 deletions apis/src/components/atoms/undo_button.rs

This file was deleted.

Loading

0 comments on commit a05a4c2

Please sign in to comment.