-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup cards to use config and added some initial cards
- Loading branch information
1 parent
f07121b
commit 85b522d
Showing
15 changed files
with
130 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
( | ||
card_texture_path: "image/card/yellow_card.png", | ||
cards: { | ||
BasicStep: CardInfo( | ||
name: "Basic Step", | ||
description: "A-one and a-two and a-step.", | ||
texture_path: "image/card/step.png", | ||
), | ||
DoubleBeat: CardInfo( | ||
name: "Double Beat", | ||
description: "Two beats, rapid fire!", | ||
texture_path: "image/card/double_beat.png", | ||
), | ||
CounterPoint: CardInfo( | ||
name: "Counter Point", | ||
description: "Notes that move apart synchronously", | ||
texture_path: "image/card/counter_point.png", | ||
), | ||
Splits: CardInfo( | ||
name: "Splits", | ||
description: "Split in two!", | ||
texture_path: "image/card/splits.png", | ||
), | ||
|
||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,89 @@ | ||
use bevy::asset::embedded_asset; | ||
use bevy::ecs::system::SystemId; | ||
use bevy::ecs::system::SystemState; | ||
use bevy::prelude::*; | ||
use bevy::utils::HashMap; | ||
use pyri_state::prelude::*; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
use crate::screen::Screen; | ||
use crate::util::prelude::*; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
// TODO: setup correct asset loading for cards | ||
embedded_asset!(app, "cards/sample_card.png"); | ||
app.configure::<ConfigHandle<CardConfig>>(); | ||
} | ||
|
||
app.add_systems( | ||
StateFlush, | ||
Screen::Playing.on_edge(exit_playing, enter_playing), | ||
); | ||
#[derive(Asset, Reflect, Serialize, Deserialize)] | ||
pub struct CardConfig { | ||
pub card_texture_path: String, | ||
#[serde(skip)] | ||
pub card_texture: Handle<Image>, | ||
cards: HashMap<CardKey, CardInfo>, | ||
} | ||
|
||
#[derive(Eq, PartialEq, Hash, Copy, Clone)] | ||
pub enum CardKey { | ||
Placeholder, | ||
#[derive(Asset, Reflect, Serialize, Deserialize)] | ||
struct CardInfo { | ||
name: String, | ||
description: String, | ||
texture_path: String, | ||
#[serde(skip)] | ||
texture: Handle<Image>, | ||
} | ||
|
||
impl Config for CardConfig { | ||
const PATH: &'static str = "config/card.ron"; | ||
const EXTENSION: &'static str = "card.ron"; | ||
|
||
fn on_load(&mut self, world: &mut World) { | ||
let id = world.register_system(basic_attack); | ||
let mut system_state = SystemState::<Res<AssetServer>>::new(world); | ||
let asset_server = system_state.get_mut(world); | ||
|
||
self.card_texture = asset_server.load(&self.card_texture_path); | ||
for card in self.cards.values_mut() { | ||
card.texture = asset_server.load(&card.texture_path); | ||
} | ||
|
||
let cards = self.cards.iter().map(|(key, value)| { | ||
( | ||
*key, | ||
Card { | ||
display_name: value.name.clone(), | ||
description: value.description.clone(), | ||
action: id, | ||
texture: value.texture.clone(), | ||
}, | ||
) | ||
}); | ||
|
||
world.insert_resource(CardStorage(cards.collect())); | ||
} | ||
|
||
fn is_ready(&self, asset_server: &AssetServer) -> bool { | ||
asset_server.is_loaded_with_dependencies(&self.card_texture) | ||
&& self | ||
.cards | ||
.values() | ||
.all(|x| asset_server.is_loaded_with_dependencies(&x.texture)) | ||
} | ||
} | ||
|
||
// TODO: Remove this `allow` later. | ||
#[allow(dead_code)] | ||
pub struct Card { | ||
pub path: String, | ||
pub display_name: String, | ||
pub description: String, | ||
pub texture: Handle<Image>, | ||
pub action: SystemId<Entity>, | ||
} | ||
|
||
#[derive(Reflect, Eq, PartialEq, Hash, Copy, Clone, Serialize, Deserialize)] | ||
pub enum CardKey { | ||
BasicStep, | ||
DoubleBeat, | ||
CounterPoint, | ||
Splits, | ||
} | ||
|
||
#[derive(Resource, Deref, DerefMut)] | ||
pub struct CardStorage(pub HashMap<CardKey, Card>); | ||
|
||
// TODO: Move this into a sub-folder of storing different attacks? | ||
fn basic_attack(In(_): In<Entity>) {} | ||
|
||
fn enter_playing(world: &mut World) { | ||
let id = world.register_system(basic_attack); | ||
world.insert_resource(CardStorage( | ||
[( | ||
CardKey::Placeholder, | ||
Card { | ||
path: "embedded://blobo_party/game/cards/sample_card.png".to_string(), | ||
action: id, | ||
}, | ||
)] | ||
.into(), | ||
)); | ||
} | ||
|
||
fn exit_playing(mut _commands: Commands) { | ||
// TODO: despawn cards? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters