Compare commits

..

No commits in common. "034e543d4049a27638e35120a8c8606b6402b58a" and "1afb7f4e3dd92dceb61553e3b4a3e42a854e9a9b" have entirely different histories.

51 changed files with 336 additions and 546 deletions

626
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

@ -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-db/src/db jong-line --delete-data=always";
exec = "spacetime dev --module-bindings-path jong/src/stdb jongline --delete-data=always";
# notify.enable = true;
# TODO features not yet supp???
# restart = "always";

View file

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

View file

@ -1,54 +0,0 @@
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()
}
}

View file

@ -1,12 +0,0 @@
[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,8 +8,6 @@ edition = "2024"
[dependencies]
bevy.workspace = true
bevy.features = ["bevy_state"]
spacetimedb.workspace = true
strum.workspace = true
derive_aliases = "0.4.7"
spacetimedb.workspace = true
strum.workspace = true

View file

@ -10,30 +10,21 @@ readme = false
[lib]
[dependencies]
# jong
jong-types.workspace = true
jong-db.path = "../jong-db"
# bevy
bevy.workspace = true
bevy.features = ["default", "dynamic_linking"]
bevy = { workspace = true, features = ["default", "dynamic_linking"] }
bevy_ratatui.workspace = true
# spacetimedb
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-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-subscriber.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
tui-logger = { workspace = true, features = ["tracing-support", "crossterm"] }

View file

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

View file

@ -5,6 +5,7 @@ use bevy_spacetimedb::StdbConnection;
use spacetimedb_sdk::credentials;
pub mod game;
pub mod stdb;
pub mod tile;
pub mod yakus;
@ -12,9 +13,60 @@ trait EnumNextCycle {
fn next(&self) -> Self;
}
pub type SpacetimeDB<'a> = Res<'a, StdbConnection<jong_db::DbConnection>>;
pub type SpacetimeDB<'a> = Res<'a, StdbConnection<stdb::DbConnection>>;
fn creds_store() -> credentials::File {
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,6 +9,7 @@ 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::{
@ -16,7 +17,6 @@ use jong::{
player::{CurrentPlayer, Player},
},
};
use jong_db::{self, discard_tile as _};
use jong_types::{GameState, TurnState};
mod input;

View file

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

View file

@ -4,11 +4,16 @@ 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 jong-line "clear_all"
spacetime call jongline "clear_all"
cargo run -- run-tui
update:
@ -19,16 +24,11 @@ spacetime:
devenv up
spacetime_dev:
spacetime dev --module-bindings-path jong-db/src/db jong-line --delete-data=always
spacetime dev --module-bindings-path jong/src/stdb jongline --delete-data=always
spacetime_generate-bindings:
spacetime generate --lang rust --out-dir jong-db/src/db --project-path jong-line
spacetime generate --lang rust --out-dir jong/src/stdb --project-path spacetimedb
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

14
spacetimedb/Cargo.toml Normal file
View file

@ -0,0 +1,14 @@
[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 }