From 60c55b1b3cdc7a6116de996cb83096dd31681688 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 24 May 2023 17:45:45 +0300 Subject: [PATCH] feat(client): load cards from a yaml file --- client/assets/card_manifest.yaml | 70 ++++++++++++++++++++ client/src/main.rs | 39 +++++++++++- client/src/plugins/game/ui/mod.rs | 102 +++++++----------------------- client/src/util/mod.rs | 28 ++++++++ 4 files changed, 158 insertions(+), 81 deletions(-) create mode 100644 client/assets/card_manifest.yaml diff --git a/client/assets/card_manifest.yaml b/client/assets/card_manifest.yaml new file mode 100644 index 0000000..7023fbf --- /dev/null +++ b/client/assets/card_manifest.yaml @@ -0,0 +1,70 @@ +# - name: +# short_details: +# - +# long_details: +# cost: 0 +# actions: +# - command: +# R: +# R: +# R: +# target_self: true +# to_be_trashed: false + +--- +version: 0.0.1 +cards: + - name: The Hermits Sack + short_details: + - +2d4 currency + long_details: + - Roll 2d4 for currency + cost: 0 + actions: + - command: + !RollForCurrency + amount: 2 + sides: 4 + target_self: true + to_be_trashed: false + + - name: Punakärpässieni + short_details: + - +3VP, trash this + long_details: + - Get 3VP, trashing the card in the process + cost: 6 + actions: + - command: + !GiveVP + amount: 3 + target_self: true + to_be_trashed: true + + - name: Test Card 3 + short_details: + - Mark random card in opponents deck to be trashed + long_details: + - Placeholder. + cost: 6 + actions: + - command: + !MarkCardInDeckToBeTrashed + index: ~ + target_self: false + to_be_trashed: false + + - name: Test Card 4 + short_details: + - +1d4 plays + long_details: + - Roll 1d4 for plays + cost: 4 + actions: + - command: + !RollForPlays + amount: 1 + sides: 4 + target_self: true + to_be_trashed: false + diff --git a/client/src/main.rs b/client/src/main.rs index ed570e9..71b5896 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -29,6 +29,7 @@ mod util; mod plugins; mod game_status; +use game_status::Card; #[macro_export] macro_rules! seed_gen { @@ -92,6 +93,10 @@ fn main() { // clear color app.insert_resource(ClearColor(Color::rgb(0.53, 0.53, 0.7))); + // yaml assets + app.add_asset::() + .init_asset_loader::(); + // add the top level app state app.add_state::(); @@ -109,6 +114,8 @@ fn main() { app.add_plugin(plugins::MenuPlugin); app.add_plugin(plugins::GamePlugin); + app.add_event::() + .add_system(load_card_manifest.run_if(on_event::())); app.add_startup_system(setup).add_system(move_camera); app.run(); @@ -118,7 +125,14 @@ fn main() { #[derive(Component)] struct PlayerCamera; -fn setup(mut commands: Commands) { +fn setup( + mut commands: Commands, + asset_server: Res, + mut lcm_ev_w: EventWriter, +) { + commands.insert_resource(CardManifestHandle { handle: asset_server.load("card_manifest.yaml") }); + lcm_ev_w.send(LoadCardManifestEvent); + commands .spawn(( Camera3dBundle { @@ -134,6 +148,18 @@ fn setup(mut commands: Commands) { .insert(PlayerCamera); } +struct LoadCardManifestEvent; + +fn load_card_manifest( + mut commands: Commands, + yaml_assets: Res>, + card_manifest_handle: Res, +) { + let card_manifest_yaml: String = yaml_assets.get(&card_manifest_handle.handle).unwrap().0.clone(); + let card_manifest: CardManifest = serde_yaml::from_str(&card_manifest_yaml).unwrap(); + commands.insert_resource(card_manifest); +} + fn move_camera( time: Res