feat: Add seed game config entries (#51)
This commit is contained in:
@@ -1,5 +1,25 @@
|
|||||||
{
|
{
|
||||||
"grid_width": 12,
|
"grid_width": 12,
|
||||||
"grid_height": 4,
|
"grid_height": 4,
|
||||||
"pom_speed": 1.5
|
"pom_speed": 1.5,
|
||||||
|
"berry_seeds": [
|
||||||
|
{
|
||||||
|
"name": "Normale Samen",
|
||||||
|
"cost": 1,
|
||||||
|
"grants": 2,
|
||||||
|
"slice": "Seed1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Super-Samen",
|
||||||
|
"cost": 3,
|
||||||
|
"grants": 9,
|
||||||
|
"slice": "Seed2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Zauber-Samen",
|
||||||
|
"cost": 5,
|
||||||
|
"grants": 20,
|
||||||
|
"slice": "Seed3"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ pub struct GameConfig {
|
|||||||
pub grid_width: u32,
|
pub grid_width: u32,
|
||||||
pub grid_height: u32,
|
pub grid_height: u32,
|
||||||
pub pom_speed: f32,
|
pub pom_speed: f32,
|
||||||
|
pub berry_seeds: Vec<BerrySeedConfig>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct BerrySeedConfig {
|
||||||
|
pub name: String,
|
||||||
|
pub cost: u32,
|
||||||
|
pub grants: u32,
|
||||||
|
pub slice: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GameConfig {
|
impl Default for GameConfig {
|
||||||
@@ -15,6 +24,26 @@ impl Default for GameConfig {
|
|||||||
grid_width: 12,
|
grid_width: 12,
|
||||||
grid_height: 4,
|
grid_height: 4,
|
||||||
pom_speed: 1.5,
|
pom_speed: 1.5,
|
||||||
|
berry_seeds: vec![
|
||||||
|
BerrySeedConfig {
|
||||||
|
name: "Normale Samen".to_string(),
|
||||||
|
cost: 1,
|
||||||
|
grants: 2,
|
||||||
|
slice: "Seed1".to_string(),
|
||||||
|
},
|
||||||
|
BerrySeedConfig {
|
||||||
|
name: "Super-Samen".to_string(),
|
||||||
|
cost: 3,
|
||||||
|
grants: 9,
|
||||||
|
slice: "Seed2".to_string(),
|
||||||
|
},
|
||||||
|
BerrySeedConfig {
|
||||||
|
name: "Zauber-Samen".to_string(),
|
||||||
|
cost: 5,
|
||||||
|
grants: 20,
|
||||||
|
slice: "Seed3".to_string(),
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,80 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub enum ItemType {
|
pub enum ItemType {
|
||||||
Berry,
|
Berry,
|
||||||
BerrySeed {
|
BerrySeed { name: String },
|
||||||
prefix: String,
|
|
||||||
cost: u32,
|
|
||||||
grants: u32,
|
|
||||||
slice: String,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemType {
|
impl ItemType {
|
||||||
pub fn singular(&self) -> String {
|
pub fn singular(&self, game_config: &GameConfig) -> String {
|
||||||
match self {
|
match self {
|
||||||
ItemType::Berry => "Beere".into(),
|
ItemType::Berry => "Beere".into(),
|
||||||
ItemType::BerrySeed { prefix, .. } => format!("{}samen", prefix),
|
ItemType::BerrySeed { name } => {
|
||||||
|
let seed_config = game_config.berry_seeds.iter().find(|s| s.name == *name);
|
||||||
|
seed_config
|
||||||
|
.map(|s| s.name.clone())
|
||||||
|
.unwrap_or_else(|| format!("Unbekannter Samen ({})", name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn plural(&self) -> String {
|
pub fn plural(&self, game_config: &GameConfig) -> String {
|
||||||
match self {
|
match self {
|
||||||
ItemType::Berry => "Beeren".into(),
|
ItemType::Berry => "Beeren".into(),
|
||||||
ItemType::BerrySeed { prefix, .. } => format!("{}samen", prefix),
|
ItemType::BerrySeed { name } => {
|
||||||
|
let seed_config = game_config.berry_seeds.iter().find(|s| s.name == *name);
|
||||||
|
seed_config
|
||||||
|
.map(|s| s.name.clone())
|
||||||
|
.unwrap_or_else(|| format!("Unbekannte Samen ({})", name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&self) -> String {
|
pub fn description(&self, game_config: &GameConfig) -> String {
|
||||||
match self {
|
match self {
|
||||||
ItemType::Berry => {
|
ItemType::Berry => {
|
||||||
"Von Pflanzen erntbar. Kann im Shop zum Einkaufen benutzt werden.".into()
|
"Von Pflanzen erntbar. Kann im Shop zum Einkaufen benutzt werden.".into()
|
||||||
}
|
}
|
||||||
ItemType::BerrySeed { grants, .. } => format!(
|
ItemType::BerrySeed { name } => {
|
||||||
"Im Shop kaufbar. Kann eingepflanzt werden. Erhalte beim Ernten {} {}.",
|
let seed_config = game_config.berry_seeds.iter().find(|s| s.name == *name);
|
||||||
grants,
|
if let Some(s) = seed_config {
|
||||||
match grants {
|
format!(
|
||||||
1 => ItemType::Berry.singular(),
|
"Im Shop kaufbar. Kann eingepflanzt werden. Erhalte beim Ernten {} {}.",
|
||||||
_ => ItemType::Berry.plural(),
|
s.grants,
|
||||||
|
match s.grants {
|
||||||
|
1 => ItemType::Berry.singular(game_config),
|
||||||
|
_ => ItemType::Berry.plural(game_config),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
format!("Unbekannter Samen ({})", name)
|
||||||
}
|
}
|
||||||
),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_sprite(&self, asset_server: Res<AssetServer>) -> AseSlice {
|
pub fn get_sprite(&self, asset_server: Res<AssetServer>, game_config: &GameConfig) -> AseSlice {
|
||||||
match self {
|
match self {
|
||||||
ItemType::Berry => AseSlice {
|
ItemType::Berry => AseSlice {
|
||||||
name: "Berry".into(),
|
name: "Berry".into(),
|
||||||
aseprite: asset_server.load("berry.aseprite"),
|
aseprite: asset_server.load("berry.aseprite"),
|
||||||
},
|
},
|
||||||
ItemType::BerrySeed { slice, .. } => AseSlice {
|
ItemType::BerrySeed { name } => {
|
||||||
name: slice.into(),
|
let seed_config = game_config.berry_seeds.iter().find(|s| s.name == *name);
|
||||||
aseprite: asset_server.load("seed.aseprite"),
|
if let Some(s) = seed_config {
|
||||||
},
|
AseSlice {
|
||||||
|
name: s.slice.clone(),
|
||||||
|
aseprite: asset_server.load("seed.aseprite"),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback for unknown seed
|
||||||
|
AseSlice {
|
||||||
|
name: "Seed1".into(),
|
||||||
|
aseprite: asset_server.load("seed.aseprite"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,13 @@ fn buttons(
|
|||||||
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
|
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
|
||||||
itemstack_query: Query<&ItemStack>,
|
itemstack_query: Query<&ItemStack>,
|
||||||
root_query: Query<(Entity, &RootMarker)>,
|
root_query: Query<(Entity, &RootMarker)>,
|
||||||
|
game_config: Res<GameConfig>,
|
||||||
) {
|
) {
|
||||||
for (interaction, button_type) in &mut interaction_query {
|
for (interaction, button_type) in &mut interaction_query {
|
||||||
match *interaction {
|
match *interaction {
|
||||||
Interaction::Pressed => match button_type {
|
Interaction::Pressed => match button_type {
|
||||||
ButtonType::InventoryOpen => {
|
ButtonType::InventoryOpen => {
|
||||||
open_inventory(&mut commands, itemstack_query);
|
open_inventory(&mut commands, itemstack_query, &game_config);
|
||||||
}
|
}
|
||||||
ButtonType::InventoryClose => {
|
ButtonType::InventoryClose => {
|
||||||
for (entity, root) in root_query.iter() {
|
for (entity, root) in root_query.iter() {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use super::super::components::{ButtonType, RootMarker};
|
use super::super::components::{ButtonType, RootMarker};
|
||||||
|
use crate::prelude::GameConfig;
|
||||||
use crate::{features::inventory::ui::list_itemstack, prelude::*};
|
use crate::{features::inventory::ui::list_itemstack, prelude::*};
|
||||||
|
|
||||||
pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
|
pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>, game_config: &Res<GameConfig>) {
|
||||||
commands
|
commands
|
||||||
.spawn((
|
.spawn((
|
||||||
RootMarker::Inventory,
|
RootMarker::Inventory,
|
||||||
@@ -57,7 +58,7 @@ pub fn open_inventory(commands: &mut Commands, items: Query<&ItemStack>) {
|
|||||||
})
|
})
|
||||||
.with_children(|parent| {
|
.with_children(|parent| {
|
||||||
for itemstack in items.iter() {
|
for itemstack in items.iter() {
|
||||||
parent.spawn(list_itemstack(itemstack));
|
parent.spawn(list_itemstack(itemstack, game_config));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub fn list_itemstack(itemstack: &ItemStack) -> impl Bundle {
|
pub fn list_itemstack(itemstack: &ItemStack, game_config: &GameConfig) -> impl Bundle {
|
||||||
let name = match itemstack.amount {
|
let name = match itemstack.amount {
|
||||||
1 => itemstack.item_type.singular(),
|
1 => itemstack.item_type.singular(game_config),
|
||||||
_ => itemstack.item_type.plural(),
|
_ => itemstack.item_type.plural(game_config),
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -36,7 +36,11 @@ pub fn list_itemstack(itemstack: &ItemStack) -> impl Bundle {
|
|||||||
14.0,
|
14.0,
|
||||||
Color::WHITE
|
Color::WHITE
|
||||||
),
|
),
|
||||||
text(itemstack.item_type.description(), 10.0, Color::WHITE)
|
text(
|
||||||
|
itemstack.item_type.description(game_config),
|
||||||
|
10.0,
|
||||||
|
Color::WHITE
|
||||||
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user