Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
dagit committed Dec 3, 2023
2 parents 55ded24 + 29b3d8f commit 0895372
Show file tree
Hide file tree
Showing 9 changed files with 1,846 additions and 1,557 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/onpush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./annelid-x86_64.AppImage/annelid.AppImage
asset_name: annelid-${{ steps.tag_date.outputs.TAG_NAME }}-x86_64-linux.AppImage
asset_name: Annelid-${{ steps.tag_date.outputs.TAG_NAME }}-x86_64-linux.AppImage
asset_content_type: application/octet-stream
- uses: actions/upload-release-asset@v1
env:
Expand Down Expand Up @@ -220,5 +220,5 @@ jobs:
with:
upload_url: '${{ steps.create_release.outputs.upload_url }}'
asset_path: ./annelid-x86_64.win/annelid.exe
asset_name: annelid-${{ steps.tag_date.outputs.TAG_NAME }}-x86_64-windows.exe
asset_name: Annelid-${{ steps.tag_date.outputs.TAG_NAME }}-x86_64-windows.exe
asset_content_type: application/octet-stream
102 changes: 102 additions & 0 deletions src/config/app_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use clap::Parser;
use serde_derive::{Deserialize, Serialize};

use crate::hotkey::*;

#[derive(Deserialize, Serialize, Parser, Debug, Clone)]
#[clap(author, version, about, long_about = None)]
pub struct AppConfig {
#[clap(name = "load-splits", short = 's', long, value_parser)]
pub recent_splits: Option<String>,
#[clap(name = "load-layout", short = 'l', long, value_parser)]
pub recent_layout: Option<String>,
#[clap(name = "load-autosplitter", short = 'a', long, value_parser)]
pub recent_autosplitter: Option<String>,
#[clap(name = "use-autosplitter", long, action)]
pub use_autosplitter: Option<YesOrNo>,
#[clap(name = "polling-rate", long, short = 'p', value_parser)]
pub polling_rate: Option<f32>,
#[clap(name = "frame-rate", long, short = 'f', value_parser)]
pub frame_rate: Option<f32>,
#[clap(name = "reset-timer-on-game-reset", long, value_parser)]
pub reset_timer_on_game_reset: Option<YesOrNo>,
#[clap(name = "reset-game-on-timer-reset", long, value_parser)]
pub reset_game_on_timer_reset: Option<YesOrNo>,
#[clap(name = "global-hotkeys", long, short = 'g', value_parser)]
pub global_hotkeys: Option<YesOrNo>,
#[clap(skip)]
pub hot_key_start: Option<HotKey>,
#[clap(skip)]
pub hot_key_reset: Option<HotKey>,
#[clap(skip)]
pub hot_key_undo: Option<HotKey>,
#[clap(skip)]
pub hot_key_skip: Option<HotKey>,
#[clap(skip)]
pub hot_key_pause: Option<HotKey>,
#[clap(skip)]
pub hot_key_comparison_next: Option<HotKey>,
#[clap(skip)]
pub hot_key_comparison_prev: Option<HotKey>,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug, Serialize, Deserialize, Default, PartialEq, Eq)]
pub enum YesOrNo {
#[default]
Yes,
No,
}

pub const DEFAULT_FRAME_RATE: f32 = 30.0;
pub const DEFAULT_POLLING_RATE: f32 = 20.0;

impl AppConfig {
fn new() -> Self {
let modifiers = ::egui::Modifiers::default();
AppConfig {
recent_splits: None,
recent_layout: None,
recent_autosplitter: None,
hot_key_start: Some(HotKey {
key: egui::Key::Num1,
modifiers,
}),
hot_key_reset: Some(HotKey {
key: egui::Key::Num3,
modifiers,
}),
hot_key_undo: Some(HotKey {
key: egui::Key::Num8,
modifiers,
}),
hot_key_skip: Some(HotKey {
key: egui::Key::Num2,
modifiers,
}),
hot_key_pause: Some(HotKey {
key: egui::Key::Num5,
modifiers,
}),
hot_key_comparison_next: Some(HotKey {
key: egui::Key::Num6,
modifiers,
}),
hot_key_comparison_prev: Some(HotKey {
key: egui::Key::Num4,
modifiers,
}),
use_autosplitter: Some(YesOrNo::Yes),
frame_rate: Some(DEFAULT_FRAME_RATE),
polling_rate: Some(DEFAULT_POLLING_RATE),
reset_timer_on_game_reset: Some(YesOrNo::No),
reset_game_on_timer_reset: Some(YesOrNo::No),
global_hotkeys: Some(YesOrNo::Yes),
}
}
}

impl Default for AppConfig {
fn default() -> Self {
AppConfig::new()
}
}
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod app_config;
129 changes: 129 additions & 0 deletions src/hotkey.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
use serde_derive::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Copy, Clone)]
pub struct HotKey {
pub key: ::egui::Key,
pub modifiers: ::egui::Modifiers,
}

impl HotKey {
pub fn to_livesplit_hotkey(self) -> livesplit_hotkey::Hotkey {
to_livesplit_keycode(&self.key).with_modifiers(to_livesplit_modifiers(&self.modifiers))
}
}

pub fn to_livesplit_keycode(key: &::egui::Key) -> livesplit_hotkey::KeyCode {
use livesplit_hotkey::KeyCode::*;

match key {
egui::Key::ArrowDown => ArrowDown,
egui::Key::ArrowLeft => ArrowLeft,
egui::Key::ArrowRight => ArrowRight,
egui::Key::ArrowUp => ArrowUp,
egui::Key::Escape => Escape,
egui::Key::Tab => Tab,
egui::Key::Backspace => Backspace,
egui::Key::Enter => Enter,
egui::Key::Space => Space,
egui::Key::Insert => Insert,
egui::Key::Delete => Delete,
egui::Key::Home => Home,
egui::Key::End => End,
egui::Key::PageUp => PageUp,
egui::Key::PageDown => PageDown,
egui::Key::Num0 => Numpad0,
egui::Key::Num1 => Numpad1,
egui::Key::Num2 => Numpad2,
egui::Key::Num3 => Numpad3,
egui::Key::Num4 => Numpad4,
egui::Key::Num5 => Numpad5,
egui::Key::Num6 => Numpad6,
egui::Key::Num7 => Numpad7,
egui::Key::Num8 => Numpad8,
egui::Key::Num9 => Numpad9,
egui::Key::A => KeyA,
egui::Key::B => KeyB,
egui::Key::C => KeyC,
egui::Key::D => KeyD,
egui::Key::E => KeyE,
egui::Key::F => KeyF,
egui::Key::G => KeyG,
egui::Key::H => KeyH,
egui::Key::I => KeyI,
egui::Key::J => KeyJ,
egui::Key::K => KeyK,
egui::Key::L => KeyL,
egui::Key::M => KeyM,
egui::Key::N => KeyN,
egui::Key::O => KeyO,
egui::Key::P => KeyP,
egui::Key::Q => KeyQ,
egui::Key::R => KeyR,
egui::Key::S => KeyS,
egui::Key::T => KeyT,
egui::Key::U => KeyU,
egui::Key::V => KeyV,
egui::Key::W => KeyW,
egui::Key::X => KeyX,
egui::Key::Y => KeyY,
egui::Key::Z => KeyZ,
egui::Key::F1 => F1,
egui::Key::F2 => F2,
egui::Key::F3 => F3,
egui::Key::F4 => F4,
egui::Key::F5 => F5,
egui::Key::F6 => F6,
egui::Key::F7 => F7,
egui::Key::F8 => F8,
egui::Key::F9 => F9,
egui::Key::F10 => F10,
egui::Key::F11 => F11,
egui::Key::F12 => F12,
egui::Key::F13 => F13,
egui::Key::F14 => F14,
egui::Key::F15 => F15,
egui::Key::F16 => F16,
egui::Key::F17 => F17,
egui::Key::F18 => F18,
egui::Key::F19 => F19,
egui::Key::F20 => F20,
egui::Key::Minus => Minus,
egui::Key::PlusEquals => Equal,
}
}

pub fn to_livesplit_keycode_alternative(key: &::egui::Key) -> Option<livesplit_hotkey::KeyCode> {
use livesplit_hotkey::KeyCode::*;

match key {
egui::Key::Num0 => Some(Digit0),
egui::Key::Num1 => Some(Digit1),
egui::Key::Num2 => Some(Digit2),
egui::Key::Num3 => Some(Digit3),
egui::Key::Num4 => Some(Digit4),
egui::Key::Num5 => Some(Digit5),
egui::Key::Num6 => Some(Digit6),
egui::Key::Num7 => Some(Digit7),
egui::Key::Num8 => Some(Digit8),
egui::Key::Num9 => Some(Digit9),
_ => None,
}
}

pub fn to_livesplit_modifiers(modifiers: &::egui::Modifiers) -> livesplit_hotkey::Modifiers {
use livesplit_hotkey::Modifiers;
let mut mods = Modifiers::empty();
if modifiers.shift {
mods.insert(Modifiers::SHIFT)
};
if modifiers.ctrl {
mods.insert(Modifiers::CONTROL)
};
if modifiers.alt {
mods.insert(Modifiers::ALT)
};
if modifiers.mac_cmd || modifiers.command {
mods.insert(Modifiers::META)
};
mods
}
Loading

0 comments on commit 0895372

Please sign in to comment.