Skip to content

Commit

Permalink
Global entity tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Jan 13, 2024
1 parent 98942ec commit 1963ca6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
- Add Delete Button on Inspector Panel by @Froggy618157725 in [#11](https://github.com/cohaereo/alkahest/pull/11)
- Show Havok shapes for 80809121 (Push Surfaces) by @DeltaDesigns in [#9](https://github.com/cohaereo/alkahest/pull/9)
- Add Global Utility Objects by @Froggy618167725 in [#12](https://github.com/cohaereo/alkahest/pull/12)
- Lazy entity updating by @cohaereo
- Global entity tag by @cohaereo

### Changed

Expand Down
12 changes: 11 additions & 1 deletion src/ecs/component_panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use super::{
StaticInstances, Visible,
},
resolve_entity_icon, resolve_entity_name,
tags::Tags,
tags::{insert_tag, remove_tag, EntityTag, Tags},
transform::{OriginalTransform, Transform},
Scene,
};
Expand Down Expand Up @@ -109,8 +109,10 @@ pub fn show_inspector_panel(
}

let mut global = e.get::<&Global>().map_or(false, |g| g.0);
let mut global_changed = false;
if e.has::<Mutable>() {
if ui.checkbox(&mut global, "Show in all Maps").clicked() {
global_changed = true;
if let Some(mut g) = e.get::<&mut Global>() {
g.0 = global;
} else {
Expand All @@ -120,6 +122,14 @@ pub fn show_inspector_panel(
ui.separator();
}
show_inspector_components(ui, e, resources);

if global_changed {
if global {
insert_tag(scene, ent, EntityTag::Global);
} else {
remove_tag(scene, ent, EntityTag::Global);
}
}
}

fn show_inspector_components(ui: &mut egui::Ui, e: EntityRef<'_>, resources: &Resources) {
Expand Down
26 changes: 24 additions & 2 deletions src/ecs/tags.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use std::fmt::Display;

use egui::Color32;
use hecs::Entity;
use nohash_hasher::IntSet;

use crate::{overlays::UiExt, util::text::name_to_color};
use crate::{icons::ICON_WEB, overlays::UiExt, util::text::name_to_color};

use super::Scene;

#[derive(strum::Display, strum::EnumIter, Hash, PartialEq, Eq)]
#[derive(strum::EnumIter, Hash, PartialEq, Eq)]
pub enum EntityTag {
Activity,
Ambient,
Global,
Havok,
Utility,
User,
Expand All @@ -26,6 +29,19 @@ impl EntityTag {
}
}

impl Display for EntityTag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EntityTag::Activity => write!(f, "Activity"),
EntityTag::Ambient => write!(f, "Ambient"),
EntityTag::Global => write!(f, "{} Global", ICON_WEB),
EntityTag::Havok => write!(f, "Havok"),
EntityTag::Utility => write!(f, "Utility"),
EntityTag::User => write!(f, "User"),
}
}
}

#[derive(Default)]
pub struct Tags(pub IntSet<EntityTag>);

Expand Down Expand Up @@ -57,3 +73,9 @@ pub fn insert_tag(scene: &mut Scene, ent: Entity, tag: EntityTag) {

scene.insert_one(ent, Tags::from_iter([tag])).ok();
}

pub fn remove_tag(scene: &mut Scene, ent: Entity, tag: EntityTag) {
if let Ok(Some(mut e)) = scene.entity(ent).map(|e| e.get::<&mut Tags>()) {
e.0.remove(&tag);
}
}

0 comments on commit 1963ca6

Please sign in to comment.