Compare commits

...

8 commits

14 changed files with 46 additions and 50 deletions

View file

@ -13,8 +13,8 @@ rayon = "1.10.0"
chrono = { version = "0.4.35", features = ["serde"] } chrono = { version = "0.4.35", features = ["serde"] }
anyhow = { version = "1.0.86", features = ["backtrace"] } anyhow = { version = "1.0.86", features = ["backtrace"] }
indexmap = { version = "2.2.6", features = ["rayon"] } indexmap = { version = "2.2.6", features = ["rayon"] }
shaderc = { version = "0.8.3", features = ["build-from-source"] } shaderc = { version = "0.9.0", features = ["build-from-source"] }
rusqlite = { version = "0.33.0", features = ["bundled"] } rusqlite = { version = "0.34.0", features = ["bundled"] }
cgmath = "0.18.0" cgmath = "0.18.0"
http = "1.1.0" http = "1.1.0"
iterchunks = "0.5.0" iterchunks = "0.5.0"

View file

@ -6,7 +6,6 @@ edition = "2024"
[dependencies] [dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
paste = { workspace = true } paste = { workspace = true }
destructure_traitobject = { workspace = true }
downcast-rs = { workspace = true } downcast-rs = { workspace = true }
engine = { workspace = true } engine = { workspace = true }

View file

@ -106,7 +106,7 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
menu.add_tooltip("active_ability", gui); menu.add_tooltip("active_ability", gui);
} }
} else { } else {
menu.remove_tooltip("active_ability"); menu.remove_tooltip(world, "active_ability")?;
} }
} }

View file

@ -124,7 +124,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityAddon> {
} else { } else {
let window = reference.upgrade().unwrap(); let window = reference.upgrade().unwrap();
window.remove_tooltip(format!("addon_{index}")); window.remove_tooltip(world, format!("addon_{index}"))?;
} }
Ok(()) Ok(())
@ -275,8 +275,8 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityBook<A>> {
} else { } else {
let window = reference.upgrade().unwrap(); let window = reference.upgrade().unwrap();
window.remove_tooltip(format!("book_{index}")); window.remove_tooltip(world, format!("book_{index}"))?;
window.remove_tooltip("active_book"); window.remove_tooltip(world, "active_book")?;
} }
Ok(()) Ok(())

View file

@ -217,8 +217,8 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, Item> {
} else { } else {
let window = reference.upgrade().unwrap(); let window = reference.upgrade().unwrap();
window.remove_tooltip(format!("item_{index}")); window.remove_tooltip(world, format!("item_{index}"))?;
window.remove_tooltip("equip"); window.remove_tooltip(world, "equip")?;
} }
Ok(()) Ok(())
@ -337,7 +337,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, Jewel> {
} else { } else {
let window = reference.upgrade().unwrap(); let window = reference.upgrade().unwrap();
window.remove_tooltip(format!("jewel_{index}")); window.remove_tooltip(world, format!("jewel_{index}"))?;
} }
Ok(()) Ok(())

View file

@ -211,11 +211,11 @@ mod macros {
reference.upgrade().unwrap().add_tooltip("equip", gui); reference.upgrade().unwrap().add_tooltip("equip", gui);
} }
None => { None => {
reference.upgrade().unwrap().remove_tooltip("equip"); reference.upgrade().unwrap().remove_tooltip(world, "equip")?;
} }
} }
} else { } else {
reference.upgrade().unwrap().remove_tooltip("equip"); reference.upgrade().unwrap().remove_tooltip(world, "equip")?;
} }
Ok(()) Ok(())
@ -346,11 +346,11 @@ mod macros {
reference.upgrade().unwrap().add_tooltip("equip", gui); reference.upgrade().unwrap().add_tooltip("equip", gui);
} }
None => { None => {
reference.upgrade().unwrap().remove_tooltip("equip"); reference.upgrade().unwrap().remove_tooltip(world, "equip")?;
} }
} }
} else { } else {
reference.upgrade().unwrap().remove_tooltip("equip"); reference.upgrade().unwrap().remove_tooltip(world, "equip")?;
} }
Ok(()) Ok(())

View file

@ -120,7 +120,7 @@ impl JewelRightSide {
menu.add_tooltip("upper", tooltip); menu.add_tooltip("upper", tooltip);
} }
} else { } else {
menu.remove_tooltip("upper"); menu.remove_tooltip(world, "upper")?;
} }
Ok(()) Ok(())
@ -163,7 +163,7 @@ impl JewelRightSide {
menu.add_tooltip(format!("lower_{index}",), tooltip); menu.add_tooltip(format!("lower_{index}",), tooltip);
} }
} else { } else {
menu.remove_tooltip(format!("lower_{index}")); menu.remove_tooltip(world, format!("lower_{index}"))?;
} }
Ok(()) Ok(())

View file

@ -234,8 +234,12 @@ impl CharacterWindow {
.insert(name.to_string(), gui.into()); .insert(name.to_string(), gui.into());
} }
pub fn remove_tooltip(&self, name: impl ToString) { pub fn remove_tooltip(&self, world: &mut World, name: impl ToString) -> Result<()> {
self.tooltips.lock().unwrap().remove(&name.to_string()); if let Some(tooltip) = self.tooltips.lock().unwrap().remove(&name.to_string()) {
tooltip.disable(world)?;
}
Ok(())
} }
pub fn salvage_from_inventory<A, F, S>(world: &mut World, hero: Entity, f: F) -> Result<()> pub fn salvage_from_inventory<A, F, S>(world: &mut World, hero: Entity, f: F) -> Result<()>

View file

@ -7,7 +7,4 @@ edition = "2024"
anyhow = { workspace = true } anyhow = { workspace = true }
rusqlite = { workspace = true } rusqlite = { workspace = true }
assetpath = { workspace = true } assetpath = { workspace = true }
destructure_traitobject = { workspace = true }
engine = { workspace = true } engine = { workspace = true }
ecs = { workspace = true }

View file

@ -326,8 +326,8 @@ impl Map {
) )
} }
pub fn disable_spawns(&self, world: &mut World) -> Result<()> { pub fn disable_spawns(&self, world: &mut World) {
self.data.write().unwrap().disable_spawns(world) self.data.write().unwrap().disable_spawns(world);
} }
pub fn set_leave_location( pub fn set_leave_location(
@ -996,37 +996,35 @@ impl Map {
Ok(self.data.read().unwrap().leave_markers()) Ok(self.data.read().unwrap().leave_markers())
} }
pub fn disable(&self, world: &mut World) -> Result<()> { pub fn disable(&self, world: &mut World) {
let data = self.data.read().unwrap(); let data = self.data.read().unwrap();
// clear tiles // clear tiles
for chunk in data.chunk_handles.values() { for chunk in data.chunk_handles.values() {
world.remove_entity(*chunk)?; world.remove_entity(*chunk);
} }
// clear entities // clear entities
for entity in data.entities.values() { for entity in data.entities.values() {
world.remove_entity(*entity)?; world.remove_entity(*entity);
} }
// clear spawns // clear spawns
for (spawn, _) in data.spawn_locations.values() { for (spawn, _) in data.spawn_locations.values() {
world.remove_entity(*spawn)?; world.remove_entity(*spawn);
} }
// clear exits // clear exits
for leave in data.leave_locations.values() { for leave in data.leave_locations.values() {
world.remove_entity(*leave)?; world.remove_entity(*leave);
} }
// clear npc spawns // clear npc spawns
for (_, marker) in data.npc_spawn_areas.iter() { for (_, marker) in data.npc_spawn_areas.iter() {
if let Some(marker) = marker { if let Some(marker) = marker {
marker.remove(world)?; marker.remove(world);
} }
} }
Ok(())
} }
} }

View file

@ -193,11 +193,9 @@ impl AlterEntities for HashMap<Coordinate, (Entity, Vector3<f32>)> {
} }
impl SpawnMarker { impl SpawnMarker {
pub fn remove(&self, world: &mut World) -> Result<()> { pub fn remove(&self, world: &mut World) {
world.remove_entity(self.flag)?; world.remove_entity(self.flag);
world.remove_entity(self.area)?; world.remove_entity(self.area);
Ok(())
} }
} }
@ -590,16 +588,14 @@ impl MapData {
Ok(()) Ok(())
} }
pub fn disable_spawns(&mut self, world: &mut World) -> Result<()> { pub fn disable_spawns(&mut self, world: &mut World) {
if self.show_spawn_locations { if self.show_spawn_locations {
self.show_spawn_locations = false; self.show_spawn_locations = false;
for (spawn_entity, _) in self.spawn_locations.values() { for (spawn_entity, _) in self.spawn_locations.values() {
world.remove_entity(*spawn_entity)?; world.remove_entity(*spawn_entity);
} }
} }
Ok(())
} }
pub fn spawn_locations(&self) -> Vec<Vector3<f32>> { pub fn spawn_locations(&self) -> Vec<Vector3<f32>> {
@ -673,7 +669,7 @@ impl MapData {
if self.show_npc_spawns { if self.show_npc_spawns {
// marker.add(scene)?; // marker.add(scene)?;
} else { } else {
marker.remove(world)?; marker.remove(world);
} }
} }
} }
@ -711,7 +707,7 @@ impl MapData {
if self.show_npc_spawns { if self.show_npc_spawns {
// marker.add(scene)?; // marker.add(scene)?;
} else { } else {
world.remove_entity(marker)?; world.remove_entity(marker);
} }
} }
} }
@ -789,7 +785,7 @@ impl MapData {
async_db.add(move |sql| sql.remove_npc_spawn((coordinate.x, coordinate.y)))?; async_db.add(move |sql| sql.remove_npc_spawn((coordinate.x, coordinate.y)))?;
if let Some(marker) = marker { if let Some(marker) = marker {
marker.remove(world)?; marker.remove(world);
} }
} }
@ -858,7 +854,7 @@ impl MapData {
async_db.add(move |sql| sql.remove_boss_spawn((coordinate.x, coordinate.y)))?; async_db.add(move |sql| sql.remove_boss_spawn((coordinate.x, coordinate.y)))?;
if let Some(marker) = marker { if let Some(marker) = marker {
world.remove_entity(marker)?; world.remove_entity(marker);
} }
} }
@ -929,7 +925,7 @@ impl MapData {
sql.remove_entity(table_name, (coordinate.x, coordinate.y)) sql.remove_entity(table_name, (coordinate.x, coordinate.y))
})?; })?;
world.remove_entity(entity)?; world.remove_entity(entity);
return Ok(()); return Ok(());
} }

View file

@ -362,7 +362,7 @@ impl SaveGame {
pub fn to_entity_object<A: Ability + 'static>( pub fn to_entity_object<A: Ability + 'static>(
self, self,
world: &mut World, world: &mut World,
) -> Result<(Entity, String)> { ) -> Result<(EntityObject, String)> {
let mut entity_object = AssetHandler::create(world).empty_entity(); let mut entity_object = AssetHandler::create(world).empty_entity();
entity_object.insert_component(Draw::new(Vec::new())); entity_object.insert_component(Draw::new(Vec::new()));
@ -397,6 +397,6 @@ impl SaveGame {
entity_object.insert_component(statistics); entity_object.insert_component(statistics);
entity_object.insert_component(current_status); entity_object.insert_component(current_status);
Ok((world.add_entity(entity_object)?, self.general.name)) Ok((entity_object, self.general.name))
} }
} }

View file

@ -21,7 +21,7 @@ use super::{
}; };
pub trait Ability: Send + Sync + Clone + Default { pub trait Ability: Send + Sync + Clone + Default {
fn create(context: &Context, asset_path: impl Into<AssetPath>) -> Result<Self>; fn create(world: &mut World, asset_path: impl Into<AssetPath>) -> Result<Self>;
fn name(&self) -> &str; fn name(&self) -> &str;
fn icon_path(&self) -> &AssetPath; fn icon_path(&self) -> &AssetPath;

View file

@ -53,7 +53,7 @@ pub struct ItemSystem<A: Ability> {
impl<A: Ability> ItemSystem<A> { impl<A: Ability> ItemSystem<A> {
pub fn new( pub fn new(
context: &Context, world: &mut World,
item_settings: &ItemSettings, item_settings: &ItemSettings,
ability_settings: &AbilitySettings, ability_settings: &AbilitySettings,
attribute_settings: &AttributeSettings, attribute_settings: &AttributeSettings,
@ -64,9 +64,11 @@ impl<A: Ability> ItemSystem<A> {
let abilities = search_dir_recursively(&ability_directory.full_path(), ".abil")? let abilities = search_dir_recursively(&ability_directory.full_path(), ".abil")?
.into_iter() .into_iter()
.map(|path| A::create(context, path)) .map(|path| A::create(world, path))
.collect::<Result<Vec<A>>>()?; .collect::<Result<Vec<A>>>()?;
let context = world.resources.get::<Context>();
let ( let (
item_icon_combinations, item_icon_combinations,
ability_icon_combinations, ability_icon_combinations,