Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz authored and regnarock committed Dec 13, 2023
1 parent 4815544 commit 293c0b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/buildings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ pub struct CreateItemDefVisual {
impl EntityCommand for CreateItemDefVisual {
fn apply(self, id: Entity, world: &mut World) {
let assets = world.get_resource::<VisualAssets>().unwrap();
let visual = (MaterialMesh2dBundle {
let visual = MaterialMesh2dBundle {
mesh: assets.mesh_def[&self.item_type.0].clone(),
transform: Transform::default().with_scale(Vec3::splat(
ITEM_VISUAL_SIZE * assets.size_def[&self.item_type.1],
)),
material: assets.color_def[&self.item_type.2].clone(),
..default()
});
};
world.entity_mut(id).insert(visual);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/random.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
use std::marker::PhantomData;


#[derive(Component)]
pub struct RandomDeterministic {
Expand All @@ -12,7 +12,7 @@ pub struct RandomDeterministic {
impl Default for RandomDeterministic {
fn default() -> Self {
let seed = 0; //thread_rng().gen::<u64>();
return Self::new_from_seed(seed);
Self::new_from_seed(seed)
}
}

Expand Down
32 changes: 17 additions & 15 deletions src/turret.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{f32::consts::FRAC_PI_2, time::Duration};

use crate::{
buildings::{self, ItemType},
buildings::{self},
bullet::SpawnBullet,
enemy::Enemy,
grid::{HexCell, HexGrid},
inventory::{self, Inventory},
grid::{HexGrid},
primitives::{
target::{SourceWithTargetAccessor, Target},
view::{
Expand All @@ -16,7 +15,7 @@ use crate::{
GameState,
};
use bevy::{
ecs::system::{CommandQueue, EntityCommand, SystemState},
ecs::system::{EntityCommand, SystemState},
math::Vec3,
prelude::*,
sprite::SpriteBundle,
Expand Down Expand Up @@ -80,32 +79,35 @@ impl EntityCommand for SpawnTurret {
let mut new_item = || {
let (mut q_inventory, q_items) = state.get_mut(world);

let (mut rng, mut inventory) = q_inventory.single_mut();
let (_rng, mut inventory) = q_inventory.single_mut();

let Some(first_item) = inventory.items.front() else {
let Some(first_item) = inventory.items.front().cloned() else {
return None;
};
let Ok(item_to_build) = q_items.get(*first_item) else {
let Ok(_item_to_build) = q_items.get(first_item) else {
return None;
};
// TODO: check if we can build item_to_build (cooldown, space available, currency, ...)
// TODO: send an event if not possible.
// TODO: pay "price" ?
inventory.items.pop_front();
drop(inventory);

/*
let new_item = buildings::get_random_item(&mut rng);
let mut queue = CommandQueue::default();
let new_item = world.spawn(new_item).id();
Some(new_item)
let new_item = world.spawn(new_item).id();*/
Some((first_item, first_item))
};

let Some(new_item) = new_item() else {
let Some((item_built, _new_item)) = new_item() else {
return;
};
let (mut q_inventory, q_items) = state.get_mut(world);
let (rng, mut inventory) = q_inventory.single_mut();
// TODO: reuse that entity to merge it with turret entity ?
world.despawn(item_built);
let (mut q_inventory, _q_items) = state.get_mut(world);
let (_rng, _inventory) = q_inventory.single_mut();

//inventory.items.push_back(new_item);

inventory.items.push_back(new_item);
let texture = world.resource_scope(|_, asset_server: Mut<AssetServer>| {
asset_server.load("textures/DifferentTurrets/Turret01.png")
});
Expand Down

0 comments on commit 293c0b1

Please sign in to comment.