Skip to content

Commit

Permalink
unfollow when moving camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Aug 3, 2023
1 parent 05b396a commit 419fef8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
19 changes: 1 addition & 18 deletions native_app/src/game_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl State {
self.all_audio
.update(&self.goria.read().unwrap(), &mut self.uiw, &mut ctx.audio);

self.manage_entity_follow();
FollowEntity::update_camera(self);
self.camera.update(ctx);
}

Expand Down Expand Up @@ -288,23 +288,6 @@ impl State {
ctx.audio.set_settings(settings);
}

fn manage_entity_follow(&mut self) {
if self
.uiw
.read::<InputMap>()
.just_act
.contains(&InputAction::Close)
{
self.uiw.write::<FollowEntity>().0.take();
}

if let Some(e) = self.uiw.read::<FollowEntity>().0 {
if let Some(pos) = self.goria.read().unwrap().pos_any(e) {
self.camera.follow(pos);
}
}
}

fn manage_io(&mut self, ctx: &mut Context) {
let goria = self.goria.read().unwrap();
let map = goria.map();
Expand Down
27 changes: 26 additions & 1 deletion native_app/src/gui/follow.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::game_loop::State;
use crate::inputmap::{InputAction, InputMap};
use egregoria::AnyEntity;
use egui::Ui;

Expand All @@ -7,7 +9,7 @@ use egui::Ui;
pub struct FollowEntity(pub(crate) Option<AnyEntity>);

impl FollowEntity {
pub fn update(&mut self, ui: &mut Ui, entity: AnyEntity) {
pub fn update_ui(&mut self, ui: &mut Ui, entity: AnyEntity) {
if self.0.is_none() {
if ui.small_button("Follow").clicked() {
self.0.replace(entity);
Expand All @@ -19,4 +21,27 @@ impl FollowEntity {
self.0.take();
}
}

pub fn update_camera(state: &mut State) {

Check failure on line 25 in native_app/src/gui/follow.rs

View workflow job for this annotation

GitHub Actions / build

crate-private type `game_loop::State` in public interface
let just = &state.uiw.read::<InputMap>().just_act;
if [
InputAction::Close,
InputAction::CameraMove,
InputAction::GoForward,
InputAction::GoBackward,
InputAction::GoLeft,
InputAction::GoRight,
]
.iter()
.any(|x| just.contains(x))
{
state.uiw.write::<FollowEntity>().0.take();
}

if let Some(e) = state.uiw.read::<FollowEntity>().0 {
if let Some(pos) = state.goria.read().unwrap().pos_any(e) {
state.camera.follow(pos);
}
}
}
}
2 changes: 1 addition & 1 deletion native_app/src/gui/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl InspectRenderer {

{
let mut follow = uiworld.write::<FollowEntity>();
follow.update(ui, entity);
follow.update_ui(ui, entity);
}

if let Ok(soul) = SoulID::try_from(entity) {
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/gui/windows/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub(crate) struct Settings {
impl Default for Settings {
fn default() -> Self {
Self {
camera_border_move: true,
camera_border_move: false,
camera_smooth: true,
music_volume_percent: 100.0,
effects_volume_percent: 100.0,
Expand Down

0 comments on commit 419fef8

Please sign in to comment.