implement command suitmod (same as armodel but always visible)

This commit is contained in:
yuni 2024-11-23 05:31:09 +01:00
parent 6e1b8d4502
commit 2a48a718b6
2 changed files with 38 additions and 39 deletions

View file

@ -128,6 +128,7 @@ struct ParserState {
light_brightness: f32, light_brightness: f32,
light_color: Option<Color>, light_color: Option<Color>,
ar_models: Vec<String>, ar_models: Vec<String>,
suit_mod_models: Vec<String>,
show_only_in_map_at_distance: Option<(f64, String)>, show_only_in_map_at_distance: Option<(f64, String)>,
} }
impl Default for ParserState { impl Default for ParserState {
@ -191,6 +192,7 @@ impl Default for ParserState {
light_brightness: 0.0, light_brightness: 0.0,
light_color: None, light_color: None,
ar_models: vec![], ar_models: vec![],
suit_mod_models: vec![],
show_only_in_map_at_distance: None, show_only_in_map_at_distance: None,
} }
} }
@ -699,6 +701,9 @@ pub fn load_defs(mut ew_spawn: EventWriter<SpawnEvent>) {
["armodel", asset_name] => { ["armodel", asset_name] => {
state.ar_models.push(asset_name.to_string()); state.ar_models.push(asset_name.to_string());
} }
["suitmod", asset_name] => {
state.suit_mod_models.push(asset_name.to_string());
}
["targeted", "yes"] => { ["targeted", "yes"] => {
state.is_targeted_on_startup = true; state.is_targeted_on_startup = true;
} }
@ -1599,6 +1604,7 @@ fn spawn_entities(
hud::AugmentedRealityOverlay { hud::AugmentedRealityOverlay {
owner: actor_entity, owner: actor_entity,
scale: 1.0, scale: 1.0,
always_visible: false,
}, },
world::DespawnOnPlayerDeath, world::DespawnOnPlayerDeath,
SpatialBundle { SpatialBundle {
@ -1610,6 +1616,21 @@ fn spawn_entities(
load_asset(ar_asset_name.as_str(), &mut entitycmd, &*asset_server); load_asset(ar_asset_name.as_str(), &mut entitycmd, &*asset_server);
} }
for ar_asset_name in &state.suit_mod_models {
let mut entitycmd = commands.spawn((
hud::AugmentedRealityOverlay {
owner: actor_entity,
scale: 1.0,
always_visible: true,
},
world::DespawnOnPlayerDeath,
SpatialBundle {
..default()
},
));
load_asset(ar_asset_name.as_str(), &mut entitycmd, &*asset_server);
}
if state.is_point_of_interest || state.is_moon || state.is_planet { if state.is_point_of_interest || state.is_moon || state.is_planet {
let mut entitycmd = commands.spawn(( let mut entitycmd = commands.spawn((
hud::PointOfInterestMarker(actor_entity), hud::PointOfInterestMarker(actor_entity),

View file

@ -105,9 +105,6 @@ impl Plugin for HudPlugin {
.before(TransformSystem::TransformPropagate), .before(TransformSystem::TransformPropagate),
), ),
); );
app.insert_resource(AugmentedRealityState {
overlays_visible: false,
});
app.insert_resource(Log { app.insert_resource(Log {
logs: VecDeque::with_capacity(LOG_MAX), logs: VecDeque::with_capacity(LOG_MAX),
needs_rerendering: true, needs_rerendering: true,
@ -180,17 +177,13 @@ enum Gauge {
//Integrity, //Integrity,
} }
#[derive(Resource)]
pub struct AugmentedRealityState {
pub overlays_visible: bool,
}
#[derive(Component)] #[derive(Component)]
pub struct AugmentedRealityOverlayBroadcaster; pub struct AugmentedRealityOverlayBroadcaster;
#[derive(Component)] #[derive(Component)]
pub struct AugmentedRealityOverlay { pub struct AugmentedRealityOverlay {
pub owner: Entity, pub owner: Entity,
pub scale: f32, pub scale: f32,
pub always_visible: bool,
} }
#[derive(Resource)] #[derive(Resource)]
@ -1230,40 +1223,24 @@ fn update_ar_overlays(
Without<AugmentedRealityOverlay>, Without<AugmentedRealityOverlay>,
), ),
>, >,
mut q_overlays: Query<( mut q_overlays: Query<(&mut Transform, &mut Visibility, &AugmentedRealityOverlay)>,
&mut Transform,
&mut Visibility,
&AugmentedRealityOverlay,
)>,
settings: ResMut<Settings>, settings: ResMut<Settings>,
mut state: ResMut<AugmentedRealityState>,
) { ) {
let (need_activate, need_clean, need_update); for (mut trans, mut vis, ar) in &mut q_overlays {
if settings.hud_active { if !ar.always_visible && !settings.hud_active {
need_activate = !state.overlays_visible; *vis = Visibility::Hidden;
need_clean = false; continue;
} else { }
need_activate = false; for (owner_id, owner_trans, owner_vis) in &q_owners {
need_clean = state.overlays_visible; if owner_id == ar.owner {
} *trans = *owner_trans;
need_update = settings.hud_active; if ar.scale != 1.0 {
state.overlays_visible = settings.hud_active; trans.scale *= ar.scale;
if need_update || need_clean || need_activate {
for (mut trans, mut vis, ar) in &mut q_overlays {
for (owner_id, owner_trans, owner_vis) in &q_owners {
if owner_id == ar.owner {
*trans = *owner_trans;
if ar.scale != 1.0 {
trans.scale *= ar.scale;
}
if need_clean {
*vis = Visibility::Hidden;
} else {
*vis = *owner_vis;
}
break;
} }
if ar.always_visible || settings.hud_active {
*vis = *owner_vis;
}
break;
} }
} }
} }
@ -1408,6 +1385,7 @@ fn update_avatar(
hud::AugmentedRealityOverlay { hud::AugmentedRealityOverlay {
owner: player_entity, owner: player_entity,
scale: model_scale, scale: model_scale,
always_visible: false,
}, },
world::DespawnOnPlayerDeath, world::DespawnOnPlayerDeath,
PlayerAvatar, PlayerAvatar,