plugins
This commit is contained in:
parent
53e4047e6a
commit
178c344859
4 changed files with 125 additions and 118 deletions
91
src/game.rs
Normal file
91
src/game.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::tiles::{self, *};
|
||||
|
||||
pub struct Riichi;
|
||||
|
||||
impl Plugin for Riichi {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<Compass>()
|
||||
.add_systems(Startup, init_match)
|
||||
.add_systems(Startup, tiles::init_tiles);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Player {
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Points(isize);
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Dice(u8, u8);
|
||||
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct Compass {
|
||||
pub(crate) prevalent_wind: Wind,
|
||||
pub(crate) round: u8,
|
||||
pub(crate) dealer_wind: Wind,
|
||||
pub(crate) riichi: usize,
|
||||
pub(crate) honba: usize,
|
||||
}
|
||||
|
||||
impl Default for Compass {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prevalent_wind: Wind::Ton,
|
||||
round: 1,
|
||||
dealer_wind: Wind::Ton,
|
||||
riichi: 0,
|
||||
honba: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct MatchSettings {
|
||||
pub(crate) starting_points: isize,
|
||||
pub(crate) player_count: u8,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Wall(VecDeque<Tile>);
|
||||
|
||||
pub(crate) fn next_round(mut compass: Res<Compass>) {}
|
||||
|
||||
pub(crate) fn init_match(
|
||||
mut commands: Commands,
|
||||
// , mut compass: ResMut<Compass>
|
||||
) {
|
||||
let starting = 25000;
|
||||
let player_count = 4;
|
||||
|
||||
commands.insert_resource(MatchSettings {
|
||||
starting_points: starting,
|
||||
player_count,
|
||||
});
|
||||
|
||||
let players = (1..=player_count)
|
||||
.map(|i| {
|
||||
(
|
||||
Player {
|
||||
name: format!("Player {i}"),
|
||||
},
|
||||
Points(starting),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
commands.spawn_batch(players);
|
||||
|
||||
// *compass = Compass {
|
||||
// prevalent_wind: Wind::Ton,
|
||||
// round: 1,
|
||||
// dealer_wind: todo!(),
|
||||
// riichi: 0,
|
||||
// honba: 0,
|
||||
// }
|
||||
}
|
||||
107
src/main.rs
107
src/main.rs
|
|
@ -1,14 +1,11 @@
|
|||
use std::{collections::VecDeque, time::Duration};
|
||||
|
||||
use bevy::{app::ScheduleRunnerPlugin, input::keyboard::Key, prelude::*};
|
||||
use bevy_ratatui::RatatuiPlugins;
|
||||
use bevy::prelude::*;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::tiles::*;
|
||||
|
||||
mod tiles;
|
||||
mod yakus;
|
||||
|
||||
mod game;
|
||||
|
||||
mod gui;
|
||||
mod tui;
|
||||
|
||||
|
|
@ -30,104 +27,10 @@ fn main() {
|
|||
let mut app = App::new();
|
||||
let app = match args.mode {
|
||||
Mode::RunGui => app.add_plugins(DefaultPlugins),
|
||||
Mode::RunTui => app
|
||||
.add_plugins((
|
||||
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
|
||||
1. / 1.,
|
||||
))),
|
||||
RatatuiPlugins {
|
||||
// enable_kitty_protocol: todo!(),
|
||||
// enable_mouse_capture: todo!(),
|
||||
enable_input_forwarding: true,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
.add_systems(Update, tui::draw_system),
|
||||
Mode::RunTui => app.add_plugins(tui::RiichiTui),
|
||||
};
|
||||
|
||||
app.init_resource::<Compass>()
|
||||
.add_systems(Startup, init_match)
|
||||
.add_systems(Startup, init_tiles);
|
||||
app.add_plugins(game::Riichi);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
fn keyboard_input_system(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
key_input: Res<ButtonInput<Key>>,
|
||||
) {
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Player {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Points(isize);
|
||||
|
||||
#[derive(Component)]
|
||||
struct Dice(u8, u8);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct Compass {
|
||||
prevalent_wind: Wind,
|
||||
round: u8,
|
||||
dealer_wind: Wind,
|
||||
riichi: usize,
|
||||
honba: usize,
|
||||
}
|
||||
|
||||
impl Default for Compass {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
prevalent_wind: Wind::Ton,
|
||||
round: 1,
|
||||
dealer_wind: Wind::Ton,
|
||||
riichi: 0,
|
||||
honba: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct MatchSettings {
|
||||
starting_points: isize,
|
||||
player_count: u8,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct Wall(VecDeque<Tile>);
|
||||
|
||||
fn next_round(mut compass: Res<Compass>) {}
|
||||
|
||||
fn init_match(mut commands: Commands, // , mut compass: ResMut<Compass>
|
||||
) {
|
||||
let starting = 25000;
|
||||
let player_count = 4;
|
||||
|
||||
commands.insert_resource(MatchSettings {
|
||||
starting_points: starting,
|
||||
player_count,
|
||||
});
|
||||
|
||||
let players = (1..=player_count)
|
||||
.map(|i| {
|
||||
(
|
||||
Player {
|
||||
name: format!("Player {i}"),
|
||||
},
|
||||
Points(starting),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
commands.spawn_batch(players);
|
||||
|
||||
// *compass = Compass {
|
||||
// prevalent_wind: Wind::Ton,
|
||||
// round: 1,
|
||||
// dealer_wind: todo!(),
|
||||
// riichi: 0,
|
||||
// honba: 0,
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
// use bevy::ecs::message::MessageReader;
|
||||
use bevy::app::AppExit;
|
||||
use bevy::input::keyboard::Key;
|
||||
use bevy::prelude::*;
|
||||
use bevy_ratatui::crossterm::event::KeyCode;
|
||||
use bevy_ratatui::event::KeyMessage;
|
||||
|
||||
pub(crate) fn input_system(
|
||||
mut messages: MessageReader<KeyMessage>,
|
||||
mut exit: MessageWriter<AppExit>,
|
||||
pub(crate) fn keyboard_input_system(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
key_input: Res<ButtonInput<Key>>,
|
||||
) {
|
||||
for message in messages.read() {
|
||||
match message.code {
|
||||
KeyCode::Char('q') => {
|
||||
exit.write_default();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,31 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::{app::ScheduleRunnerPlugin, prelude::*};
|
||||
use bevy_ratatui::{RatatuiContext, RatatuiPlugins};
|
||||
|
||||
use crate::tiles::Tile;
|
||||
|
||||
pub(crate) mod input;
|
||||
mod input;
|
||||
|
||||
pub(crate) use input::input_system;
|
||||
pub struct RiichiTui;
|
||||
|
||||
impl Plugin for RiichiTui {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins((
|
||||
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
|
||||
1. / 1.,
|
||||
))),
|
||||
RatatuiPlugins {
|
||||
// enable_kitty_protocol: todo!(),
|
||||
// enable_mouse_capture: todo!(),
|
||||
enable_input_forwarding: true,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
.add_systems(Update, draw_system)
|
||||
.add_systems(Update, input::keyboard_input_system);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_system(mut context: ResMut<RatatuiContext>, query: Query<&Tile>) -> Result {
|
||||
context.draw(|frame| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue