Compare commits

...
19 Commits
Author SHA1 Message Date
meehl e2c0f2fffc chore: Release rusty-path-of-building version 0.2.14
Release / create-release (push) Successful in 6s
2026-03-14 10:35:33 +01:00
meehl a6be413190 Update CHANGELOG 2026-03-14 10:35:21 +01:00
AiSatan 8034eef8c7 fix removing build directory 2026-03-11 16:48:11 +01:00
meehl 3b0d5295d3 installer: only install release versions
This prevents the installer from trying to download a beta version which
leads to a 404.
2026-03-10 16:07:54 +01:00
meehl ff46a570fc chore: Release rusty-path-of-building version 0.2.13
Release / create-release (push) Successful in 4s
2026-03-09 18:17:47 +01:00
meehl 7db64e337d Update CHANGELOG 2026-03-09 18:17:33 +01:00
meehl 522ab489cd Fix ascendancy flavour text size. 2026-03-09 18:13:58 +01:00
meehl 8217aca6f2 chore: Release rusty-path-of-building version 0.2.12
Release / create-release (push) Successful in 4s
2026-03-09 16:35:19 +01:00
meehl 249116af52 Update CHANGELOG 2026-03-09 16:35:06 +01:00
meehl c47bf48556 Add more fine-grained logging and UI feedback to installer 2026-03-09 16:30:00 +01:00
meehl 1f89e31f30 Set global timeout for ureq requests 2026-03-09 16:30:00 +01:00
AiSatan 913d2127d8 Fix to enable "Save changes" popup 2026-03-09 14:10:30 +01:00
meehl 1c99e9fabc chore: Release rusty-path-of-building version 0.2.11
Release / create-release (push) Successful in 4s
2026-03-05 08:50:53 +01:00
meehl 12fc773958 Update CHANGELOG 2026-03-05 08:50:34 +01:00
meehl ef4f86eac8 Track state and forward events for logical keys.
Using physical key codes leads to unexpected bevahior on different
keyboard layouts. Use logical keys like SimpleGraphic.

Closes #27
2026-03-05 08:30:56 +01:00
Ac5000 966363a859 Added method to InputState to clear pressed keys, mods, and mouse. Call method on window focus loss. 2026-02-28 10:23:56 +01:00
Ac5000 9d33a7704c Added documentation to src/input.rs 2026-02-28 10:23:56 +01:00
Ac5000 3a66f15b49 Added documentation. 2026-02-28 10:23:56 +01:00
meehl 7d02ca098c Use repology to display packaging status 2025-12-17 12:19:40 +01:00
15 changed files with 374 additions and 243 deletions

No files matched your search

+36 -1
View File
@@ -2,6 +2,37 @@
## [Unreleased] - ReleaseDate
## [0.2.14] - 2026-03-14
### Fixed
- Fix deletion of character build directories
- Prevent installer from downloading beta versions
## [0.2.13] - 2026-03-09
### Fixed
- Fix size of ascendancy flavour texts
## [0.2.12] - 2026-03-09
### Changed
- Add better logging and UI feedback for initial install
- Set global timeout for network requests
### Fixed
- Fix confirmation dialog not showing on close with unsaved changes
## [0.2.11] - 2026-03-05
### Fixed
- Clear pressed keys on focus loss to avoid stuck keys
- Use logical keys for input handling to fix unexpected behavior with different keyboard layouts
## [0.2.10] - 2025-12-15
### Added
@@ -143,8 +174,12 @@
- First release
<!-- next-url -->
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.10...HEAD
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.14...HEAD
[0.2.14]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.13...v0.2.14
[0.2.13]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.12...v0.2.13
[0.2.12]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.11...v0.2.12
[0.2.11]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.10...v0.2.11
[0.2.10]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.9...v0.2.10
[0.2.9]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.8...v0.2.9
[0.2.8]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.7...v0.2.8
Generated
+1 -1
View File
@@ -2506,7 +2506,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "rusty-path-of-building"
version = "0.2.10"
version = "0.2.14"
dependencies = [
"ahash",
"anyhow",
+1 -1
View File
@@ -4,7 +4,7 @@ authors = ["meehl"]
description = "Cross-platform runtime for Path of Building"
repository = "https://github.com/meehl/rusty-path-of-building"
license = "MIT"
version = "0.2.10"
version = "0.2.14"
edition = "2024"
publish = false
+1 -9
View File
@@ -12,20 +12,12 @@ rusty-path-of-building [poe1|poe2]
## Installation
### Arch (AUR)
[![Stable version badge](https://img.shields.io/aur/version/rusty-path-of-building)](https://aur.archlinux.org/packages/rusty-path-of-building)
Please check [the Arch Wiki](https://wiki.archlinux.org/title/Arch_User_Repository) on how to install packages from the AUR.
[![Packaging status](https://repology.org/badge/vertical-allrepos/rusty-path-of-building.svg)](https://repology.org/project/rusty-path-of-building/versions)
### Flathub
[![Stable version badge](https://img.shields.io/flathub/v/community.pathofbuilding.PathOfBuilding)](https://flathub.org/en/apps/community.pathofbuilding.PathOfBuilding)
### Nix
[nixpkgs](https://search.nixos.org/packages?type=packages&query=rusty-path-of-building)
### Building from source
`LuaJIT` needs to be installed on your system for the `mlua` crate to compile.
+13 -1
View File
@@ -9,7 +9,8 @@ use crate::{
input::{get_cursor_pos, is_key_down},
lua::{load_module, protected_call, protected_load_module},
paths::{
get_runtime_path, get_script_path, get_user_path, get_work_dir, make_dir, set_work_dir,
get_runtime_path, get_script_path, get_user_path, get_work_dir, make_dir, remove_dir,
set_work_dir,
},
rendering::PoBString,
search_handle::new_search_handle,
@@ -51,6 +52,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> {
globals.set("GetWorkDir", lua.create_function(get_work_dir)?)?;
globals.set("SetWorkDir", lua.create_function(set_work_dir)?)?;
globals.set("MakeDir", lua.create_function(make_dir)?)?;
globals.set("RemoveDir", lua.create_function(remove_dir)?)?;
// console
globals.set("ConPrintf", lua.create_function(console_printf)?)?;
@@ -61,6 +63,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> {
// general
globals.set("GetTime", lua.create_function(get_time)?)?;
globals.set("StripEscapes", lua.create_function(strip_escapes)?)?;
globals.set("Exit", lua.create_function(exit)?)?;
globals.set("Restart", lua.create_function(restart)?)?;
globals.set("OpenURL", lua.create_function(open_url)?)?;
globals.set("RenderInit", lua.create_function(render_init)?)?;
@@ -128,6 +131,15 @@ fn strip_escapes(_: &Lua, text: String) -> LuaResult<String> {
Ok(PoBString(&text).strip_escapes())
}
fn exit(l: &Lua, exit_msg: Option<String>) -> LuaResult<()> {
if let Some(exit_msg) = exit_msg {
println!("{exit_msg}");
}
let ctx = l.app_data_ref::<&'static Context>().unwrap();
*ctx.should_exit() = true;
Ok(())
}
fn restart(l: &Lua, _: ()) -> LuaResult<()> {
let ctx = l.app_data_ref::<&'static Context>().unwrap();
*ctx.needs_restart() = true;
+3 -3
View File
@@ -1,5 +1,5 @@
use crate::{
input::{str_as_keycode, str_as_mousebutton},
input::{str_as_key, str_as_mousebutton},
lua::Context,
};
use mlua::{Lua, Result as LuaResult};
@@ -13,8 +13,8 @@ pub fn get_cursor_pos(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
pub fn is_key_down(l: &Lua, key_name: String) -> LuaResult<bool> {
let ctx = l.app_data_ref::<&'static Context>().unwrap();
if let Some(code) = str_as_keycode(&key_name) {
Ok(ctx.input().key_pressed(code))
if let Some(key) = str_as_key(&key_name) {
Ok(ctx.input().key_pressed(key))
} else if let Some(button) = str_as_mousebutton(&key_name) {
Ok(ctx.input().mouse_pressed(button))
} else {
+12
View File
@@ -47,3 +47,15 @@ pub fn make_dir(l: &Lua, path: String) -> LuaResult<MultiValue> {
Err(err) => Ok((Value::Nil, err.to_string()).into_lua_multi(l)?),
}
}
pub fn remove_dir(l: &Lua, (path, recursive): (String, Option<bool>)) -> LuaResult<MultiValue> {
let result = if recursive.unwrap_or(false) {
fs::remove_dir_all(&path)
} else {
fs::remove_dir(&path)
};
match result {
Ok(_) => Ok(Value::Boolean(true).into_lua_multi(l)?),
Err(err) => Ok((Value::Nil, err.to_string()).into_lua_multi(l)?),
}
}
+9 -2
View File
@@ -484,8 +484,15 @@ fn build_layout_job<'a>(
}
};
// TODO: check how PoB determines font size
let font_size = (line_height - 2).clamp(11, 32) as f32;
// NOTE: This is just an approximation and was chosen based on how it looks.
//
// PoB uses pre-rendered font atlases of discrete sizes and selects the appropriate
// atlas based on the provided height. Rusty-PoB dynamically renders fonts to a
// cached font atlas to support the selection of arbitrary sizes.
//
// TODO: font size in some dropdowns is too small, e.g. socket group selection in
// 'Calcs' tab
let font_size = (line_height - 2).max(1) as f32;
let mut job = LayoutJob::new(
font_family,
+32 -18
View File
@@ -14,7 +14,7 @@ use anyhow::Result;
use std::path::PathBuf;
use std::sync::Arc;
use winit::{
application::ApplicationHandler, event::*, event_loop::ActiveEventLoop, keyboard::PhysicalKey,
application::ApplicationHandler, event::*, event_loop::ActiveEventLoop,
platform::modifier_supplement::KeyEventExtModifierSupplement, window::Window,
};
@@ -29,6 +29,7 @@ pub struct AppState {
pub fonts: Fonts,
pub texture_manager: WrappedTextureManager,
pub script_dir: PathBuf,
pub should_exit: bool,
}
impl AppState {
@@ -59,6 +60,7 @@ impl App {
fonts: Fonts::new(pob_font_definitions()),
texture_manager: WrappedTextureManager::new(),
script_dir,
should_exit: false,
};
let current_mode = if uses_custom_script_dir {
@@ -188,8 +190,10 @@ impl ApplicationHandler<GraphicsContext> for App {
) {
match event {
WindowEvent::CloseRequested => {
self.handle_event(AppEvent::Exit);
event_loop.exit();
self.state.should_exit = self.current_mode.can_exit(&mut self.state);
if !self.state.should_exit {
self.state.window.request_redraw();
}
}
WindowEvent::RedrawRequested => {
profiling::scope!("RedrawRequested");
@@ -200,6 +204,12 @@ impl ApplicationHandler<GraphicsContext> for App {
return;
}
if self.state.should_exit {
self.handle_event(AppEvent::Exit);
event_loop.exit();
return;
}
if self.needs_reconfigure {
if let Some(ref mut gfx) = self.gfx_context {
let size = gfx.window.inner_size();
@@ -258,32 +268,36 @@ impl ApplicationHandler<GraphicsContext> for App {
self.state.window.is_focused = focused;
if focused {
self.state.window.request_redraw();
} else {
// Clear inputs on lost focus to avoid "stuck" keys on Wayland
// systems.
self.state.input.clear_pressed();
}
}
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
self.state.window.set_scale_factor(scale_factor as f32);
}
WindowEvent::KeyboardInput {
event:
key_event @ KeyEvent {
physical_key: PhysicalKey::Code(code),
state,
..
},
..
} => {
WindowEvent::KeyboardInput { event, .. } => {
let state = event.state;
// update input state
self.state.input.set_key_pressed(code, state.is_pressed());
self.state
.input
.set_key_pressed(event.logical_key.clone(), state.is_pressed());
// forward KeyUp/KeyDown events
let event = match state {
ElementState::Pressed => AppEvent::KeyDown { code },
ElementState::Released => AppEvent::KeyUp { code },
let app_event = match state {
ElementState::Pressed => AppEvent::KeyDown {
key: event.logical_key.clone(),
},
ElementState::Released => AppEvent::KeyUp {
key: event.logical_key.clone(),
},
};
self.handle_event(event);
self.handle_event(app_event);
// handle text input
if let Some(text) = key_event.text_with_all_modifiers()
if let Some(text) = event.text_with_all_modifiers()
&& state.is_pressed()
{
for ch in text.chars() {
+14
View File
@@ -1,29 +1,42 @@
//! `args` is used to parse the arguments passed to the program on launch.
//!
//! Normally these are the arguments passed after the `rusty-path-of-building`
//! command from a CLI.
use clap::Parser;
use clap::ValueEnum;
use directories::BaseDirs;
use std::path::PathBuf;
/// CLI arguments passed to the application on launch.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
/// Used to determine which PoB to start. (PoE1 or PoE2)
#[arg(value_enum)]
pub game: Game,
/// Specify a build to load on start using a URL. (Optional)
#[arg(
help = "URL of build to import on startup. Needs to use custom protocol schema, e.g. `pob://pobbin/<id>`"
)]
pub import_url: Option<String>,
}
/// Enum representing which game (PoE1 or PoE2) the application needs to launch.
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Game {
/// Path of Exile 1
#[value(name = "poe1")]
Poe1,
/// Path of Exile 2
#[value(name = "poe2")]
Poe2,
}
impl Game {
/// Returns the path to the user’s data directory based on which `Game` option
/// was used to start the application.
pub fn data_dir(&self) -> PathBuf {
let directory_name = match self {
Game::Poe1 => "RustyPathOfBuilding1",
@@ -32,6 +45,7 @@ impl Game {
BaseDirs::new().unwrap().data_dir().join(directory_name)
}
/// Returns the path to the user's data directory. Calls [`Self::data_dir`].
pub fn script_dir(&self) -> PathBuf {
self.data_dir()
}
+167 -182
View File
@@ -1,33 +1,45 @@
//! Module to handle user inputs like keyboard keys and mouse buttons.
use crate::dpi::LogicalPoint;
use ahash::{HashMap, HashSet};
use std::time::{Duration, Instant};
use winit::{
event::MouseButton,
keyboard::{KeyCode, ModifiersState},
keyboard::{Key, ModifiersState, NamedKey, SmolStr},
};
/// Current state of various keyboard and mouse inputs for the application.
#[derive(Default)]
pub struct InputState {
/// Current state(s) of modifier keys. (Shift, Control, Alt, Super)
pub key_modifiers: ModifiersState,
keys_pressed: HashSet<KeyCode>,
/// HashSet of currently pressed keyboard keys.
keys_pressed: HashSet<Key>,
/// HashSet of currently pressed mouse buttons.
mouse_pressed: HashSet<MouseButton>,
/// HashMap of mouse buttons (keys) with the last time they were pressed.
mouse_last_pressed: HashMap<MouseButton, Instant>,
/// Current cursor position relative to the top-left corner of the window.
cursor_pos: LogicalPoint<f32>,
}
impl InputState {
pub fn set_key_pressed(&mut self, code: KeyCode, is_pressed: bool) {
/// Updates [`Self::keys_pressed`] based on `is_pressed`.
pub fn set_key_pressed(&mut self, key: Key, is_pressed: bool) {
if is_pressed {
self.keys_pressed.insert(code);
self.keys_pressed.insert(key);
} else {
self.keys_pressed.remove(&code);
self.keys_pressed.remove(&key);
}
}
pub fn key_pressed(&self, code: KeyCode) -> bool {
self.keys_pressed.contains(&code)
/// Returns if the key is pressed (`true`) or not pressed (`false`).
pub fn key_pressed(&self, key: Key) -> bool {
self.keys_pressed.contains(&key)
}
/// Updates [`Self::mouse_pressed`](field@Self::mouse_pressed) based on provided
/// `button` and `is_pressed`.
pub fn set_mouse_pressed(&mut self, button: MouseButton, is_pressed: bool) -> bool {
if is_pressed {
self.mouse_pressed.insert(button);
@@ -50,202 +62,171 @@ impl InputState {
}
}
/// Returns `true` if the `button` was pressed and no release has been seen.
pub fn mouse_pressed(&self, button: MouseButton) -> bool {
self.mouse_pressed.contains(&button)
}
/// Returns the last known cursor position.
pub fn mouse_pos(&self) -> LogicalPoint<f32> {
self.cursor_pos
}
/// Sets [`Self::cursor_pos`] to the provided `pos`.
pub fn set_mouse_pos(&mut self, pos: LogicalPoint<f32>) {
self.cursor_pos = pos;
}
/// Clears all pressed keys, buttons, and modifier states. Used when the
/// application loses focus to avoid keys being "stuck" on/pressed.
pub fn clear_pressed(&mut self) {
self.keys_pressed.clear();
self.mouse_pressed.clear();
self.key_modifiers = ModifiersState::empty();
}
}
pub fn str_as_keycode(s: &str) -> Option<KeyCode> {
/// Attempts to convert the provided string `s` to a [winit::keyboard::Key].
/// Returns [None] if no matching Key found.
pub fn str_as_key(s: &str) -> Option<Key> {
Some(match s.to_uppercase().as_str() {
// Letters
"A" => KeyCode::KeyA,
"B" => KeyCode::KeyB,
"C" => KeyCode::KeyC,
"D" => KeyCode::KeyD,
"E" => KeyCode::KeyE,
"F" => KeyCode::KeyF,
"G" => KeyCode::KeyG,
"H" => KeyCode::KeyH,
"I" => KeyCode::KeyI,
"J" => KeyCode::KeyJ,
"K" => KeyCode::KeyK,
"L" => KeyCode::KeyL,
"M" => KeyCode::KeyM,
"N" => KeyCode::KeyN,
"O" => KeyCode::KeyO,
"P" => KeyCode::KeyP,
"Q" => KeyCode::KeyQ,
"R" => KeyCode::KeyR,
"S" => KeyCode::KeyS,
"T" => KeyCode::KeyT,
"U" => KeyCode::KeyU,
"V" => KeyCode::KeyV,
"W" => KeyCode::KeyW,
"X" => KeyCode::KeyX,
"Y" => KeyCode::KeyY,
"Z" => KeyCode::KeyZ,
"A" => Key::Character(SmolStr::new_static("A")),
"B" => Key::Character(SmolStr::new_static("B")),
"C" => Key::Character(SmolStr::new_static("C")),
"D" => Key::Character(SmolStr::new_static("D")),
"E" => Key::Character(SmolStr::new_static("E")),
"F" => Key::Character(SmolStr::new_static("F")),
"G" => Key::Character(SmolStr::new_static("G")),
"H" => Key::Character(SmolStr::new_static("H")),
"I" => Key::Character(SmolStr::new_static("I")),
"J" => Key::Character(SmolStr::new_static("J")),
"K" => Key::Character(SmolStr::new_static("K")),
"L" => Key::Character(SmolStr::new_static("L")),
"M" => Key::Character(SmolStr::new_static("M")),
"N" => Key::Character(SmolStr::new_static("N")),
"O" => Key::Character(SmolStr::new_static("O")),
"P" => Key::Character(SmolStr::new_static("P")),
"Q" => Key::Character(SmolStr::new_static("Q")),
"R" => Key::Character(SmolStr::new_static("R")),
"S" => Key::Character(SmolStr::new_static("S")),
"T" => Key::Character(SmolStr::new_static("T")),
"U" => Key::Character(SmolStr::new_static("U")),
"V" => Key::Character(SmolStr::new_static("V")),
"W" => Key::Character(SmolStr::new_static("W")),
"X" => Key::Character(SmolStr::new_static("X")),
"Y" => Key::Character(SmolStr::new_static("Y")),
"Z" => Key::Character(SmolStr::new_static("Z")),
// Digits
"0" => KeyCode::Digit0,
"1" => KeyCode::Digit1,
"2" => KeyCode::Digit2,
"3" => KeyCode::Digit3,
"4" => KeyCode::Digit4,
"5" => KeyCode::Digit5,
"6" => KeyCode::Digit6,
"7" => KeyCode::Digit7,
"8" => KeyCode::Digit8,
"9" => KeyCode::Digit9,
"0" => Key::Character(SmolStr::new_static("0")),
"1" => Key::Character(SmolStr::new_static("1")),
"2" => Key::Character(SmolStr::new_static("2")),
"3" => Key::Character(SmolStr::new_static("3")),
"4" => Key::Character(SmolStr::new_static("4")),
"5" => Key::Character(SmolStr::new_static("5")),
"6" => Key::Character(SmolStr::new_static("6")),
"7" => Key::Character(SmolStr::new_static("7")),
"8" => Key::Character(SmolStr::new_static("8")),
"9" => Key::Character(SmolStr::new_static("9")),
// Modifiers
"SHIFT" => KeyCode::ShiftLeft,
"CTRL" => KeyCode::ControlLeft,
"ALT" => KeyCode::AltLeft,
"SHIFT" => Key::Named(NamedKey::Shift),
"CTRL" => Key::Named(NamedKey::Control),
"ALT" => Key::Named(NamedKey::Alt),
// F Keys
"F1" => KeyCode::F1,
"F2" => KeyCode::F2,
"F3" => KeyCode::F3,
"F4" => KeyCode::F4,
"F5" => KeyCode::F5,
"F6" => KeyCode::F6,
"F7" => KeyCode::F7,
"F8" => KeyCode::F8,
"F9" => KeyCode::F9,
"F10" => KeyCode::F10,
"F11" => KeyCode::F11,
"F12" => KeyCode::F12,
"F1" => Key::Named(NamedKey::F1),
"F2" => Key::Named(NamedKey::F2),
"F3" => Key::Named(NamedKey::F3),
"F4" => Key::Named(NamedKey::F4),
"F5" => Key::Named(NamedKey::F5),
"F6" => Key::Named(NamedKey::F6),
"F7" => Key::Named(NamedKey::F7),
"F8" => Key::Named(NamedKey::F8),
"F9" => Key::Named(NamedKey::F9),
"F10" => Key::Named(NamedKey::F10),
"F11" => Key::Named(NamedKey::F11),
"F12" => Key::Named(NamedKey::F12),
// Rest
" " => KeyCode::Space,
"BACK" => KeyCode::Backspace,
"TAB" => KeyCode::Tab,
"RETURN" => KeyCode::Enter,
"ESCAPE" => KeyCode::Escape,
"PAUSE" => KeyCode::Pause,
"PAGEUP" => KeyCode::PageUp,
"PAGEDOWN" => KeyCode::PageDown,
"END" => KeyCode::End,
"HOME" => KeyCode::Home,
"PRINTSCREEN" => KeyCode::PrintScreen,
"INSERT" => KeyCode::Insert,
"DELETE" => KeyCode::Delete,
"UP" => KeyCode::ArrowUp,
"DOWN" => KeyCode::ArrowDown,
"LEFT" => KeyCode::ArrowLeft,
"RIGHT" => KeyCode::ArrowRight,
"NUMLOCK" => KeyCode::NumLock,
"SCROLL" => KeyCode::ScrollLock,
" " => Key::Named(NamedKey::Space),
"BACK" => Key::Named(NamedKey::Backspace),
"TAB" => Key::Named(NamedKey::Tab),
"RETURN" => Key::Named(NamedKey::Enter),
"ESCAPE" => Key::Named(NamedKey::Escape),
"PAUSE" => Key::Named(NamedKey::Pause),
"PAGEUP" => Key::Named(NamedKey::PageUp),
"PAGEDOWN" => Key::Named(NamedKey::PageDown),
"END" => Key::Named(NamedKey::End),
"HOME" => Key::Named(NamedKey::Home),
"PRINTSCREEN" => Key::Named(NamedKey::PrintScreen),
"INSERT" => Key::Named(NamedKey::Insert),
"DELETE" => Key::Named(NamedKey::Delete),
"UP" => Key::Named(NamedKey::ArrowUp),
"DOWN" => Key::Named(NamedKey::ArrowDown),
"LEFT" => Key::Named(NamedKey::ArrowLeft),
"RIGHT" => Key::Named(NamedKey::ArrowRight),
"NUMLOCK" => Key::Named(NamedKey::NumLock),
"SCROLL" => Key::Named(NamedKey::ScrollLock),
_ => return None,
})
}
pub fn keycode_as_str(code: KeyCode) -> Option<&'static str> {
Some(match code {
// Letters
KeyCode::KeyA => "a",
KeyCode::KeyB => "b",
KeyCode::KeyC => "c",
KeyCode::KeyD => "d",
KeyCode::KeyE => "e",
KeyCode::KeyF => "f",
KeyCode::KeyG => "g",
KeyCode::KeyH => "h",
KeyCode::KeyI => "i",
KeyCode::KeyJ => "j",
KeyCode::KeyK => "k",
KeyCode::KeyL => "l",
KeyCode::KeyM => "m",
KeyCode::KeyN => "n",
KeyCode::KeyO => "o",
KeyCode::KeyP => "p",
KeyCode::KeyQ => "q",
KeyCode::KeyR => "r",
KeyCode::KeyS => "s",
KeyCode::KeyT => "t",
KeyCode::KeyU => "u",
KeyCode::KeyV => "v",
KeyCode::KeyW => "w",
KeyCode::KeyX => "x",
KeyCode::KeyY => "y",
KeyCode::KeyZ => "z",
// Digits
KeyCode::Digit0 => "0",
KeyCode::Digit1 => "1",
KeyCode::Digit2 => "2",
KeyCode::Digit3 => "3",
KeyCode::Digit4 => "4",
KeyCode::Digit5 => "5",
KeyCode::Digit6 => "6",
KeyCode::Digit7 => "7",
KeyCode::Digit8 => "8",
KeyCode::Digit9 => "9",
// Modifiers
KeyCode::ShiftLeft => "SHIFT",
KeyCode::ControlLeft => "CTRL",
KeyCode::AltLeft => "ALT",
// F Keys
KeyCode::F1 => "F1",
KeyCode::F2 => "F2",
KeyCode::F3 => "F3",
KeyCode::F4 => "F4",
KeyCode::F5 => "F5",
KeyCode::F6 => "F6",
KeyCode::F7 => "F7",
KeyCode::F8 => "F8",
KeyCode::F9 => "F9",
KeyCode::F10 => "F10",
KeyCode::F11 => "F11",
KeyCode::F12 => "F12",
// Rest
KeyCode::Space => " ",
KeyCode::Backspace => "BACK",
KeyCode::Tab => "TAB",
KeyCode::Enter => "RETURN",
KeyCode::Escape => "ESCAPE",
KeyCode::Pause => "PAUSE",
KeyCode::PageUp => "PAGEUP",
KeyCode::PageDown => "PAGEDOWN",
KeyCode::End => "END",
KeyCode::Home => "HOME",
KeyCode::PrintScreen => "PRINTSCREEN",
KeyCode::Insert => "INSERT",
KeyCode::Delete => "DELETE",
KeyCode::ArrowUp => "UP",
KeyCode::ArrowDown => "DOWN",
KeyCode::ArrowLeft => "LEFT",
KeyCode::ArrowRight => "RIGHT",
KeyCode::NumLock => "NUMLOCK",
KeyCode::ScrollLock => "SCROLL",
KeyCode::Equal => "+", // This is what PoB does
KeyCode::Minus => "-",
KeyCode::Comma => ",",
KeyCode::Period => ".",
KeyCode::Slash => "/",
KeyCode::NumpadAdd => "+",
KeyCode::NumpadSubtract => "-",
KeyCode::NumpadEnter => "RETURN",
KeyCode::Numpad0 => "0",
/// Attempts to convert the provided [winit::keyboard::Key] `key` to a string
/// representation that PoB recognizes.
///
/// Returns [None] if no matching string found.
pub fn key_as_str(key: Key) -> Option<SmolStr> {
Some(match key {
Key::Character(ch) => {
if ch == "=" {
SmolStr::new("+") // This is what PoB does
} else {
ch
}
}
Key::Named(named) => SmolStr::new(match named {
NamedKey::Shift => "SHIFT",
NamedKey::Control => "CTRL",
NamedKey::Alt => "ALT",
NamedKey::F1 => "F1",
NamedKey::F2 => "F2",
NamedKey::F3 => "F3",
NamedKey::F4 => "F4",
NamedKey::F5 => "F5",
NamedKey::F6 => "F6",
NamedKey::F7 => "F7",
NamedKey::F8 => "F8",
NamedKey::F9 => "F9",
NamedKey::F10 => "F10",
NamedKey::F11 => "F11",
NamedKey::F12 => "F12",
NamedKey::Space => " ",
NamedKey::Backspace => "BACK",
NamedKey::Tab => "TAB",
NamedKey::Enter => "RETURN",
NamedKey::Escape => "ESCAPE",
NamedKey::Pause => "PAUSE",
NamedKey::PageUp => "PAGEUP",
NamedKey::PageDown => "PAGEDOWN",
NamedKey::End => "END",
NamedKey::Home => "HOME",
NamedKey::PrintScreen => "PRINTSCREEN",
NamedKey::Insert => "INSERT",
NamedKey::Delete => "DELETE",
NamedKey::ArrowUp => "UP",
NamedKey::ArrowDown => "DOWN",
NamedKey::ArrowLeft => "LEFT",
NamedKey::ArrowRight => "RIGHT",
NamedKey::NumLock => "NUMLOCK",
NamedKey::ScrollLock => "SCROLL",
_ => return None,
}),
_ => return None,
})
}
/// Attempts to convert the provided [&str] `s` from the PoB Lua Backend to a
/// [MouseButton].
///
/// Returns [None] if no matching string found.
pub fn str_as_mousebutton(s: &str) -> Option<MouseButton> {
Some(match s.to_uppercase().as_str() {
"LEFTBUTTON" => MouseButton::Left,
@@ -257,13 +238,17 @@ pub fn str_as_mousebutton(s: &str) -> Option<MouseButton> {
})
}
pub fn mousebutton_as_str(button: MouseButton) -> Option<&'static str> {
/// Attempts to convert the provided [MouseButton] to a [SmolStr] that the PoB Lua
/// backend recognizes.
///
/// Returns [None] if no matching [MouseButton] was found.
pub fn mousebutton_as_str(button: MouseButton) -> Option<SmolStr> {
Some(match button {
MouseButton::Left => "LEFTBUTTON",
MouseButton::Right => "RIGHTBUTTON",
MouseButton::Middle => "MIDDLEBUTTON",
MouseButton::Back => "MOUSE4",
MouseButton::Forward => "MOUSE5",
MouseButton::Left => SmolStr::new("LEFTBUTTON"),
MouseButton::Right => SmolStr::new("RIGHTBUTTON"),
MouseButton::Middle => SmolStr::new("MIDDLEBUTTON"),
MouseButton::Back => SmolStr::new("MOUSE4"),
MouseButton::Forward => SmolStr::new("MOUSE5"),
_ => return None,
})
}
+39 -9
View File
@@ -11,7 +11,6 @@ use crate::{
use flate2::read::GzDecoder;
use parley::{FontFamily, GenericFamily};
use regex::Regex;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{
fs::{self},
io::copy,
@@ -19,9 +18,15 @@ use std::{
sync::mpsc::{self, Receiver, TryRecvError},
thread,
};
use ureq::http::Response;
use std::{
sync::LazyLock,
time::{Duration, SystemTime, UNIX_EPOCH},
};
use ureq::{Agent, http::Response};
const REPO_NAME: &str = "meehl/rusty-pob-manifest";
static VERSION_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^(\d+)\.(\d+)\.(\d+)$").unwrap());
enum DownloadProgress {
Percentage(f32), // percentage of total size (between 0 and 1)
@@ -29,6 +34,7 @@ enum DownloadProgress {
}
enum Progress {
Status(String),
Download(DownloadProgress),
Complete,
Error(anyhow::Error),
@@ -36,6 +42,7 @@ enum Progress {
enum CurrentProgress {
Starting,
Status(String),
Download(DownloadProgress),
}
@@ -84,6 +91,9 @@ impl InstallMode {
Ok(Progress::Download(progress)) => {
self.current_progress = CurrentProgress::Download(progress);
}
Ok(Progress::Status(msg)) => {
self.current_progress = CurrentProgress::Status(msg);
}
Ok(Progress::Complete) => {
return Ok(Some(ModeTransition::PoB));
}
@@ -126,6 +136,7 @@ impl InstallMode {
let progress_text = match &self.current_progress {
CurrentProgress::Starting => String::from("Starting download..."),
CurrentProgress::Status(msg) => msg.clone(),
CurrentProgress::Download(progress) => match progress {
DownloadProgress::Percentage(progress) => {
let percent = (progress * 100.0) as u32;
@@ -175,16 +186,29 @@ fn install<P: AsRef<Path>>(
return Ok(());
}
progress_tx.send(Progress::Status("Fetching compatibility info...".into()))?;
log::info!("Fetching compatibility info...");
let compatibility_info = fetch_compatibility_info(game)?;
progress_tx.send(Progress::Status("Resolving PoB version...".into()))?;
log::info!("Resolving supported PoB version...");
let needed_pob_version = highest_supported_pob_version(&compatibility_info, current_version)
.ok_or_else(|| anyhow::anyhow!("Unable to determine supported PoB version"))?;
log::info!("Using PoB version: {needed_pob_version}");
progress_tx.send(Progress::Status("Downloading assets...".into()))?;
download_path_of_building(&target_dir, game, needed_pob_version, progress_tx)?;
progress_tx.send(Progress::Status("Patching UpdateCheck...".into()))?;
log::info!("Patching UpdateCheck...");
replace_updatecheck(&target_dir)?;
progress_tx.send(Progress::Status("Finalizing installation...".into()))?;
log::info!("Finalizing installation...");
set_branch_and_platform(&target_dir)?;
// write version file
fs::write(&version_file_path, env!("CARGO_PKG_VERSION")).unwrap();
log::info!("Installation complete.");
Ok(())
}
@@ -217,6 +241,9 @@ fn fetch_compatibility_info(game: Game) -> anyhow::Result<Vec<VersionReq>> {
Ok(compatibility_table
.pairs::<String, String>()
.filter_map(|p| p.ok())
// filter out beta versions. beta version adds a suffix to the version string which is not
// matched by the version regex resulting in them being filtered out
.filter(|(pob_version, _)| VERSION_RE.is_match(pob_version))
.map(|(pob_version, min_req_rpob_ver)| VersionReq {
pob_ver: pob_version,
min_rpob_ver: min_req_rpob_ver,
@@ -340,8 +367,6 @@ fn download_path_of_building<P: AsRef<Path>>(
/// Replaces UpdateCheck with rusty-path-of-building's modified version
fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
log::info!("Downloading modified UpdateCheck.lua script...");
download_file(
&format!(
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
@@ -486,9 +511,16 @@ fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
let mut attempt = 0;
let mut backoff_secs: u64 = 2;
let config = Agent::config_builder()
.timeout_global(Some(Duration::from_secs(10)))
.build();
let agent: Agent = config.into();
loop {
attempt += 1;
let resp_result = ureq::get(url)
let resp_result = agent
.get(url)
.header("User-Agent", "rusty-path-of-building")
.call();
@@ -544,10 +576,8 @@ fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
/// Compares two SemVer versions and returns true if v2 is higher or equal than v1
fn is_higher_version(v1: &str, v2: &str) -> anyhow::Result<bool> {
let re = Regex::new(r"^(\d+)\.(\d+)\.(\d+)$").unwrap();
let parse_version = |v: &str| -> anyhow::Result<(u32, u32, u32)> {
let caps = re
let caps = VERSION_RE
.captures(v)
.ok_or_else(|| anyhow::anyhow!("Invalid semver format: {}", v))?;
+22 -4
View File
@@ -18,6 +18,7 @@ use std::{
path::PathBuf,
rc::Rc,
};
use winit::keyboard::SmolStr;
macro_rules! ctx_accessor {
($field:ident: & $ty:ty) => {
@@ -51,6 +52,7 @@ pub struct Context {
current_working_dir: Cell<*mut PathBuf>,
layers: Cell<*mut Layers>,
needs_restart: Cell<*mut bool>,
should_exit: Cell<*mut bool>,
is_dpi_aware: Cell<*mut bool>,
}
@@ -65,6 +67,7 @@ impl Context {
current_working_dir: Cell::new(std::ptr::null_mut()),
layers: Cell::new(std::ptr::null_mut()),
needs_restart: Cell::new(std::ptr::null_mut()),
should_exit: Cell::new(std::ptr::null_mut()),
is_dpi_aware: Cell::new(std::ptr::null_mut()),
}))
}
@@ -79,6 +82,7 @@ impl Context {
.set(&mut ctx.pob.current_working_dir);
self.layers.set(&mut ctx.pob.layers);
self.needs_restart.set(&mut ctx.pob.needs_restart);
self.should_exit.set(&mut ctx.app.should_exit);
self.is_dpi_aware.set(&mut ctx.pob.is_dpi_aware);
}
@@ -91,6 +95,7 @@ impl Context {
self.current_working_dir.set(std::ptr::null_mut());
self.layers.set(std::ptr::null_mut());
self.needs_restart.set(std::ptr::null_mut());
self.should_exit.set(std::ptr::null_mut());
self.is_dpi_aware.set(std::ptr::null_mut());
}
@@ -102,6 +107,7 @@ impl Context {
ctx_accessor!(current_working_dir: &mut PathBuf);
ctx_accessor!(layers: &mut Layers);
ctx_accessor!(needs_restart: &mut bool);
ctx_accessor!(should_exit: &mut bool);
ctx_accessor!(is_dpi_aware: &mut bool);
}
@@ -109,8 +115,8 @@ pub enum PoBEvent {
Init,
Exit,
Frame,
KeyDown(&'static str, bool),
KeyUp(&'static str),
KeyDown(SmolStr, bool),
KeyUp(SmolStr),
Char(char),
SubFinished {
id: u64,
@@ -258,6 +264,18 @@ impl LuaInstance {
list_func.call::<Table>(())
}
pub fn can_exit(&self, pob_ctx: &mut PoBContext) -> bool {
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
ctx.set(pob_ctx);
let can_exit = get_callback(&self.lua, "CanExit")
.and_then(|f| f.call(()))
.unwrap_or(true);
ctx.clear();
can_exit
}
pub fn handle_event(&self, event: PoBEvent, pob_ctx: &mut PoBContext) -> LuaResult<()> {
profiling::scope!("handle_event", format!("{}", event));
@@ -271,9 +289,9 @@ impl LuaInstance {
PoBEvent::Exit => get_callback(&self.lua, "OnExit")?.call::<()>(()),
PoBEvent::Frame => get_callback(&self.lua, "OnFrame")?.call::<()>(()),
PoBEvent::KeyDown(key, double_click) => {
get_callback(&self.lua, "OnKeyDown")?.call::<()>((key, double_click))
get_callback(&self.lua, "OnKeyDown")?.call::<()>((key.as_str(), double_click))
}
PoBEvent::KeyUp(key) => get_callback(&self.lua, "OnKeyUp")?.call::<()>(key),
PoBEvent::KeyUp(key) => get_callback(&self.lua, "OnKeyUp")?.call::<()>(key.as_str()),
PoBEvent::Char(ch) => get_callback(&self.lua, "OnChar")?.call::<()>(ch),
PoBEvent::SubFinished { id, return_values } => {
get_callback(&self.lua, "OnSubFinished")?.call::<()>((id, return_values))
+10 -3
View File
@@ -1,14 +1,14 @@
use crate::{
app::AppState, installer::InstallMode, pob::PoBMode, renderer::primitives::ClippedPrimitive,
};
use winit::{event::MouseButton, keyboard::KeyCode};
use winit::{event::MouseButton, keyboard::Key};
pub enum AppEvent {
KeyDown {
code: KeyCode,
key: Key,
},
KeyUp {
code: KeyCode,
key: Key,
},
MouseDown {
button: MouseButton,
@@ -65,4 +65,11 @@ impl AppMode {
AppMode::PoB(mode) => mode.handle_event(state, event),
}
}
pub fn can_exit(&mut self, state: &mut AppState) -> bool {
match self {
AppMode::Install(_) => true,
AppMode::PoB(mode) => mode.can_exit(state),
}
}
}
+14 -9
View File
@@ -1,7 +1,7 @@
use crate::{
app::AppState,
dpi::{LogicalRect, LogicalSize},
input::{keycode_as_str, mousebutton_as_str},
input::{key_as_str, mousebutton_as_str},
layers::Layers,
lua::{LuaInstance, PoBContext, PoBEvent},
mode::{AppEvent, ModeFrameOutput, ModeTransition},
@@ -97,14 +97,14 @@ impl PoBMode {
let mut ctx = PoBContext::new(app_state, &mut self.state);
match event {
AppEvent::KeyDown { code } => {
if let Some(key_string) = keycode_as_str(code) {
AppEvent::KeyDown { key } => {
if let Some(key_string) = key_as_str(key) {
let pob_event = PoBEvent::KeyDown(key_string, false);
self.lua_instance.handle_event(pob_event, &mut ctx)?;
}
}
AppEvent::KeyUp { code } => {
if let Some(key_string) = keycode_as_str(code) {
AppEvent::KeyUp { key } => {
if let Some(key_string) = key_as_str(key) {
let pob_event = PoBEvent::KeyUp(key_string);
self.lua_instance.handle_event(pob_event, &mut ctx)?;
}
@@ -127,14 +127,14 @@ impl PoBMode {
AppEvent::MouseWheel { delta } => {
if delta > 0.0 {
self.lua_instance
.handle_event(PoBEvent::KeyDown("WHEELUP", false), &mut ctx)?;
.handle_event(PoBEvent::KeyDown("WHEELUP".into(), false), &mut ctx)?;
self.lua_instance
.handle_event(PoBEvent::KeyUp("WHEELUP"), &mut ctx)?;
.handle_event(PoBEvent::KeyUp("WHEELUP".into()), &mut ctx)?;
} else if delta < 0.0 {
self.lua_instance
.handle_event(PoBEvent::KeyDown("WHEELDOWN", false), &mut ctx)?;
.handle_event(PoBEvent::KeyDown("WHEELDOWN".into(), false), &mut ctx)?;
self.lua_instance
.handle_event(PoBEvent::KeyUp("WHEELDOWN"), &mut ctx)?;
.handle_event(PoBEvent::KeyUp("WHEELDOWN".into()), &mut ctx)?;
}
}
AppEvent::CharacterInput { ch } => {
@@ -147,6 +147,11 @@ impl PoBMode {
Ok(())
}
pub fn can_exit(&mut self, app_state: &mut AppState) -> bool {
let mut ctx = PoBContext::new(app_state, &mut self.state);
self.lua_instance.can_exit(&mut ctx)
}
fn reset_viewport(&mut self, size: LogicalSize<u32>) {
self.state
.layers