From c709fb5851927df2c38fb1b9347315baee9b622c Mon Sep 17 00:00:00 2001 From: Tao Tien <29749622+taotien@users.noreply.github.com> Date: Sun, 15 Feb 2026 23:40:21 -0800 Subject: [PATCH] re-organize crates --- Cargo.lock | 27 ++++++---- Cargo.toml | 2 +- devenv.nix | 2 +- jong-db/Cargo.toml | 10 ++++ .../src/db}/add_bot_reducer.rs | 0 .../src/stdb => jong-db/src/db}/bot_table.rs | 0 {jong/src/stdb => jong-db/src/db}/bot_type.rs | 0 .../src/db}/clear_all_reducer.rs | 0 .../stdb => jong-db/src/db}/db_tile_type.rs | 0 .../stdb => jong-db/src/db}/db_wall_type.rs | 0 .../src/db}/discard_tile_reducer.rs | 0 .../stdb => jong-db/src/db}/dragon_type.rs | 0 .../src/db}/draw_tile_reducer.rs | 0 .../src/db}/game_state_type.rs | 0 .../src/db}/join_or_create_lobby_reducer.rs | 0 .../stdb => jong-db/src/db}/lobby_table.rs | 0 .../src/stdb => jong-db/src/db}/lobby_type.rs | 0 .../src/db}/login_or_add_player_reducer.rs | 0 {jong/src/stdb => jong-db/src/db}/mod.rs | 0 .../src/db}/player_or_bot_type.rs | 0 .../stdb => jong-db/src/db}/player_table.rs | 0 .../stdb => jong-db/src/db}/player_type.rs | 0 .../src/stdb => jong-db/src/db}/rank_type.rs | 0 .../src/db}/set_ready_reducer.rs | 0 .../src/db}/shuffle_deal_reducer.rs | 0 .../src/db}/skip_call_reducer.rs | 0 .../src/db}/start_game_reducer.rs | 0 .../src/stdb => jong-db/src/db}/suit_type.rs | 0 .../src/stdb => jong-db/src/db}/tile_table.rs | 0 .../src/stdb => jong-db/src/db}/tile_type.rs | 0 .../src/db}/turn_state_type.rs | 0 .../src/stdb => jong-db/src/db}/wall_table.rs | 0 .../src/stdb => jong-db/src/db}/wind_type.rs | 0 jong-db/src/lib.rs | 54 +++++++++++++++++++ jong-line/Cargo.toml | 12 +++++ {spacetimedb => jong-line}/src/lib.rs | 0 .../src/reducers/game.rs | 0 .../src/reducers/game/bot.rs | 0 .../src/reducers/game/deal.rs | 0 .../src/reducers/game/hand.rs | 0 {spacetimedb => jong-line}/src/tables.rs | 0 .../src/tables/player.rs | 0 jong-types/Cargo.toml | 4 +- jong/Cargo.toml | 31 +++++++---- jong/src/game.rs | 35 ++++++------ jong/src/lib.rs | 54 +------------------ jong/src/tui.rs | 2 +- jong/src/tui/input/keyboard.rs | 6 +-- justfile | 16 +++--- spacetimedb/Cargo.toml | 14 ----- 50 files changed, 148 insertions(+), 121 deletions(-) create mode 100644 jong-db/Cargo.toml rename {jong/src/stdb => jong-db/src/db}/add_bot_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/bot_table.rs (100%) rename {jong/src/stdb => jong-db/src/db}/bot_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/clear_all_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/db_tile_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/db_wall_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/discard_tile_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/dragon_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/draw_tile_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/game_state_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/join_or_create_lobby_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/lobby_table.rs (100%) rename {jong/src/stdb => jong-db/src/db}/lobby_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/login_or_add_player_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/mod.rs (100%) rename {jong/src/stdb => jong-db/src/db}/player_or_bot_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/player_table.rs (100%) rename {jong/src/stdb => jong-db/src/db}/player_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/rank_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/set_ready_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/shuffle_deal_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/skip_call_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/start_game_reducer.rs (100%) rename {jong/src/stdb => jong-db/src/db}/suit_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/tile_table.rs (100%) rename {jong/src/stdb => jong-db/src/db}/tile_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/turn_state_type.rs (100%) rename {jong/src/stdb => jong-db/src/db}/wall_table.rs (100%) rename {jong/src/stdb => jong-db/src/db}/wind_type.rs (100%) create mode 100644 jong-db/src/lib.rs create mode 100644 jong-line/Cargo.toml rename {spacetimedb => jong-line}/src/lib.rs (100%) rename {spacetimedb => jong-line}/src/reducers/game.rs (100%) rename {spacetimedb => jong-line}/src/reducers/game/bot.rs (100%) rename {spacetimedb => jong-line}/src/reducers/game/deal.rs (100%) rename {spacetimedb => jong-line}/src/reducers/game/hand.rs (100%) rename {spacetimedb => jong-line}/src/tables.rs (100%) rename {spacetimedb => jong-line}/src/tables/player.rs (100%) delete mode 100644 spacetimedb/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index fa24bf0..92d739c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3750,6 +3750,7 @@ dependencies = [ "bevy_ratatui", "bevy_spacetimedb", "clap", + "jong-db", "jong-types", "log", "rand 0.9.2", @@ -3762,6 +3763,23 @@ dependencies = [ "tui-logger", ] +[[package]] +name = "jong-db" +version = "0.1.0" +dependencies = [ + "jong-types", + "spacetimedb-sdk", +] + +[[package]] +name = "jong-line" +version = "0.1.0" +dependencies = [ + "jong-types", + "log", + "spacetimedb", +] + [[package]] name = "jong-types" version = "0.1.0" @@ -3772,15 +3790,6 @@ dependencies = [ "strum 0.27.2", ] -[[package]] -name = "jongline" -version = "0.1.0" -dependencies = [ - "jong-types", - "log", - "spacetimedb", -] - [[package]] name = "js-sys" version = "0.3.85" diff --git a/Cargo.toml b/Cargo.toml index eb2e720..03b5cd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "3" -members = ["jong", "jong-types", "spacetimedb"] +members = ["jong", "jong-types", "jong-line", "jong-db"] [workspace.dependencies] jong = { version = "0.1.0", path = "jong" } diff --git a/devenv.nix b/devenv.nix index 36d9034..ea36f0b 100644 --- a/devenv.nix +++ b/devenv.nix @@ -7,7 +7,7 @@ # processes.lspmux.exec = "lspmux server"; processes.spacetimedb_start.exec = "spacetime start"; processes.spacetimedb_dev = { - exec = "spacetime dev --module-bindings-path jong/src/stdb jongline --delete-data=always"; + exec = "spacetime dev --module-bindings-path jong-db/src/db jong-line --delete-data=always"; # notify.enable = true; # TODO features not yet supp??? # restart = "always"; diff --git a/jong-db/Cargo.toml b/jong-db/Cargo.toml new file mode 100644 index 0000000..9e77deb --- /dev/null +++ b/jong-db/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "jong-db" +version = "0.1.0" +edition = "2024" + +[lib] + +[dependencies] +jong-types.workspace = true +spacetimedb-sdk.workspace = true diff --git a/jong/src/stdb/add_bot_reducer.rs b/jong-db/src/db/add_bot_reducer.rs similarity index 100% rename from jong/src/stdb/add_bot_reducer.rs rename to jong-db/src/db/add_bot_reducer.rs diff --git a/jong/src/stdb/bot_table.rs b/jong-db/src/db/bot_table.rs similarity index 100% rename from jong/src/stdb/bot_table.rs rename to jong-db/src/db/bot_table.rs diff --git a/jong/src/stdb/bot_type.rs b/jong-db/src/db/bot_type.rs similarity index 100% rename from jong/src/stdb/bot_type.rs rename to jong-db/src/db/bot_type.rs diff --git a/jong/src/stdb/clear_all_reducer.rs b/jong-db/src/db/clear_all_reducer.rs similarity index 100% rename from jong/src/stdb/clear_all_reducer.rs rename to jong-db/src/db/clear_all_reducer.rs diff --git a/jong/src/stdb/db_tile_type.rs b/jong-db/src/db/db_tile_type.rs similarity index 100% rename from jong/src/stdb/db_tile_type.rs rename to jong-db/src/db/db_tile_type.rs diff --git a/jong/src/stdb/db_wall_type.rs b/jong-db/src/db/db_wall_type.rs similarity index 100% rename from jong/src/stdb/db_wall_type.rs rename to jong-db/src/db/db_wall_type.rs diff --git a/jong/src/stdb/discard_tile_reducer.rs b/jong-db/src/db/discard_tile_reducer.rs similarity index 100% rename from jong/src/stdb/discard_tile_reducer.rs rename to jong-db/src/db/discard_tile_reducer.rs diff --git a/jong/src/stdb/dragon_type.rs b/jong-db/src/db/dragon_type.rs similarity index 100% rename from jong/src/stdb/dragon_type.rs rename to jong-db/src/db/dragon_type.rs diff --git a/jong/src/stdb/draw_tile_reducer.rs b/jong-db/src/db/draw_tile_reducer.rs similarity index 100% rename from jong/src/stdb/draw_tile_reducer.rs rename to jong-db/src/db/draw_tile_reducer.rs diff --git a/jong/src/stdb/game_state_type.rs b/jong-db/src/db/game_state_type.rs similarity index 100% rename from jong/src/stdb/game_state_type.rs rename to jong-db/src/db/game_state_type.rs diff --git a/jong/src/stdb/join_or_create_lobby_reducer.rs b/jong-db/src/db/join_or_create_lobby_reducer.rs similarity index 100% rename from jong/src/stdb/join_or_create_lobby_reducer.rs rename to jong-db/src/db/join_or_create_lobby_reducer.rs diff --git a/jong/src/stdb/lobby_table.rs b/jong-db/src/db/lobby_table.rs similarity index 100% rename from jong/src/stdb/lobby_table.rs rename to jong-db/src/db/lobby_table.rs diff --git a/jong/src/stdb/lobby_type.rs b/jong-db/src/db/lobby_type.rs similarity index 100% rename from jong/src/stdb/lobby_type.rs rename to jong-db/src/db/lobby_type.rs diff --git a/jong/src/stdb/login_or_add_player_reducer.rs b/jong-db/src/db/login_or_add_player_reducer.rs similarity index 100% rename from jong/src/stdb/login_or_add_player_reducer.rs rename to jong-db/src/db/login_or_add_player_reducer.rs diff --git a/jong/src/stdb/mod.rs b/jong-db/src/db/mod.rs similarity index 100% rename from jong/src/stdb/mod.rs rename to jong-db/src/db/mod.rs diff --git a/jong/src/stdb/player_or_bot_type.rs b/jong-db/src/db/player_or_bot_type.rs similarity index 100% rename from jong/src/stdb/player_or_bot_type.rs rename to jong-db/src/db/player_or_bot_type.rs diff --git a/jong/src/stdb/player_table.rs b/jong-db/src/db/player_table.rs similarity index 100% rename from jong/src/stdb/player_table.rs rename to jong-db/src/db/player_table.rs diff --git a/jong/src/stdb/player_type.rs b/jong-db/src/db/player_type.rs similarity index 100% rename from jong/src/stdb/player_type.rs rename to jong-db/src/db/player_type.rs diff --git a/jong/src/stdb/rank_type.rs b/jong-db/src/db/rank_type.rs similarity index 100% rename from jong/src/stdb/rank_type.rs rename to jong-db/src/db/rank_type.rs diff --git a/jong/src/stdb/set_ready_reducer.rs b/jong-db/src/db/set_ready_reducer.rs similarity index 100% rename from jong/src/stdb/set_ready_reducer.rs rename to jong-db/src/db/set_ready_reducer.rs diff --git a/jong/src/stdb/shuffle_deal_reducer.rs b/jong-db/src/db/shuffle_deal_reducer.rs similarity index 100% rename from jong/src/stdb/shuffle_deal_reducer.rs rename to jong-db/src/db/shuffle_deal_reducer.rs diff --git a/jong/src/stdb/skip_call_reducer.rs b/jong-db/src/db/skip_call_reducer.rs similarity index 100% rename from jong/src/stdb/skip_call_reducer.rs rename to jong-db/src/db/skip_call_reducer.rs diff --git a/jong/src/stdb/start_game_reducer.rs b/jong-db/src/db/start_game_reducer.rs similarity index 100% rename from jong/src/stdb/start_game_reducer.rs rename to jong-db/src/db/start_game_reducer.rs diff --git a/jong/src/stdb/suit_type.rs b/jong-db/src/db/suit_type.rs similarity index 100% rename from jong/src/stdb/suit_type.rs rename to jong-db/src/db/suit_type.rs diff --git a/jong/src/stdb/tile_table.rs b/jong-db/src/db/tile_table.rs similarity index 100% rename from jong/src/stdb/tile_table.rs rename to jong-db/src/db/tile_table.rs diff --git a/jong/src/stdb/tile_type.rs b/jong-db/src/db/tile_type.rs similarity index 100% rename from jong/src/stdb/tile_type.rs rename to jong-db/src/db/tile_type.rs diff --git a/jong/src/stdb/turn_state_type.rs b/jong-db/src/db/turn_state_type.rs similarity index 100% rename from jong/src/stdb/turn_state_type.rs rename to jong-db/src/db/turn_state_type.rs diff --git a/jong/src/stdb/wall_table.rs b/jong-db/src/db/wall_table.rs similarity index 100% rename from jong/src/stdb/wall_table.rs rename to jong-db/src/db/wall_table.rs diff --git a/jong/src/stdb/wind_type.rs b/jong-db/src/db/wind_type.rs similarity index 100% rename from jong/src/stdb/wind_type.rs rename to jong-db/src/db/wind_type.rs diff --git a/jong-db/src/lib.rs b/jong-db/src/lib.rs new file mode 100644 index 0000000..c6f9297 --- /dev/null +++ b/jong-db/src/lib.rs @@ -0,0 +1,54 @@ +pub mod db; +pub use db::*; + +impl From for jong_types::GameState { + fn from(value: GameState) -> Self { + Self::from_repr(value as usize).unwrap() + } +} + +impl From for jong_types::TurnState { + fn from(value: TurnState) -> Self { + Self::from_repr(value as usize).unwrap() + } +} + +impl From<&Tile> for jong_types::Tile { + fn from(value: &tile_type::Tile) -> Self { + Self { + suit: value.suit.clone().into(), + } + } +} + +impl From for jong_types::Suit { + fn from(value: Suit) -> Self { + match value { + Suit::Man(rank) => Self::Man(rank.into()), + Suit::Pin(rank) => Self::Pin(rank.into()), + Suit::Sou(rank) => Self::Sou(rank.into()), + Suit::Wind(wind) => Self::Wind(wind.into()), + Suit::Dragon(dragon) => Self::Dragon(dragon.into()), + } + } +} + +impl From for jong_types::Rank { + fn from(value: Rank) -> Self { + Self { + number: value.number, + } + } +} + +impl From for jong_types::Wind { + fn from(value: Wind) -> Self { + Self::from_repr(value as usize).unwrap() + } +} + +impl From for jong_types::Dragon { + fn from(value: Dragon) -> Self { + Self::from_repr(value as usize).unwrap() + } +} diff --git a/jong-line/Cargo.toml b/jong-line/Cargo.toml new file mode 100644 index 0000000..2eccaf0 --- /dev/null +++ b/jong-line/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "jong-line" +version = "0.1.0" +edition = "2024" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +jong-types.workspace = true +spacetimedb.workspace = true +log.workspace = true diff --git a/spacetimedb/src/lib.rs b/jong-line/src/lib.rs similarity index 100% rename from spacetimedb/src/lib.rs rename to jong-line/src/lib.rs diff --git a/spacetimedb/src/reducers/game.rs b/jong-line/src/reducers/game.rs similarity index 100% rename from spacetimedb/src/reducers/game.rs rename to jong-line/src/reducers/game.rs diff --git a/spacetimedb/src/reducers/game/bot.rs b/jong-line/src/reducers/game/bot.rs similarity index 100% rename from spacetimedb/src/reducers/game/bot.rs rename to jong-line/src/reducers/game/bot.rs diff --git a/spacetimedb/src/reducers/game/deal.rs b/jong-line/src/reducers/game/deal.rs similarity index 100% rename from spacetimedb/src/reducers/game/deal.rs rename to jong-line/src/reducers/game/deal.rs diff --git a/spacetimedb/src/reducers/game/hand.rs b/jong-line/src/reducers/game/hand.rs similarity index 100% rename from spacetimedb/src/reducers/game/hand.rs rename to jong-line/src/reducers/game/hand.rs diff --git a/spacetimedb/src/tables.rs b/jong-line/src/tables.rs similarity index 100% rename from spacetimedb/src/tables.rs rename to jong-line/src/tables.rs diff --git a/spacetimedb/src/tables/player.rs b/jong-line/src/tables/player.rs similarity index 100% rename from spacetimedb/src/tables/player.rs rename to jong-line/src/tables/player.rs diff --git a/jong-types/Cargo.toml b/jong-types/Cargo.toml index e4d5d42..9b5ef99 100644 --- a/jong-types/Cargo.toml +++ b/jong-types/Cargo.toml @@ -8,6 +8,8 @@ edition = "2024" [dependencies] bevy.workspace = true bevy.features = ["bevy_state"] -derive_aliases = "0.4.7" + spacetimedb.workspace = true + strum.workspace = true +derive_aliases = "0.4.7" diff --git a/jong/Cargo.toml b/jong/Cargo.toml index a579d2f..e44613d 100644 --- a/jong/Cargo.toml +++ b/jong/Cargo.toml @@ -10,21 +10,30 @@ readme = false [lib] [dependencies] +# jong jong-types.workspace = true +jong-db.path = "../jong-db" -bevy = { workspace = true, features = ["default", "dynamic_linking"] } +# bevy +bevy.workspace = true +bevy.features = ["default", "dynamic_linking"] bevy_ratatui.workspace = true -bevy_spacetimedb.workspace = true -clap = { workspace = true, features = ["derive"] } -log = { workspace = true, features = [ - "release_max_level_error", - "max_level_trace", -] } -rand.workspace = true -ratatui.workspace = true + +# spacetimedb spacetimedb-sdk.workspace = true spacetimedb.workspace = true +bevy_spacetimedb.workspace = true + +# tui +ratatui.workspace = true +tui-logger.workspace = true +tui-logger.features = ["tracing-support", "crossterm"] + +clap.features = ["derive"] +clap.workspace = true +log.features = ["release_max_level_error", "max_level_trace"] +log.workspace = true +rand.workspace = true strum.workspace = true -tracing.workspace = true tracing-subscriber.workspace = true -tui-logger = { workspace = true, features = ["tracing-support", "crossterm"] } +tracing.workspace = true diff --git a/jong/src/game.rs b/jong/src/game.rs index 571e066..344d5f3 100644 --- a/jong/src/game.rs +++ b/jong/src/game.rs @@ -4,15 +4,12 @@ use bevy_spacetimedb::{ }; use spacetimedb_sdk::{DbContext, Table}; -use crate::stdb::{self, DbConnection, LobbyTableAccess, PlayerTableAccess, RemoteTables}; -use crate::stdb::{ - add_bot, draw_tile, set_ready, shuffle_deal, - skip_call, start_game, -}; use crate::{ SpacetimeDB, creds_store, game::hand::{Drawn, Hand, Pond}, }; +use jong_db::{self, DbConnection, LobbyTableAccess, PlayerTableAccess, RemoteTables}; +use jong_db::{add_bot, draw_tile, set_ready, shuffle_deal, skip_call, start_game}; use jong_types::*; pub mod hand; @@ -108,7 +105,7 @@ pub struct TileId(pub u32); fn on_player_insert_update( _stdb: SpacetimeDB, - mut messages: ReadInsertUpdateMessage, + mut messages: ReadInsertUpdateMessage, mut commands: Commands, @@ -164,7 +161,7 @@ fn on_player_insert_update( fn on_lobby_insert_update( stdb: SpacetimeDB, - mut messages: ReadInsertUpdateMessage, + mut messages: ReadInsertUpdateMessage, _commands: Commands, mut next_gamestate: ResMut>, @@ -182,10 +179,10 @@ fn on_lobby_insert_update( next_gamestate.set(msg.new.game_state.into()); match msg.new.game_state { - stdb::GameState::None => { + jong_db::GameState::None => { trace!("game entered none"); } - stdb::GameState::Lobby => { + jong_db::GameState::Lobby => { trace!("game entered lobby"); if !player.ready { for _ in 0..3 { @@ -195,31 +192,31 @@ fn on_lobby_insert_update( stdb.reducers().start_game().unwrap(); } } - stdb::GameState::Setup => { + jong_db::GameState::Setup => { trace!("game entered setup"); stdb.reducers().shuffle_deal(player.lobby_id).unwrap(); } - stdb::GameState::Deal => { + jong_db::GameState::Deal => { trace!("game entered deal"); } - stdb::GameState::Play => { + jong_db::GameState::Play => { trace!("game entered play"); match msg.new.turn_state { - stdb::TurnState::None => {} - stdb::TurnState::Tsumo => { + jong_db::TurnState::None => {} + jong_db::TurnState::Tsumo => { stdb.reducers().draw_tile().unwrap(); } - stdb::TurnState::Menzen => todo!(), - stdb::TurnState::RiichiKan => todo!(), - stdb::TurnState::RonChiiPonKan => { + jong_db::TurnState::Menzen => todo!(), + jong_db::TurnState::RiichiKan => todo!(), + jong_db::TurnState::RonChiiPonKan => { stdb.reducers().skip_call().unwrap(); } - stdb::TurnState::End => todo!(), + jong_db::TurnState::End => todo!(), // _ => todo!(), } next_turnstate.set(msg.new.turn_state.into()); } - stdb::GameState::Exit => { + jong_db::GameState::Exit => { trace!("game enetered exit"); } } diff --git a/jong/src/lib.rs b/jong/src/lib.rs index e6a3fe9..1d548af 100644 --- a/jong/src/lib.rs +++ b/jong/src/lib.rs @@ -5,7 +5,6 @@ use bevy_spacetimedb::StdbConnection; use spacetimedb_sdk::credentials; pub mod game; -pub mod stdb; pub mod tile; pub mod yakus; @@ -13,60 +12,9 @@ trait EnumNextCycle { fn next(&self) -> Self; } -pub type SpacetimeDB<'a> = Res<'a, StdbConnection>; +pub type SpacetimeDB<'a> = Res<'a, StdbConnection>; fn creds_store() -> credentials::File { credentials::File::new("jongline") } -impl From for jong_types::GameState { - fn from(value: stdb::GameState) -> Self { - Self::from_repr(value as usize).unwrap() - } -} - -impl From for jong_types::TurnState { - fn from(value: stdb::TurnState) -> Self { - Self::from_repr(value as usize).unwrap() - } -} - -impl From<&stdb::Tile> for jong_types::Tile { - fn from(value: &stdb::tile_type::Tile) -> Self { - Self { - suit: value.suit.clone().into(), - } - } -} - -impl From for jong_types::Suit { - fn from(value: stdb::Suit) -> Self { - match value { - stdb::Suit::Man(rank) => Self::Man(rank.into()), - stdb::Suit::Pin(rank) => Self::Pin(rank.into()), - stdb::Suit::Sou(rank) => Self::Sou(rank.into()), - stdb::Suit::Wind(wind) => Self::Wind(wind.into()), - stdb::Suit::Dragon(dragon) => Self::Dragon(dragon.into()), - } - } -} - -impl From for jong_types::Rank { - fn from(value: stdb::Rank) -> Self { - Self { - number: value.number, - } - } -} - -impl From for jong_types::Wind { - fn from(value: stdb::Wind) -> Self { - Self::from_repr(value as usize).unwrap() - } -} - -impl From for jong_types::Dragon { - fn from(value: stdb::Dragon) -> Self { - Self::from_repr(value as usize).unwrap() - } -} diff --git a/jong/src/tui.rs b/jong/src/tui.rs index 4c6c664..f58fb51 100644 --- a/jong/src/tui.rs +++ b/jong/src/tui.rs @@ -9,7 +9,6 @@ use jong::game::player::MainPlayer; use tui_logger::TuiWidgetState; use crate::tui::{input::ConfirmSelect, states::ConsoleWidget}; -use jong::stdb::{self, discard_tile as _}; use jong::{ SpacetimeDB, game::{ @@ -17,6 +16,7 @@ use jong::{ player::{CurrentPlayer, Player}, }, }; +use jong_db::{self, discard_tile as _}; use jong_types::{GameState, TurnState}; mod input; diff --git a/jong/src/tui/input/keyboard.rs b/jong/src/tui/input/keyboard.rs index 722d6fb..3e75e64 100644 --- a/jong/src/tui/input/keyboard.rs +++ b/jong/src/tui/input/keyboard.rs @@ -1,9 +1,9 @@ use bevy::prelude::*; use bevy_ratatui::crossterm::event::KeyCode; use bevy_ratatui::event::KeyMessage; -use jong::stdb::PlayerTableAccess; -use jong::stdb::join_or_create_lobby; -use jong::stdb::start_game; +use jong_db::PlayerTableAccess; +use jong_db::join_or_create_lobby; +use jong_db::start_game; use tui_logger::TuiWidgetEvent; use jong::SpacetimeDB; diff --git a/justfile b/justfile index da1758e..1e14034 100644 --- a/justfile +++ b/justfile @@ -4,16 +4,11 @@ alias rt := run-tui alias s := spacetime alias g := spacetime_generate-bindings -rrt: - just spacetime_restart_dev - sleep 3sec - just run-tui - default: just --list run-tui: - spacetime call jongline "clear_all" + spacetime call jong-line "clear_all" cargo run -- run-tui update: @@ -24,11 +19,16 @@ spacetime: devenv up spacetime_dev: - spacetime dev --module-bindings-path jong/src/stdb jongline --delete-data=always + spacetime dev --module-bindings-path jong-db/src/db jong-line --delete-data=always spacetime_generate-bindings: - spacetime generate --lang rust --out-dir jong/src/stdb --project-path spacetimedb + spacetime generate --lang rust --out-dir jong-db/src/db --project-path jong-line spacetime_restart_dev: mprocs -s localhost:4050 --ctl $"({c: restart-proc, name: spacetimedb_dev} | to yaml)" +rrt: + just spacetime_restart_dev + sleep 3sec + just run-tui + diff --git a/spacetimedb/Cargo.toml b/spacetimedb/Cargo.toml deleted file mode 100644 index 60070ef..0000000 --- a/spacetimedb/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "jongline" -version = "0.1.0" -edition = "2024" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -crate-type = ["cdylib"] - -[dependencies] -spacetimedb = { workspace = true } -log = { workspace = true } -jong-types = { workspace = true }