extract types
This commit is contained in:
parent
d7d567b0e6
commit
c86f8d93f1
30 changed files with 986 additions and 474 deletions
13
jong-types/Cargo.toml
Normal file
13
jong-types/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "jong-types"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
|
||||
[dependencies]
|
||||
bevy.version = "0.17.3"
|
||||
bevy.default-features = false
|
||||
spacetimedb.workspace = true
|
||||
strum.workspace = true
|
||||
strum.features = ["derive"]
|
||||
77
jong-types/src/lib.rs
Normal file
77
jong-types/src/lib.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
use bevy::prelude::*;
|
||||
use spacetimedb::SpacetimeType;
|
||||
use strum::FromRepr;
|
||||
|
||||
#[derive(Component, Debug, Clone, Copy, SpacetimeType)]
|
||||
pub struct Tile {
|
||||
pub suit: Suit,
|
||||
}
|
||||
|
||||
#[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||
pub enum Suit {
|
||||
Man(Rank),
|
||||
Pin(Rank),
|
||||
Sou(Rank),
|
||||
Wind(Wind),
|
||||
Dragon(Dragon),
|
||||
}
|
||||
|
||||
impl Suit {
|
||||
pub fn rank(&self) -> Option<Rank> {
|
||||
match self {
|
||||
Suit::Man(rank) => Some(*rank),
|
||||
Suit::Pin(rank) => Some(*rank),
|
||||
Suit::Sou(rank) => Some(*rank),
|
||||
// Suit::Wind(wind) | Suit::Dragon(dragon) => None,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||
pub struct Rank {
|
||||
pub number: u8,
|
||||
}
|
||||
|
||||
#[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||
pub enum Wind {
|
||||
Ton,
|
||||
Nan,
|
||||
Shaa,
|
||||
Pei,
|
||||
}
|
||||
|
||||
#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||
pub enum Dragon {
|
||||
Haku,
|
||||
Hatsu,
|
||||
Chun,
|
||||
}
|
||||
|
||||
pub fn tiles() -> Vec<Tile> {
|
||||
let mut tiles = vec![];
|
||||
for _ in 0..4 {
|
||||
for i in 1..=9 {
|
||||
tiles.push(Tile {
|
||||
suit: Suit::Pin(Rank { number: i }),
|
||||
});
|
||||
tiles.push(Tile {
|
||||
suit: Suit::Sou(Rank { number: i }),
|
||||
});
|
||||
tiles.push(Tile {
|
||||
suit: Suit::Man(Rank { number: i }),
|
||||
});
|
||||
}
|
||||
for i in 0..4 {
|
||||
tiles.push(Tile {
|
||||
suit: Suit::Wind(Wind::from_repr(i).unwrap()),
|
||||
});
|
||||
}
|
||||
for i in 0..3 {
|
||||
tiles.push(Tile {
|
||||
suit: Suit::Dragon(Dragon::from_repr(i).unwrap()),
|
||||
});
|
||||
}
|
||||
}
|
||||
tiles
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue