Rename controller main, alt to primary, secondary

This commit is contained in:
timokoesters
2019-08-31 00:13:45 +02:00
parent a95893e43b
commit 15978d216b
6 changed files with 24 additions and 24 deletions

View File

@ -4,11 +4,11 @@ use vek::*;
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Controller { pub struct Controller {
pub primary: bool,
pub secondary: bool,
pub move_dir: Vec2<f32>, pub move_dir: Vec2<f32>,
pub look_dir: Vec3<f32>, pub look_dir: Vec3<f32>,
pub jump: bool, pub jump: bool,
pub main: bool,
pub alt: bool,
pub roll: bool, pub roll: bool,
pub glide: bool, pub glide: bool,
pub respawn: bool, pub respawn: bool,

View File

@ -87,9 +87,9 @@ impl<'a> System<'a> for Sys {
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5; Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5;
if rand::random::<f32>() < 0.05 { if rand::random::<f32>() < 0.05 {
controller.main = true; controller.primary = true;
} else { } else {
controller.main = false; controller.primary = false;
} }
} else if dist < SIGHT_DIST { } else if dist < SIGHT_DIST {
controller.move_dir = controller.move_dir =

View File

@ -97,7 +97,7 @@ impl<'a> System<'a> for Sys {
} }
// Wield // Wield
if controller.main if controller.primary
&& character.action == Idle && character.action == Idle
&& (character.movement == Stand || character.movement == Run) && (character.movement == Stand || character.movement == Run)
{ {
@ -109,7 +109,7 @@ impl<'a> System<'a> for Sys {
match stats.equipment.main { match stats.equipment.main {
Some(Item::Tool { .. }) => { Some(Item::Tool { .. }) => {
// Attack // Attack
if controller.main if controller.primary
&& (character.movement == Stand && (character.movement == Stand
|| character.movement == Run || character.movement == Run
|| character.movement == Jump) || character.movement == Jump)
@ -126,25 +126,25 @@ impl<'a> System<'a> for Sys {
} }
// Block // Block
if controller.alt if controller.secondary
&& (character.movement == Stand || character.movement == Run) && (character.movement == Stand || character.movement == Run)
&& (character.action == Idle || character.action.is_wield()) && (character.action == Idle || character.action.is_wield())
{ {
character.action = Block { character.action = Block {
time_left: Duration::from_secs(5), time_left: Duration::from_secs(5),
}; };
} else if !controller.alt && character.action.is_block() { } else if !controller.secondary && character.action.is_block() {
character.action = Idle; character.action = Idle;
} }
} }
Some(Item::Debug(item::Debug::Boost)) => { Some(Item::Debug(item::Debug::Boost)) => {
if controller.main { if controller.primary {
local_emitter.emit(LocalEvent::Boost { local_emitter.emit(LocalEvent::Boost {
entity, entity,
vel: controller.look_dir * 7.0, vel: controller.look_dir * 7.0,
}); });
} }
if controller.alt { if controller.secondary {
// Go upward // Go upward
local_emitter.emit(LocalEvent::Boost { local_emitter.emit(LocalEvent::Boost {
entity, entity,

View File

@ -129,7 +129,7 @@ impl PlayState for SessionState {
Event::Close => { Event::Close => {
return PlayStateResult::Shutdown; return PlayStateResult::Shutdown;
} }
Event::InputUpdate(GameInput::Main, state) => { Event::InputUpdate(GameInput::Primary, state) => {
// Check the existence of CanBuild component. If it's here, use LMB to // Check the existence of CanBuild component. If it's here, use LMB to
// place blocks, if not, use it to attack // place blocks, if not, use it to attack
let mut client = self.client.borrow_mut(); let mut client = self.client.borrow_mut();
@ -152,11 +152,11 @@ impl PlayState for SessionState {
client.place_block(pos, self.selected_block); client.place_block(pos, self.selected_block);
} }
} else { } else {
self.controller.main = state self.controller.primary = state
} }
} }
Event::InputUpdate(GameInput::Alt, state) => { Event::InputUpdate(GameInput::Secondary, state) => {
let mut client = self.client.borrow_mut(); let mut client = self.client.borrow_mut();
if state if state
&& client && client
@ -176,7 +176,7 @@ impl PlayState for SessionState {
client.remove_block(pos); client.remove_block(pos);
} }
} else { } else {
self.controller.alt = state; self.controller.secondary = state;
} }
} }
Event::InputUpdate(GameInput::Roll, state) => { Event::InputUpdate(GameInput::Roll, state) => {

View File

@ -13,8 +13,8 @@ use std::{fs, io::prelude::*, path::PathBuf};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct ControlSettings { pub struct ControlSettings {
pub main: KeyMouse, pub primary: KeyMouse,
pub alt: KeyMouse, pub secondary: KeyMouse,
pub toggle_cursor: KeyMouse, pub toggle_cursor: KeyMouse,
pub escape: KeyMouse, pub escape: KeyMouse,
pub enter: KeyMouse, pub enter: KeyMouse,
@ -46,8 +46,8 @@ pub struct ControlSettings {
impl Default for ControlSettings { impl Default for ControlSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
main: KeyMouse::Mouse(MouseButton::Left), primary: KeyMouse::Mouse(MouseButton::Left),
alt: KeyMouse::Mouse(MouseButton::Right), secondary: KeyMouse::Mouse(MouseButton::Right),
toggle_cursor: KeyMouse::Key(VirtualKeyCode::Tab), toggle_cursor: KeyMouse::Key(VirtualKeyCode::Tab),
escape: KeyMouse::Key(VirtualKeyCode::Escape), escape: KeyMouse::Key(VirtualKeyCode::Escape),
enter: KeyMouse::Key(VirtualKeyCode::Return), enter: KeyMouse::Key(VirtualKeyCode::Return),

View File

@ -11,8 +11,8 @@ use vek::*;
/// Represents a key that the game recognises after keyboard mapping. /// Represents a key that the game recognises after keyboard mapping.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum GameInput { pub enum GameInput {
Main, Primary,
Alt, Secondary,
ToggleCursor, ToggleCursor,
MoveForward, MoveForward,
MoveBack, MoveBack,
@ -109,12 +109,12 @@ impl Window {
.map_err(|err| Error::BackendError(Box::new(err)))?; .map_err(|err| Error::BackendError(Box::new(err)))?;
let mut map: HashMap<_, Vec<_>> = HashMap::new(); let mut map: HashMap<_, Vec<_>> = HashMap::new();
map.entry(settings.controls.main) map.entry(settings.controls.primary)
.or_default() .or_default()
.push(GameInput::Main); .push(GameInput::Primary);
map.entry(settings.controls.alt) map.entry(settings.controls.secondary)
.or_default() .or_default()
.push(GameInput::Alt); .push(GameInput::Secondary);
map.entry(settings.controls.toggle_cursor) map.entry(settings.controls.toggle_cursor)
.or_default() .or_default()
.push(GameInput::ToggleCursor); .push(GameInput::ToggleCursor);