added wasm port

This commit is contained in:
2025-07-08 22:32:58 +08:00
parent fa675c4b7f
commit 325ee25b2e
31 changed files with 1572 additions and 181 deletions
-96
View File
@@ -1,96 +0,0 @@
use std::clone::Clone;
use std::cmp::Eq;
use std::cmp::PartialEq;
use std::fmt::Display;
use std::marker::Copy;
use std::ops::Add;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Neg;
use std::ops::Sub;
#[derive(Debug)]
pub struct Point {
x: f64,
y: f64,
}
impl Point {
pub fn x(&self) -> f64 {
self.x
}
pub fn y(&self) -> f64 {
self.y
}
pub fn new(x: f64, y: f64) -> Point {
Point { x, y }
}
}
impl Add<&Point> for &Point {
fn add(self, rhs: &Point) -> Self::Output {
Point {
x: self.x() + rhs.x(),
y: self.y() + rhs.y(),
}
}
type Output = Point;
}
impl Sub<&Point> for &Point {
fn sub(self, rhs: &Point) -> Self::Output {
Point {
x: self.x() - rhs.x(),
y: self.y() - rhs.y(),
}
}
type Output = Point;
}
impl Mul<f64> for &Point {
fn mul(self, rhs: f64) -> Self::Output {
Point::new(self.x * rhs, self.y * rhs)
}
type Output = Point;
}
impl Div<f64> for &Point {
fn div(self, rhs: f64) -> Self::Output {
Point::new(self.x / rhs, self.y / rhs)
}
type Output = Point;
}
impl Neg for &Point {
fn neg(self) -> Self::Output {
Point::new(-self.x(), -self.y())
}
type Output = Point;
}
impl PartialEq for Point {
fn eq(&self, other: &Self) -> bool {
self.x.eq(&other.x) && self.y.eq(&other.y)
}
}
impl Eq for Point {}
impl Clone for Point {
fn clone(&self) -> Self {
*self
}
}
impl Copy for Point {}
impl Display for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Point({}, {})", self.x, self.y)
}
}
impl Point {}
+1 -1
View File
@@ -1,7 +1,7 @@
use gtk4::{Align, Application, Box, CheckButton, Label, Orientation, Window, prelude::*};
use crate::types::SharedMutable;
use rdraught::Player;
use rdraught_ui_common::SharedMutable;
pub(crate) fn create(application: &Application, current_player: SharedMutable<Player>) -> Window {
let label = Label::builder().label("Main player:").build();
-3
View File
@@ -1,8 +1,5 @@
mod geo2d;
mod final_dialog;
mod greeting_dialog;
mod rdraught_application;
mod types;
pub use rdraught_application::run;
+4 -5
View File
@@ -1,4 +1,3 @@
use super::geo2d::Point;
use core::f64::consts::PI;
use gdk4::cairo::{Context as CairoContext, Matrix, Rectangle};
use glib::ExitCode;
@@ -14,9 +13,9 @@ const SQUARE_SIZE: f64 = 1.0;
use super::final_dialog;
use super::greeting_dialog;
use super::types;
use types::{SharedMutable, SharedMutableRef, new_shared_mut, new_shared_mut_ref};
use rdraught_ui_common::{
Point, SharedMutable, SharedMutableRef, new_shared_mut, new_shared_mut_ref,
};
const CROWN_RED: &[u8] = include_bytes!("crown_red.svg");
const CROWN_WHITE: &[u8] = include_bytes!("crown_white.svg");
@@ -494,7 +493,7 @@ fn create_game_window(
};
let p = transform_point(&Point::new(x, y), &inverse);
if board_clone.contains(&p) {
let p = &p - &board_clone.tl();
let p = p - board_clone.tl();
// println!("Point: {:?}", p);
let position = match current_player {
Player::White => Position::new(
-12
View File
@@ -1,12 +0,0 @@
use std::cell::{Cell, RefCell};
use std::rc::Rc;
pub(crate) type SharedMutable<T> = Rc<Cell<T>>;
pub(crate) type SharedMutableRef<T> = Rc<RefCell<T>>;
pub(crate) fn new_shared_mut_ref<T>(obj: T) -> SharedMutableRef<T> {
Rc::new(RefCell::new(obj))
}
pub(crate) fn new_shared_mut<T>(obj: T) -> SharedMutable<T> {
Rc::new(Cell::new(obj))
}