Compare commits

..

2 commits

Author SHA1 Message Date
Tao Tien
034e543d40 update 2026-02-16 00:04:16 -08:00
Tao Tien
c709fb5851 re-organize crates 2026-02-16 00:04:16 -08:00
51 changed files with 545 additions and 335 deletions

626
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
[workspace] [workspace]
resolver = "3" resolver = "3"
members = ["jong", "jong-types", "spacetimedb"] members = ["jong", "jong-types", "jong-line", "jong-db"]
[workspace.dependencies] [workspace.dependencies]
jong = { version = "0.1.0", path = "jong" } jong = { version = "0.1.0", path = "jong" }

View file

@ -3,10 +3,10 @@
"devenv": { "devenv": {
"locked": { "locked": {
"dir": "src/modules", "dir": "src/modules",
"lastModified": 1770666213, "lastModified": 1771157881,
"owner": "cachix", "owner": "cachix",
"repo": "devenv", "repo": "devenv",
"rev": "d4ffee46c9088df6e000470b998a2d2c16517f62", "rev": "b0b3dfa70ec90fa49f672e579f186faf4f61bd4b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -40,10 +40,10 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1769939035, "lastModified": 1770726378,
"owner": "cachix", "owner": "cachix",
"repo": "git-hooks.nix", "repo": "git-hooks.nix",
"rev": "a8ca480175326551d6c4121498316261cbb5b260", "rev": "5eaaedde414f6eb1aea8b8525c466dc37bba95ae",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -125,10 +125,10 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1770606655, "lastModified": 1771211437,
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "11a396520bf911e4ed01e78e11633d3fc63b350e", "rev": "c62195b3d6e1bb11e0c2fb2a494117d3b55d410f",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -7,7 +7,7 @@
# processes.lspmux.exec = "lspmux server"; # processes.lspmux.exec = "lspmux server";
processes.spacetimedb_start.exec = "spacetime start"; processes.spacetimedb_start.exec = "spacetime start";
processes.spacetimedb_dev = { 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; # notify.enable = true;
# TODO features not yet supp??? # TODO features not yet supp???
# restart = "always"; # restart = "always";

10
jong-db/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "jong-db"
version = "0.1.0"
edition = "2024"
[lib]
[dependencies]
jong-types.workspace = true
spacetimedb-sdk.workspace = true

54
jong-db/src/lib.rs Normal file
View file

@ -0,0 +1,54 @@
pub mod db;
pub use db::*;
impl From<GameState> for jong_types::GameState {
fn from(value: GameState) -> Self {
Self::from_repr(value as usize).unwrap()
}
}
impl From<TurnState> 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<Suit> 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<Rank> for jong_types::Rank {
fn from(value: Rank) -> Self {
Self {
number: value.number,
}
}
}
impl From<Wind> for jong_types::Wind {
fn from(value: Wind) -> Self {
Self::from_repr(value as usize).unwrap()
}
}
impl From<Dragon> for jong_types::Dragon {
fn from(value: Dragon) -> Self {
Self::from_repr(value as usize).unwrap()
}
}

12
jong-line/Cargo.toml Normal file
View file

@ -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

View file

@ -8,6 +8,8 @@ edition = "2024"
[dependencies] [dependencies]
bevy.workspace = true bevy.workspace = true
bevy.features = ["bevy_state"] bevy.features = ["bevy_state"]
derive_aliases = "0.4.7"
spacetimedb.workspace = true spacetimedb.workspace = true
strum.workspace = true strum.workspace = true
derive_aliases = "0.4.7"

View file

@ -10,21 +10,30 @@ readme = false
[lib] [lib]
[dependencies] [dependencies]
# jong
jong-types.workspace = true 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_ratatui.workspace = true
bevy_spacetimedb.workspace = true
clap = { workspace = true, features = ["derive"] } # spacetimedb
log = { workspace = true, features = [
"release_max_level_error",
"max_level_trace",
] }
rand.workspace = true
ratatui.workspace = true
spacetimedb-sdk.workspace = true spacetimedb-sdk.workspace = true
spacetimedb.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 strum.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true tracing-subscriber.workspace = true
tui-logger = { workspace = true, features = ["tracing-support", "crossterm"] } tracing.workspace = true

View file

@ -4,15 +4,12 @@ use bevy_spacetimedb::{
}; };
use spacetimedb_sdk::{DbContext, Table}; 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::{ use crate::{
SpacetimeDB, creds_store, SpacetimeDB, creds_store,
game::hand::{Drawn, Hand, Pond}, 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::*; use jong_types::*;
pub mod hand; pub mod hand;
@ -108,7 +105,7 @@ pub struct TileId(pub u32);
fn on_player_insert_update( fn on_player_insert_update(
_stdb: SpacetimeDB, _stdb: SpacetimeDB,
mut messages: ReadInsertUpdateMessage<stdb::Player>, mut messages: ReadInsertUpdateMessage<jong_db::Player>,
mut commands: Commands, mut commands: Commands,
@ -164,7 +161,7 @@ fn on_player_insert_update(
fn on_lobby_insert_update( fn on_lobby_insert_update(
stdb: SpacetimeDB, stdb: SpacetimeDB,
mut messages: ReadInsertUpdateMessage<stdb::Lobby>, mut messages: ReadInsertUpdateMessage<jong_db::Lobby>,
_commands: Commands, _commands: Commands,
mut next_gamestate: ResMut<NextState<GameState>>, mut next_gamestate: ResMut<NextState<GameState>>,
@ -182,10 +179,10 @@ fn on_lobby_insert_update(
next_gamestate.set(msg.new.game_state.into()); next_gamestate.set(msg.new.game_state.into());
match msg.new.game_state { match msg.new.game_state {
stdb::GameState::None => { jong_db::GameState::None => {
trace!("game entered none"); trace!("game entered none");
} }
stdb::GameState::Lobby => { jong_db::GameState::Lobby => {
trace!("game entered lobby"); trace!("game entered lobby");
if !player.ready { if !player.ready {
for _ in 0..3 { for _ in 0..3 {
@ -195,31 +192,31 @@ fn on_lobby_insert_update(
stdb.reducers().start_game().unwrap(); stdb.reducers().start_game().unwrap();
} }
} }
stdb::GameState::Setup => { jong_db::GameState::Setup => {
trace!("game entered setup"); trace!("game entered setup");
stdb.reducers().shuffle_deal(player.lobby_id).unwrap(); stdb.reducers().shuffle_deal(player.lobby_id).unwrap();
} }
stdb::GameState::Deal => { jong_db::GameState::Deal => {
trace!("game entered deal"); trace!("game entered deal");
} }
stdb::GameState::Play => { jong_db::GameState::Play => {
trace!("game entered play"); trace!("game entered play");
match msg.new.turn_state { match msg.new.turn_state {
stdb::TurnState::None => {} jong_db::TurnState::None => {}
stdb::TurnState::Tsumo => { jong_db::TurnState::Tsumo => {
stdb.reducers().draw_tile().unwrap(); stdb.reducers().draw_tile().unwrap();
} }
stdb::TurnState::Menzen => todo!(), jong_db::TurnState::Menzen => todo!(),
stdb::TurnState::RiichiKan => todo!(), jong_db::TurnState::RiichiKan => todo!(),
stdb::TurnState::RonChiiPonKan => { jong_db::TurnState::RonChiiPonKan => {
stdb.reducers().skip_call().unwrap(); stdb.reducers().skip_call().unwrap();
} }
stdb::TurnState::End => todo!(), jong_db::TurnState::End => todo!(),
// _ => todo!(), // _ => todo!(),
} }
next_turnstate.set(msg.new.turn_state.into()); next_turnstate.set(msg.new.turn_state.into());
} }
stdb::GameState::Exit => { jong_db::GameState::Exit => {
trace!("game enetered exit"); trace!("game enetered exit");
} }
} }

View file

@ -5,7 +5,6 @@ use bevy_spacetimedb::StdbConnection;
use spacetimedb_sdk::credentials; use spacetimedb_sdk::credentials;
pub mod game; pub mod game;
pub mod stdb;
pub mod tile; pub mod tile;
pub mod yakus; pub mod yakus;
@ -13,60 +12,9 @@ trait EnumNextCycle {
fn next(&self) -> Self; fn next(&self) -> Self;
} }
pub type SpacetimeDB<'a> = Res<'a, StdbConnection<stdb::DbConnection>>; pub type SpacetimeDB<'a> = Res<'a, StdbConnection<jong_db::DbConnection>>;
fn creds_store() -> credentials::File { fn creds_store() -> credentials::File {
credentials::File::new("jongline") credentials::File::new("jongline")
} }
impl From<stdb::GameState> for jong_types::GameState {
fn from(value: stdb::GameState) -> Self {
Self::from_repr(value as usize).unwrap()
}
}
impl From<stdb::TurnState> 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<stdb::Suit> 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<stdb::Rank> for jong_types::Rank {
fn from(value: stdb::Rank) -> Self {
Self {
number: value.number,
}
}
}
impl From<stdb::Wind> for jong_types::Wind {
fn from(value: stdb::Wind) -> Self {
Self::from_repr(value as usize).unwrap()
}
}
impl From<stdb::Dragon> for jong_types::Dragon {
fn from(value: stdb::Dragon) -> Self {
Self::from_repr(value as usize).unwrap()
}
}

View file

@ -9,7 +9,6 @@ use jong::game::player::MainPlayer;
use tui_logger::TuiWidgetState; use tui_logger::TuiWidgetState;
use crate::tui::{input::ConfirmSelect, states::ConsoleWidget}; use crate::tui::{input::ConfirmSelect, states::ConsoleWidget};
use jong::stdb::{self, discard_tile as _};
use jong::{ use jong::{
SpacetimeDB, SpacetimeDB,
game::{ game::{
@ -17,6 +16,7 @@ use jong::{
player::{CurrentPlayer, Player}, player::{CurrentPlayer, Player},
}, },
}; };
use jong_db::{self, discard_tile as _};
use jong_types::{GameState, TurnState}; use jong_types::{GameState, TurnState};
mod input; mod input;

View file

@ -1,9 +1,9 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_ratatui::crossterm::event::KeyCode; use bevy_ratatui::crossterm::event::KeyCode;
use bevy_ratatui::event::KeyMessage; use bevy_ratatui::event::KeyMessage;
use jong::stdb::PlayerTableAccess; use jong_db::PlayerTableAccess;
use jong::stdb::join_or_create_lobby; use jong_db::join_or_create_lobby;
use jong::stdb::start_game; use jong_db::start_game;
use tui_logger::TuiWidgetEvent; use tui_logger::TuiWidgetEvent;
use jong::SpacetimeDB; use jong::SpacetimeDB;

View file

@ -4,16 +4,11 @@ alias rt := run-tui
alias s := spacetime alias s := spacetime
alias g := spacetime_generate-bindings alias g := spacetime_generate-bindings
rrt:
just spacetime_restart_dev
sleep 3sec
just run-tui
default: default:
just --list just --list
run-tui: run-tui:
spacetime call jongline "clear_all" spacetime call jong-line "clear_all"
cargo run -- run-tui cargo run -- run-tui
update: update:
@ -24,11 +19,16 @@ spacetime:
devenv up devenv up
spacetime_dev: 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-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: spacetime_restart_dev:
mprocs -s localhost:4050 --ctl $"({c: restart-proc, name: spacetimedb_dev} | to yaml)" mprocs -s localhost:4050 --ctl $"({c: restart-proc, name: spacetimedb_dev} | to yaml)"
rrt:
just spacetime_restart_dev
sleep 3sec
just run-tui

View file

@ -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 }