70 lines
2.0 KiB
Rust
70 lines
2.0 KiB
Rust
use bevy::prelude::*;
|
|
use pomomon_garden::features::config::components::{BerrySeedConfig, GameConfig};
|
|
use pomomon_garden::features::grid::components::{Grid, Tile, TileState};
|
|
use pomomon_garden::features::inventory::components::{Inventory, ItemStack, ItemType};
|
|
|
|
pub fn setup_app(
|
|
grid_width: u32,
|
|
grid_height: u32,
|
|
initial_tile_states: &[(u32, u32, TileState)],
|
|
initial_inventory: Vec<(ItemType, u32)>,
|
|
seed_configs: Option<Vec<BerrySeedConfig>>,
|
|
) -> App {
|
|
let mut app = App::new();
|
|
app.add_plugins(MinimalPlugins);
|
|
app.add_plugins(AssetPlugin::default());
|
|
|
|
// Grid Setup
|
|
let mut grid_tiles = Vec::with_capacity(grid_width as usize);
|
|
for x in 0..grid_width {
|
|
let mut column = Vec::with_capacity(grid_height as usize);
|
|
for y in 0..grid_height {
|
|
let entity = app
|
|
.world_mut()
|
|
.spawn((Tile { x, y }, TileState::Unclaimed))
|
|
.id();
|
|
column.push(entity);
|
|
}
|
|
grid_tiles.push(column);
|
|
}
|
|
app.insert_resource(Grid {
|
|
width: grid_width,
|
|
height: grid_height,
|
|
tiles: grid_tiles,
|
|
});
|
|
|
|
for &(x, y, ref state) in initial_tile_states {
|
|
if let Ok(entity) = app.world().resource::<Grid>().get_tile((x, y)) {
|
|
*app.world_mut().get_mut::<TileState>(entity).unwrap() = state.clone();
|
|
}
|
|
}
|
|
|
|
// Inventory Setup
|
|
let mut inventory_items = Vec::new();
|
|
for (item_type, amount) in initial_inventory {
|
|
let id = app.world_mut().spawn(ItemStack { item_type, amount }).id();
|
|
inventory_items.push(id);
|
|
}
|
|
app.insert_resource(Inventory {
|
|
items: inventory_items,
|
|
});
|
|
|
|
// Game Config
|
|
let seeds = seed_configs.unwrap_or_else(|| {
|
|
vec![BerrySeedConfig {
|
|
name: "TestSeed".to_string(),
|
|
cost: 1,
|
|
grants: 1,
|
|
slice: "seed.aseprite".to_string(),
|
|
growth_stages: 2,
|
|
}]
|
|
});
|
|
|
|
app.insert_resource(GameConfig {
|
|
berry_seeds: seeds,
|
|
..Default::default()
|
|
});
|
|
|
|
app
|
|
}
|