init tiles, table/camera/environment placeholder

This commit is contained in:
Tao Tien 2026-01-05 23:49:37 -08:00
parent 78cc4be844
commit b47ecbf45a
6 changed files with 172 additions and 1 deletions

28
Cargo.lock generated
View file

@ -2616,6 +2616,12 @@ dependencies = [
"stable_deref_trait", "stable_deref_trait",
] ]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.5.2" version = "0.5.2"
@ -4174,6 +4180,27 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
[[package]]
name = "strum"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "svg_fmt" name = "svg_fmt"
version = "0.4.5" version = "0.4.5"
@ -4325,6 +4352,7 @@ name = "tiny_riichi"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bevy", "bevy",
"strum",
] ]
[[package]] [[package]]

View file

@ -5,6 +5,7 @@ edition = "2024"
[dependencies] [dependencies]
bevy = { version = "0.17.3", features = ["dynamic_linking"] } bevy = { version = "0.17.3", features = ["dynamic_linking"] }
strum = { version = "0.27.2", features = ["derive"] }
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1

31
src/gui/mod.rs Normal file
View file

@ -0,0 +1,31 @@
use bevy::{color::palettes::css::GREEN, prelude::*};
pub(crate) mod tiles;
pub(crate) fn init_environment(mut commands: Commands) {
commands.spawn((
DirectionalLight {
shadows_enabled: true,
..default()
},
// Transform::from_xyz(),
));
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-200.5, 100., 0.).looking_at(Vec3::ZERO, Vec3::Y),
));
}
pub(crate) fn init_table(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let green: Color = GREEN.into();
let table = Cuboid::new(1000., 5., 1000.);
commands.spawn((
Mesh3d(meshes.add(table)),
MeshMaterial3d(materials.add(green)),
));
}

99
src/gui/tiles.rs Normal file
View file

@ -0,0 +1,99 @@
use bevy::{color::palettes::css::GREY, prelude::*};
use strum::FromRepr;
#[derive(Component)]
pub(crate) enum Tile {
Pin(Number),
Sou(Number),
Man(Number),
Wind(Wind),
Dragon(Dragon),
}
#[derive(FromRepr)]
pub(crate) enum Number {
One = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
}
#[derive(FromRepr)]
pub(crate) enum Wind {
Ton,
Nan,
Shaa,
Pei,
}
#[derive(FromRepr)]
pub(crate) enum Dragon {
Haku,
Hatsu,
Chun,
}
#[derive(Component)]
struct Dora;
pub fn init_tileset(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let cuboid = Cuboid::new(25., 20., 16.);
for _ in 0..4 {
for i in 1..=9 {
commands.spawn((
(
Mesh3d(meshes.add(cuboid)),
Transform::from_xyz(30., 0., 0.),
MeshMaterial3d(materials.add(std::convert::Into::<Color>::into(GREY))),
),
Tile::Pin(Number::from_repr(i).unwrap()),
));
commands.spawn((
(
Mesh3d(meshes.add(cuboid)),
Transform::from_xyz(30., 0., 0.),
MeshMaterial3d(materials.add(std::convert::Into::<Color>::into(GREY))),
),
Tile::Sou(Number::from_repr(i).unwrap()),
));
commands.spawn((
(
Mesh3d(meshes.add(cuboid)),
Transform::from_xyz(30., 0., 0.),
MeshMaterial3d(materials.add(std::convert::Into::<Color>::into(GREY))),
),
Tile::Man(Number::from_repr(i).unwrap()),
));
}
for i in 0..4 {
commands.spawn((
(
Mesh3d(meshes.add(cuboid)),
Transform::from_xyz(30., 0., 0.),
MeshMaterial3d(materials.add(std::convert::Into::<Color>::into(GREY))),
),
Tile::Wind(Wind::from_repr(i).unwrap()),
));
}
for i in 0..3 {
commands.spawn((
(
Mesh3d(meshes.add(cuboid)),
Transform::from_xyz(30., 0., 0.),
MeshMaterial3d(materials.add(std::convert::Into::<Color>::into(GREY))),
),
Tile::Dragon(Dragon::from_repr(i).unwrap()),
));
}
}
}

View file

@ -1,3 +1,15 @@
use bevy::prelude::*;
use crate::gui::{tiles::*, *};
mod gui;
mod tui;
fn main() { fn main() {
println!("Hello, world!"); App::new()
// .add_plugins(DefaultPlugins)
.add_systems(Startup, init_table)
.add_systems(Startup, init_tileset)
.add_systems(Startup, init_environment)
.run();
} }

0
src/tui.rs Normal file
View file