summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine-ecs/src/actions.rs12
-rw-r--r--engine-ecs/src/lib.rs21
-rw-r--r--engine/src/ui/dear_imgui.rs3
-rw-r--r--engine/src/windowing.rs3
4 files changed, 35 insertions, 4 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs
index cef51cc..bbc19c6 100644
--- a/engine-ecs/src/actions.rs
+++ b/engine-ecs/src/actions.rs
@@ -10,6 +10,7 @@ use crate::component::{
use crate::entity::Name as EntityName;
use crate::event::component::Removed;
use crate::pair::Pair;
+use crate::sole::Sole;
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
use crate::uid::Uid;
use crate::{ActionQueue, World};
@@ -304,6 +305,16 @@ impl Actions<'_>
});
}
+ /// Queues up creation of a sole at the end of the current tick, returning the [`Uid`]
+ /// of the sole.
+ pub fn create_sole<SoleT: Sole>(&mut self, sole: SoleT) -> Uid
+ {
+ self.action_queue
+ .push(Action::CreateSole(sole.into_parts()));
+
+ SoleT::id()
+ }
+
/// Stops the [`World`]. The world will finish the current tick and that tick will be
/// the last.
pub fn stop(&mut self)
@@ -339,5 +350,6 @@ pub(crate) enum Action
pair_id: Uid,
new_pair: ComponentParts,
},
+ CreateSole(ComponentParts),
Stop,
}
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index 6028cf7..188ca7a 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -667,6 +667,27 @@ impl World
&ComponentAddingFlags { allow_soles: false },
);
}
+ Action::CreateSole(sole_parts) => {
+ if let Err(EntityAlreadyExistsError) =
+ self.data.component_storage.create_entity(sole_parts.id)
+ {
+ tracing::error!(
+ name = sole_parts.name,
+ "Can not create sole that already exists"
+ );
+ continue;
+ }
+
+ let name = sole_parts.name;
+
+ Self::add_entity_components(
+ sole_parts.id,
+ [sole_parts, EntityName { name: name.into() }.into_parts()],
+ &mut self.data.component_storage,
+ &EventSubmitter::new(&self.data.new_events),
+ &ComponentAddingFlags { allow_soles: true },
+ );
+ }
Action::Stop => {
self.stop.store(true, Ordering::Relaxed);
}
diff --git a/engine/src/ui/dear_imgui.rs b/engine/src/ui/dear_imgui.rs
index 0047394..349cf6c 100644
--- a/engine/src/ui/dear_imgui.rs
+++ b/engine/src/ui/dear_imgui.rs
@@ -9,7 +9,6 @@ use dear_imgui_rs::{
MouseButton as ImguiMouseButton,
};
use ecs::component::local::Local;
-use ecs::component::Component;
use ecs::error::Context as _;
use ecs::event::component::{Changed, EventMatchExt};
use ecs::pair::Pair;
@@ -211,7 +210,7 @@ fn handle_window_changed(
let Some(event_match) = observe
.iter()
- .find(|event_match| event_match.get_entity().has_component(TargetWindow::id()))
+ .find(|event_match| event_match.get_entity().has_component::<TargetWindow>())
else {
return;
};
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs
index 46f281f..b76d942 100644
--- a/engine/src/windowing.rs
+++ b/engine/src/windowing.rs
@@ -23,7 +23,6 @@ use winit::keyboard::PhysicalKey;
use winit::window::{Window as WinitWindow, WindowId as WinitWindowId};
use crate::ecs::actions::Actions;
-use crate::ecs::component::Component;
use crate::ecs::event::component::{Added, Changed, EventMatchExt, Removed};
use crate::ecs::pair::{ChildOf, Pair};
use crate::ecs::phase::{Phase, PRE_UPDATE as PRE_UPDATE_PHASE};
@@ -112,7 +111,7 @@ fn handle_window_creation_ready(
unreachable!();
};
- if ent.has_component(Window::id()) || ent.has_component(WindowClosed::id()) {
+ if ent.has_component::<Window>() || ent.has_component::<WindowClosed>() {
continue;
}