mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Code quality
This commit is contained in:
parent
8da59bb8e8
commit
fe186fb44d
@ -931,6 +931,11 @@ impl Client {
|
|||||||
|
|
||||||
pub fn is_dead(&self) -> bool { self.current::<comp::Health>().map_or(false, |h| h.is_dead) }
|
pub fn is_dead(&self) -> bool { self.current::<comp::Health>().map_or(false, |h| h.is_dead) }
|
||||||
|
|
||||||
|
pub fn is_gliding(&self) -> bool {
|
||||||
|
self.current::<comp::CharacterState>()
|
||||||
|
.map_or(false, |cs| matches!(cs, comp::CharacterState::Glide(_)))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn split_swap_slots(&mut self, a: comp::slot::Slot, b: comp::slot::Slot) {
|
pub fn split_swap_slots(&mut self, a: comp::slot::Slot, b: comp::slot::Slot) {
|
||||||
match (a, b) {
|
match (a, b) {
|
||||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => self.control_action(
|
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => self.control_action(
|
||||||
@ -1234,7 +1239,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_glide(&mut self) {
|
pub fn toggle_glide(&mut self) {
|
||||||
let is_gliding = self
|
let using_glider = self
|
||||||
.state
|
.state
|
||||||
.ecs()
|
.ecs()
|
||||||
.read_storage::<comp::CharacterState>()
|
.read_storage::<comp::CharacterState>()
|
||||||
@ -1246,7 +1251,7 @@ impl Client {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
match is_gliding {
|
match using_glider {
|
||||||
Some(true) => self.control_action(ControlAction::Unwield),
|
Some(true) => self.control_action(ControlAction::Unwield),
|
||||||
Some(false) => self.control_action(ControlAction::GlideWield),
|
Some(false) => self.control_action(ControlAction::GlideWield),
|
||||||
None => warn!("Can't toggle glide, client entity doesn't have a `CharacterState`"),
|
None => warn!("Can't toggle glide, client entity doesn't have a `CharacterState`"),
|
||||||
|
@ -686,20 +686,8 @@ impl PlayState for SessionState {
|
|||||||
|b| hud.auto_walk(b),
|
|b| hud.auto_walk(b),
|
||||||
);
|
);
|
||||||
|
|
||||||
if self
|
self.key_state.auto_walk =
|
||||||
.client
|
self.auto_walk && !self.client.borrow().is_gliding();
|
||||||
.borrow()
|
|
||||||
.state()
|
|
||||||
.ecs()
|
|
||||||
.read_storage::<comp::CharacterState>()
|
|
||||||
.get(self.client.borrow().entity())
|
|
||||||
.filter(|cs| matches!(cs, comp::CharacterState::Glide(_)))
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
self.key_state.auto_walk = false
|
|
||||||
} else {
|
|
||||||
self.key_state.auto_walk = self.auto_walk
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
GameInput::CameraClamp => {
|
GameInput::CameraClamp => {
|
||||||
let hud = &mut self.hud;
|
let hud = &mut self.hud;
|
||||||
@ -764,30 +752,24 @@ impl PlayState for SessionState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(dir) = self
|
// If auto-gliding, point camera into the wind
|
||||||
.auto_walk
|
if let Some(dir) = (self.auto_walk && self.client.borrow().is_gliding())
|
||||||
.then_some((
|
.then_some(self.client.borrow())
|
||||||
self.client.borrow().state().ecs(),
|
.and_then(|client| {
|
||||||
self.client.borrow().entity(),
|
let ecs = client.state().ecs();
|
||||||
))
|
let entity = client.entity();
|
||||||
.filter(|(ecs, entity)| {
|
let fluid = ecs
|
||||||
ecs.read_storage::<comp::CharacterState>()
|
.read_storage::<comp::PhysicsState>()
|
||||||
.get(*entity)
|
|
||||||
.map_or(false, |cs| matches!(cs, comp::CharacterState::Glide(_)))
|
|
||||||
})
|
|
||||||
.and_then(|(ecs, entity)| {
|
|
||||||
ecs.read_storage::<comp::PhysicsState>()
|
|
||||||
.get(entity)?
|
.get(entity)?
|
||||||
.in_fluid
|
.in_fluid?;
|
||||||
.and_then(|fluid| {
|
let wind = ecs
|
||||||
Dir::from_unnormalized(
|
.read_storage::<comp::Vel>()
|
||||||
-fluid
|
.get(entity)
|
||||||
.relative_flow(ecs.read_storage::<comp::Vel>().get(entity)?)
|
.map(|vel| -fluid.relative_flow(vel).0)?;
|
||||||
.0,
|
Dir::from_unnormalized(wind)
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
|
self.key_state.auto_walk = false;
|
||||||
self.inputs.look_dir = dir;
|
self.inputs.look_dir = dir;
|
||||||
} else if !self.free_look {
|
} else if !self.free_look {
|
||||||
self.walk_forward_dir = self.scene.camera().forward_xy();
|
self.walk_forward_dir = self.scene.camera().forward_xy();
|
||||||
|
Loading…
Reference in New Issue
Block a user