feat: Enable dynamic shovel pricing calculation (#15)
This commit is contained in:
@@ -74,4 +74,19 @@ impl Grid {
|
||||
*tile_state = mapper(&*tile_state);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn count_claimed_tiles(&self, tile_query: &Query<&TileState>) -> u32 {
|
||||
self.tiles
|
||||
.iter()
|
||||
.flatten()
|
||||
.filter(|&entity| {
|
||||
if let Ok(state) = tile_query.get(*entity) {
|
||||
!matches!(state, TileState::Unclaimed)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.count() as u32
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,9 +162,17 @@ fn shop_keybind(
|
||||
mut commands: Commands,
|
||||
game_config: Res<GameConfig>,
|
||||
asset_server: Res<AssetServer>,
|
||||
grid: Res<Grid>,
|
||||
tile_query: Query<&TileState>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::KeyP) {
|
||||
open_shop(&mut commands, &game_config, &asset_server);
|
||||
open_shop(
|
||||
&mut commands,
|
||||
&game_config,
|
||||
&asset_server,
|
||||
&grid,
|
||||
&tile_query,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,14 @@ fn buttons(
|
||||
asset_server: Res<AssetServer>,
|
||||
mut inventory: ResMut<Inventory>,
|
||||
mut items: Query<&mut ItemStack>,
|
||||
grid: Res<Grid>,
|
||||
tile_query: Query<&TileState>,
|
||||
) {
|
||||
for (interaction, button_type) in &mut interaction_query {
|
||||
match *interaction {
|
||||
Interaction::Pressed => match button_type {
|
||||
ButtonType::ShopOpen => {
|
||||
open_shop(&mut commands, &game_config, &asset_server);
|
||||
open_shop(&mut commands, &game_config, &asset_server, &grid, &tile_query);
|
||||
}
|
||||
ButtonType::ShopBuyItem(offer) => {
|
||||
if offer.buy(&mut inventory, &mut commands, &mut items) {
|
||||
|
||||
@@ -5,9 +5,11 @@ pub fn open_shop(
|
||||
commands: &mut Commands,
|
||||
game_config: &GameConfig,
|
||||
asset_server: &Res<AssetServer>,
|
||||
grid: &Grid,
|
||||
tile_query: &Query<&TileState>,
|
||||
) {
|
||||
// TODO: calculate tile_count
|
||||
let offers = ShopOffer::list_all(game_config, 0);
|
||||
let tile_count = grid.count_claimed_tiles(tile_query);
|
||||
let offers = ShopOffer::list_all(game_config, tile_count);
|
||||
|
||||
spawn_popup(
|
||||
commands,
|
||||
|
||||
Reference in New Issue
Block a user