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
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
6 changed files with 24 additions and 24 deletions

View File

@ -4,11 +4,11 @@ use vek::*;
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Controller {
pub primary: bool,
pub secondary: bool,
pub move_dir: Vec2<f32>,
pub look_dir: Vec3<f32>,
pub jump: bool,
pub main: bool,
pub alt: bool,
pub roll: bool,
pub glide: 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;
if rand::random::<f32>() < 0.05 {
controller.main = true;
controller.primary = true;
} else {
controller.main = false;
controller.primary = false;
}
} else if dist < SIGHT_DIST {
controller.move_dir =

View File

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

View File

@ -129,7 +129,7 @@ impl PlayState for SessionState {
Event::Close => {
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
// place blocks, if not, use it to attack
let mut client = self.client.borrow_mut();
@ -152,11 +152,11 @@ impl PlayState for SessionState {
client.place_block(pos, self.selected_block);
}
} 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();
if state
&& client
@ -176,7 +176,7 @@ impl PlayState for SessionState {
client.remove_block(pos);
}
} else {
self.controller.alt = state;
self.controller.secondary = state;
}
}
Event::InputUpdate(GameInput::Roll, state) => {

View File

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

View File

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