A card game engine for TCGs, primarily Magic: The Gathering but with support for others
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Creating a sub-crate for use in a workspace

+93 -46
+28 -3
Cargo.lock game/Cargo.lock
··· 1306 1306 version = "0.1.0" 1307 1307 dependencies = [ 1308 1308 "sea-orm", 1309 + "tokio", 1309 1310 "uuid", 1310 1311 ] 1311 1312 ··· 2230 2231 checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 2231 2232 2232 2233 [[package]] 2234 + name = "signal-hook-registry" 2235 + version = "1.4.8" 2236 + source = "registry+https://github.com/rust-lang/crates.io-index" 2237 + checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" 2238 + dependencies = [ 2239 + "errno", 2240 + "libc", 2241 + ] 2242 + 2243 + [[package]] 2233 2244 name = "signature" 2234 2245 version = "2.2.0" 2235 2246 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2574 2585 checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" 2575 2586 dependencies = [ 2576 2587 "fastrand", 2577 - "getrandom 0.3.4", 2588 + "getrandom 0.4.2", 2578 2589 "once_cell", 2579 2590 "rustix", 2580 2591 "windows-sys 0.61.2", ··· 2667 2678 2668 2679 [[package]] 2669 2680 name = "tokio" 2670 - version = "1.51.0" 2681 + version = "1.52.1" 2671 2682 source = "registry+https://github.com/rust-lang/crates.io-index" 2672 - checksum = "2bd1c4c0fc4a7ab90fc15ef6daaa3ec3b893f004f915f2392557ed23237820cd" 2683 + checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" 2673 2684 dependencies = [ 2674 2685 "bytes", 2675 2686 "libc", 2676 2687 "mio", 2688 + "parking_lot", 2677 2689 "pin-project-lite", 2690 + "signal-hook-registry", 2678 2691 "socket2", 2692 + "tokio-macros", 2679 2693 "windows-sys 0.61.2", 2694 + ] 2695 + 2696 + [[package]] 2697 + name = "tokio-macros" 2698 + version = "2.7.0" 2699 + source = "registry+https://github.com/rust-lang/crates.io-index" 2700 + checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" 2701 + dependencies = [ 2702 + "proc-macro2", 2703 + "quote", 2704 + "syn 2.0.117", 2680 2705 ] 2681 2706 2682 2707 [[package]]
+1 -1
Cargo.toml game/Cargo.toml
··· 14 14 features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] 15 15 16 16 [dependencies.tokio] 17 - version = "1" 17 + version = "1.52.1" 18 18 features = [ "full" ]
+59
game/src/game/mod.rs
··· 1 + use std::{fmt, collections::HashMap}; 2 + use crate::game::{state::GameState, card::{CardDefId, Card}}; 3 + use sea_orm::{Database, DatabaseConnection, DbErr}; 4 + use uuid::Uuid; 5 + 6 + pub mod card; 7 + pub mod player; 8 + pub mod zone; 9 + pub mod state; 10 + 11 + pub type Result<T> = std::result::Result<T, ManaGroveError>; 12 + 13 + #[derive(Debug, Clone)] 14 + pub struct ManaGroveError(pub String); 15 + 16 + impl fmt::Display for ManaGroveError { 17 + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 18 + write!(f, "Error in running game: {}", self.0) 19 + } 20 + } 21 + 22 + impl From<DbErr> for ManaGroveError { 23 + fn from(value: DbErr) -> Self { 24 + Self(value.to_string()) 25 + } 26 + } 27 + 28 + pub struct Game { 29 + state: GameState, 30 + cards: HashMap<CardDefId, Card>, 31 + namespace_uuid: Uuid 32 + } 33 + 34 + impl Game { 35 + pub fn new(player_names: Vec<String>) -> Result<Self> { 36 + let namespace_uuid = Uuid::new_v4(); 37 + let state = GameState::new(player_names, &namespace_uuid); 38 + 39 + let cards = tokio::runtime::Builder::new_multi_thread() 40 + .enable_all() 41 + .build() 42 + .unwrap() 43 + .block_on(Self::setup_cards())?; 44 + 45 + Ok(Self { 46 + state, 47 + cards, 48 + namespace_uuid 49 + }) 50 + } 51 + 52 + async fn setup_cards() -> Result<HashMap<CardDefId, Card>> { 53 + let db: DatabaseConnection = Database::connect("sqlite://cards.db?mode=rwc").await?; 54 + db.ping().await?; 55 + 56 + db.close().await?; 57 + Ok(HashMap::new()) 58 + } 59 + }
src/game/card.rs game/src/game/card.rs
-38
src/game/mod.rs
··· 1 - use std::{fmt, collections::HashMap}; 2 - use crate::game::{state::GameState, card::{CardDefId, Card}}; 3 - use uuid::Uuid; 4 - 5 - pub mod card; 6 - pub mod player; 7 - pub mod zone; 8 - pub mod state; 9 - 10 - pub type Result<T> = std::result::Result<T, ManaGroveError>; 11 - 12 - #[derive(Debug, Clone)] 13 - pub struct ManaGroveError; 14 - 15 - impl fmt::Display for ManaGroveError { 16 - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 17 - write!(f, "Error in running game.") 18 - } 19 - } 20 - 21 - pub struct Game { 22 - state: GameState, 23 - cards: HashMap<CardDefId, Card>, 24 - namespace_uuid: Uuid 25 - } 26 - 27 - impl Game { 28 - pub fn new(player_names: Vec<String>) -> Self { 29 - let namespace_uuid = Uuid::new_v4(); 30 - let state = GameState::new(player_names, &namespace_uuid); 31 - 32 - Self { 33 - state, 34 - cards: HashMap::new(), 35 - namespace_uuid 36 - } 37 - } 38 - }
+1 -1
src/game/player.rs game/src/game/player.rs
··· 31 31 let graveyard_zone_id = ZoneId::new(format!("{}-{}", name, "graveyard"), namespace_uuid); 32 32 let battlefield_zone_id = ZoneId::new(format!("{}-{}", name, "battlefield"), namespace_uuid); 33 33 let exile_zone_id = ZoneId::new(format!("{}-{}", name, "exile"), namespace_uuid); 34 - zones.insert(hand_zone_id.clone(), Zone::new(String::from("Hand"), id.clone(), hand_zone_id.clone(), ZoneVisibility::Player)).unwrap(); 34 + zones.insert(hand_zone_id.clone(), Zone::new(String::from("Hand"), id.clone(), hand_zone_id.clone(), ZoneVisibility::Player)); 35 35 zones.insert(library_zone_id.clone(), Zone::new(String::from("Library"), id.clone(), library_zone_id.clone(), ZoneVisibility::Hidden)); 36 36 zones.insert(graveyard_zone_id.clone(), Zone::new(String::from("Graveyard"), id.clone(), graveyard_zone_id.clone(), ZoneVisibility::All)); 37 37 zones.insert(battlefield_zone_id.clone(), Zone::new(String::from("Battlefield"), id.clone(), battlefield_zone_id.clone(), ZoneVisibility::All));
src/game/state.rs game/src/game/state.rs
src/game/zone.rs game/src/game/zone.rs
+4 -3
src/main.rs game/src/main.rs
··· 1 - use crate::game::Game; 1 + use crate::game::{Game, Result}; 2 2 3 3 mod game; 4 4 5 - fn main() { 6 - let _ = Game::new(vec![String::from("Player 1"), String::from("Player 2"), String::from("Player 3"), String::from("Player 4")]); 5 + fn main() -> Result<()> { 6 + let _ = Game::new(vec![String::from("Player 1"), String::from("Player 2"), String::from("Player 3"), String::from("Player 4")])?; 7 + Ok(()) 7 8 }