Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2c0f2fffc | ||
|
|
a6be413190 | ||
|
|
8034eef8c7 | ||
|
|
3b0d5295d3 | ||
|
|
ff46a570fc | ||
|
|
7db64e337d | ||
|
|
522ab489cd | ||
|
|
8217aca6f2 | ||
|
|
249116af52 | ||
|
|
c47bf48556 | ||
|
|
1f89e31f30 | ||
|
|
913d2127d8 | ||
|
|
1c99e9fabc | ||
|
|
12fc773958 | ||
|
|
ef4f86eac8 | ||
|
|
966363a859 | ||
|
|
9d33a7704c | ||
|
|
3a66f15b49 | ||
|
|
7d02ca098c | ||
|
|
a858af2c38 | ||
|
|
7fc3e340e7 | ||
|
|
dadf5c8804 | ||
|
|
031df6ed9c | ||
|
|
e395e729e8 | ||
|
|
76b5449bad | ||
|
|
f9f05aad08 | ||
|
|
3eacd43837 | ||
|
|
523d5ffe29 | ||
|
|
e18623edb4 | ||
|
|
1812edcbe9 | ||
|
|
df06c8f9c6 | ||
|
|
ae6a24f82c | ||
|
|
0066a05e13 | ||
|
|
3d8143c4d1 | ||
|
|
a3ef4b39d0 | ||
|
|
f48ab50633 | ||
|
|
b86486d5aa | ||
|
|
1f1a331cc2 | ||
|
|
27b93c4a9d | ||
|
|
c95514036f | ||
|
|
37bc3c5dbb | ||
|
|
56155d066a | ||
|
|
f27e83b467 | ||
|
|
50d4b4b09c | ||
|
|
51e6881cb0 | ||
|
|
8a69d15b49 | ||
|
|
3af5e3dccb | ||
|
|
76a1b4691d | ||
|
|
e877b599c1 | ||
|
|
cc38e31dbb | ||
|
|
2739c45181 | ||
|
|
18b05338bf | ||
|
|
73ebb1655a | ||
|
|
87ff0968d8 |
No files matched your search
@@ -0,0 +1,11 @@
|
||||
# Contributing to Rusty Path Of Building
|
||||
|
||||
## Reporting bugs
|
||||
- Ensure the bug was not already reported by searching through existing [issues](https://github.com/meehl/rusty-path-of-building/issues).
|
||||
- If the bug can also be reproduced with the official runtime (e.g. by running through wine), please open an issue in the [PoB1](https://github.com/PathOfBuildingCommunity/PathOfBuilding) or [PoB2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2) repo instead. If you're unsure, feel free to just open it here.
|
||||
- If possible, use the bug report template to create the issue and provide as much information as possible.
|
||||
|
||||
## Contributing code
|
||||
- Get familiar with the code base before you start. I'll try to add more documentation providing a high-level overview of the architecture in the future. Until then, feel free to reach out through [Discussions](https://github.com/meehl/rusty-path-of-building/discussions) if you have any questions.
|
||||
- If you intend to work on the API functions, also check out the [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) code base. A great place to ask questions about it is the PoB dev discord server. [Here](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic) is more info on how to join.
|
||||
- Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A description of what you expected to happen.
|
||||
|
||||
**System information:**
|
||||
- OS: [e.g. Linux, Windows, macOS]
|
||||
- Desktop Environment/Compositor: [e.g. KDE, Gnome, sway, etc.] (only on Linux)
|
||||
- Rusty Path of Building Version: [e.g. v0.2.8]
|
||||
- Path of Building Version: [e.g. PoB1 v2.59.0 or PoB2 v0.12.2]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here. Feel free to add screenshots or any other info like PoB build codes if relevant.
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: yes
|
||||
contact_links:
|
||||
- name: GitHub Discussions
|
||||
url: https://github.com/meehl/rusty-path-of-building/discussions
|
||||
about: Please ask questions unrelated to actual bugs/issues here.
|
||||
+83
-1
@@ -2,6 +2,80 @@
|
||||
|
||||
## [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
|
||||
|
||||
- Implement GetDrawColor
|
||||
|
||||
### Fixed
|
||||
|
||||
- Avoid redundant update after initial download
|
||||
|
||||
## [0.2.9] - 2025-12-03
|
||||
|
||||
### Added
|
||||
|
||||
- Implement UI scale overriding
|
||||
|
||||
### Changed
|
||||
|
||||
- Reduce CPU usage while window is unfocused and not hovered over
|
||||
- Download highest compatible PoB version instead of latest version
|
||||
|
||||
### Fixed
|
||||
|
||||
- Register `AbortSubscript` function under right name
|
||||
|
||||
## [0.2.8] - 2025-11-07
|
||||
|
||||
### Changed
|
||||
|
||||
- Replace non-ASCII characters in text input with '?'
|
||||
- Use `smithay-clipboard` crate for clipboard support on Wayland
|
||||
|
||||
## [0.2.7] - 2025-11-02
|
||||
|
||||
### Added
|
||||
|
||||
- Add missing window icon. Note for package maintainers: On Wayland, the name of the `.desktop` file entries needs to match RustyPoB's `app_id`. `app_id` is set to either `rusty-path-of-building-1` or `rusty-path-of-building-2`, depending on the game argument.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix missing window title during installation step
|
||||
- Fix UI scaling factor not being applied at startup on X11
|
||||
|
||||
## [0.2.6] - 2025-10-31
|
||||
|
||||
### Added
|
||||
@@ -100,8 +174,16 @@
|
||||
- First release
|
||||
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...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
|
||||
[0.2.7]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.6...v0.2.7
|
||||
[0.2.6]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.5...v0.2.6
|
||||
[0.2.5]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.4...v0.2.5
|
||||
[0.2.4]: https://github.com/meehl/rusty-path-of-building/compare/v0.2.3...v0.2.4
|
||||
|
||||
Generated
+100
-101
@@ -173,7 +173,6 @@ dependencies = [
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"windows-sys 0.60.2",
|
||||
"wl-clipboard-rs",
|
||||
"x11rb",
|
||||
]
|
||||
|
||||
@@ -242,7 +241,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"arrayvec",
|
||||
"log",
|
||||
"nom 8.0.0",
|
||||
"nom",
|
||||
"num-rational",
|
||||
"v_frame",
|
||||
]
|
||||
@@ -387,18 +386,43 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
version = "0.14.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb9f6e1368bd4621d2c86baa7e37de77a938adf5221e5dd3d6133340101b309e"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"polling",
|
||||
"rustix 1.1.2",
|
||||
"slab",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
|
||||
dependencies = [
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"rustix 0.38.44",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa"
|
||||
dependencies = [
|
||||
"calloop 0.14.3",
|
||||
"rustix 1.1.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.43"
|
||||
@@ -803,12 +827,6 @@ dependencies = [
|
||||
"thiserror 2.0.17",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.7"
|
||||
@@ -836,12 +854,6 @@ version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.5"
|
||||
@@ -1397,12 +1409,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
@@ -1518,16 +1524,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "8.0.0"
|
||||
@@ -1943,16 +1939,6 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_pipe"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owned_ttf_parser"
|
||||
version = "0.25.1"
|
||||
@@ -2017,16 +2003,6 @@ version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.10"
|
||||
@@ -2530,7 +2506,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-path-of-building"
|
||||
version = "0.2.6"
|
||||
version = "0.2.14"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"anyhow",
|
||||
@@ -2555,7 +2531,9 @@ dependencies = [
|
||||
"pollster",
|
||||
"profiling",
|
||||
"puffin_http",
|
||||
"raw-window-handle",
|
||||
"regex",
|
||||
"smithay-clipboard",
|
||||
"swash",
|
||||
"tar",
|
||||
"ureq",
|
||||
@@ -2594,7 +2572,7 @@ dependencies = [
|
||||
"ab_glyph",
|
||||
"log",
|
||||
"memmap2",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
@@ -2687,8 +2665,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"calloop",
|
||||
"calloop-wayland-source",
|
||||
"calloop 0.13.0",
|
||||
"calloop-wayland-source 0.3.0",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -2705,6 +2683,44 @@ dependencies = [
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-client-toolkit"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"calloop 0.14.3",
|
||||
"calloop-wayland-source 0.4.1",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix 1.1.2",
|
||||
"thiserror 2.0.17",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
"wayland-cursor",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-experimental",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"wayland-scanner",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-clipboard"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"smithay-client-toolkit 0.20.0",
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.2.2"
|
||||
@@ -2799,19 +2815,6 @@ version = "0.12.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.3.4",
|
||||
"once_cell",
|
||||
"rustix 1.1.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
@@ -2967,6 +2970,7 @@ version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
@@ -2977,18 +2981,6 @@ version = "0.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
|
||||
|
||||
[[package]]
|
||||
name = "tree_magic_mini"
|
||||
version = "3.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f943391d896cdfe8eec03a04d7110332d445be7df856db382dd96a730667562c"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"nom 7.1.3",
|
||||
"once_cell",
|
||||
"petgraph",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ttf-parser"
|
||||
version = "0.25.1"
|
||||
@@ -3227,6 +3219,32 @@ dependencies = [
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-experimental"
|
||||
version = "20250721.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfe33d551eb8bffd03ff067a8b44bb963919157841a99957151299a6307d19c"
|
||||
dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.9"
|
||||
@@ -3737,7 +3755,7 @@ dependencies = [
|
||||
"bitflags 2.10.0",
|
||||
"block2",
|
||||
"bytemuck",
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"cfg_aliases",
|
||||
"concurrent-queue",
|
||||
"core-foundation",
|
||||
@@ -3759,7 +3777,7 @@ dependencies = [
|
||||
"redox_syscall 0.4.1",
|
||||
"rustix 0.38.44",
|
||||
"sctk-adwaita",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"smol_str",
|
||||
"tracing",
|
||||
"unicode-segmentation",
|
||||
@@ -3792,25 +3810,6 @@ version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||
|
||||
[[package]]
|
||||
name = "wl-clipboard-rs"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5ff8d0e60065f549fafd9d6cb626203ea64a798186c80d8e7df4f8af56baeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"os_pipe",
|
||||
"rustix 0.38.44",
|
||||
"tempfile",
|
||||
"thiserror 2.0.17",
|
||||
"tree_magic_mini",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-wlr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
version = "0.6.2"
|
||||
|
||||
+6
-2
@@ -4,14 +4,14 @@ authors = ["meehl"]
|
||||
description = "Cross-platform runtime for Path of Building"
|
||||
repository = "https://github.com/meehl/rusty-path-of-building"
|
||||
license = "MIT"
|
||||
version = "0.2.6"
|
||||
version = "0.2.14"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.8.12"
|
||||
anyhow = "1.0"
|
||||
arboard = { version = "3.6.1", default-features = false, features = ["wayland-data-control"] }
|
||||
arboard = { version = "3.6.1", default-features = false }
|
||||
bytemuck = "1.23.2"
|
||||
clap = { version = "4.5.46", features = ["derive"] }
|
||||
dds = "0.1.0"
|
||||
@@ -32,6 +32,7 @@ parley = "0.6.0"
|
||||
pollster = "0.3"
|
||||
profiling = "1.0"
|
||||
puffin_http = { version = "0.16", optional = true }
|
||||
raw-window-handle = "0.6.2"
|
||||
regex = "1.11.2"
|
||||
swash = "0.2.5"
|
||||
tar = "0.4.44"
|
||||
@@ -40,5 +41,8 @@ wgpu = { version = "27.0.1", default-features = false, features = ["std", "parki
|
||||
winit = "0.30"
|
||||
zstd = "0.13.3"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
smithay-clipboard = "0.7.3"
|
||||
|
||||
[features]
|
||||
profile-with-puffin = ["profiling/profile-with-puffin", "dep:puffin_http"]
|
||||
@@ -1,8 +1,8 @@
|
||||
# Rusty Path of Building
|
||||
|
||||
Rusty Path of Building is a cross-platform runtime for [Path of Building](https://github.com/PathOfBuildingCommunity/PathOfBuilding) and [Path of Building 2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2). Like the [official runtime](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic), it serves as a host environment for PoB by implementing the API used by the application's Lua logic, as well as rendering, window management, and input handling.
|
||||
Rusty Path of Building is a cross-platform runtime environment for [Path of Building](https://github.com/PathOfBuildingCommunity/PathOfBuilding) and [Path of Building 2](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2). Like [SimpleGraphic](https://github.com/PathOfBuildingCommunity/PathOfBuilding-SimpleGraphic), PoB's official runtime environment, it implements the API functions required by PoB's Lua code, handles window management and input, and renders the UI.
|
||||
|
||||
This project was primarily created to allow Path of Building to run natively on Linux. It is written in Rust (in case you couldn't already tell from the unimaginative name) and should run on all platforms, though only Linux has been tested so far.
|
||||
The primary goal of this project is to provide native Linux support for Path of Building. It is written in Rust with cross-platform compatibility in mind and also runs on Windows, though testing there has been minimal.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -12,11 +12,11 @@ rusty-path-of-building [poe1|poe2]
|
||||
|
||||
## Installation
|
||||
|
||||
### Arch (AUR)
|
||||
[](https://repology.org/project/rusty-path-of-building/versions)
|
||||
|
||||
[](https://aur.archlinux.org/packages/rusty-path-of-building)
|
||||
### Flathub
|
||||
|
||||
Please check [the Arch Wiki](https://wiki.archlinux.org/title/Arch_User_Repository) on how to install packages from the AUR.
|
||||
[](https://flathub.org/en/apps/community.pathofbuilding.PathOfBuilding)
|
||||
|
||||
### Building from source
|
||||
|
||||
@@ -39,4 +39,4 @@ Please refer to the [Lua documentation](https://www.lua.org/manual/5.1/manual.ht
|
||||
|
||||
## Known Issues
|
||||
|
||||
- The clipboard doesn't work with Wayland compositors that don't support the data-control extension(s). It is recommended to fall back to `Xwayland` in these cases. This can be done by unsetting `WAYLAND_DISPLAY`. More info here: https://github.com/1Password/arboard?tab=readme-ov-file#backend-support
|
||||
- If automatic updates fail, navigate to `~/.local/share/RustyPathOfBuilding{1,2}/` and delete both the `rpob.version` file and the `Update` directory. This will force a complete re-download of PoB's latest assets and Lua code on the next startup. (Note: Third-party backends, like this project, face challenges supporting PoB's update mechanism. To make it work, fragile workarounds had to be implemented that can break unexpectedly)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
@@ -646,7 +646,7 @@ static int l_zipFile_Read(lua_State* L)
|
||||
if (n < 1) {
|
||||
luaL_error(L, "Usage: zipFile:Read(count) or zipFile:read(\"*a\")");
|
||||
}
|
||||
int count;
|
||||
int count = 0;
|
||||
if (lua_isnumber(L, 1)) {
|
||||
count = lua_tointeger(L, 1);
|
||||
} else {
|
||||
|
||||
+18
-6
@@ -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,
|
||||
@@ -18,7 +19,7 @@ use crate::{
|
||||
set_foreground, set_window_title,
|
||||
},
|
||||
},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Variadic};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
@@ -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,9 +131,18 @@ 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 socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
*socket.needs_restart() = true;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
*ctx.needs_restart() = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -142,10 +154,10 @@ fn open_url(l: &Lua, url: String) -> LuaResult<MultiValue> {
|
||||
}
|
||||
|
||||
fn render_init(l: &Lua, features: Variadic<String>) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
for feature in features {
|
||||
if feature == "DPI_AWARE" {
|
||||
*socket.is_dpi_aware() = true;
|
||||
*ctx.is_dpi_aware() = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
+6
-13
@@ -1,20 +1,13 @@
|
||||
use crate::lua::ContextSocket;
|
||||
use crate::lua::Context;
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn copy(l: &Lua, text: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket
|
||||
.clipboard()
|
||||
.set_text(text)
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().set_clipboard_text(text);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn paste(l: &Lua, _: ()) -> LuaResult<String> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let text = socket
|
||||
.clipboard()
|
||||
.get_text()
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
Ok(text)
|
||||
pub fn paste(l: &Lua, _: ()) -> LuaResult<Option<String>> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.window().get_clipboard_text())
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
renderer::textures::{TextureHandle, TextureOptions},
|
||||
};
|
||||
use mlua::{Lua, MultiValue, Result as LuaResult, UserData};
|
||||
@@ -56,7 +56,7 @@ fn load(
|
||||
handle: &mut ImageHandle,
|
||||
(image_path, flags): (String, MultiValue),
|
||||
) -> LuaResult<()> {
|
||||
let socket = lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = lua.app_data_ref::<&'static Context>().unwrap();
|
||||
let mut is_async = false;
|
||||
let mut options = TextureOptions::LINEAR_REPEAT;
|
||||
|
||||
@@ -76,7 +76,7 @@ fn load(
|
||||
// replace image data if already allocated
|
||||
ImageHandle::Loaded(texture_handle) => {
|
||||
// in case of error, stay loaded with current texture
|
||||
let _ = socket.texture_manager().update_texture(
|
||||
let _ = ctx.texture_manager().update_texture(
|
||||
texture_handle.id(),
|
||||
image_path,
|
||||
options,
|
||||
@@ -85,7 +85,7 @@ fn load(
|
||||
}
|
||||
// create new texture handle
|
||||
ImageHandle::Unloaded => {
|
||||
if let Ok(tex_handle) = socket
|
||||
if let Ok(tex_handle) = ctx
|
||||
.texture_manager()
|
||||
.load_texture(image_path, options, is_async)
|
||||
{
|
||||
|
||||
+8
-8
@@ -1,22 +1,22 @@
|
||||
use crate::{
|
||||
input::{str_as_keycode, str_as_mousebutton},
|
||||
lua::ContextSocket,
|
||||
input::{str_as_key, str_as_mousebutton},
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn get_cursor_pos(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let pos = socket.input().mouse_pos();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let pos = ctx.input().mouse_pos();
|
||||
Ok((pos.x as u32, pos.y as u32))
|
||||
}
|
||||
|
||||
pub fn is_key_down(l: &Lua, key_name: String) -> LuaResult<bool> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
if let Some(code) = str_as_keycode(&key_name) {
|
||||
Ok(socket.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(socket.input().mouse_pressed(button))
|
||||
Ok(ctx.input().mouse_pressed(button))
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,4 +1,4 @@
|
||||
use crate::{args::Game, util::change_working_directory};
|
||||
use crate::{lua::Context, util::change_working_directory};
|
||||
use mlua::{Function, IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
|
||||
use std::env;
|
||||
|
||||
@@ -12,26 +12,28 @@ pub fn protected_call(l: &Lua, (func, args): (Function, MultiValue)) -> LuaResul
|
||||
}
|
||||
|
||||
pub fn load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<MultiValue> {
|
||||
let mut module_path = Game::script_dir().join(name);
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let mut module_path = ctx.script_dir().join(name);
|
||||
if module_path.extension().is_none() {
|
||||
module_path.set_extension("lua");
|
||||
}
|
||||
|
||||
let current_dir = env::current_dir()?;
|
||||
change_working_directory(Game::script_dir().as_path())?;
|
||||
change_working_directory(ctx.script_dir().as_path())?;
|
||||
let result = l.load(module_path).call::<MultiValue>(args);
|
||||
change_working_directory(current_dir)?;
|
||||
result
|
||||
}
|
||||
|
||||
pub fn protected_load_module(l: &Lua, (name, args): (String, MultiValue)) -> LuaResult<MultiValue> {
|
||||
let mut module_path = Game::script_dir().join(name);
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let mut module_path = ctx.script_dir().join(name);
|
||||
if module_path.extension().is_none() {
|
||||
module_path.set_extension("lua");
|
||||
}
|
||||
|
||||
let current_dir = env::current_dir()?;
|
||||
change_working_directory(Game::script_dir().as_path())?;
|
||||
change_working_directory(ctx.script_dir().as_path())?;
|
||||
let result = match l.load(module_path).call::<MultiValue>(args) {
|
||||
// on success, callers expect a Nil followed by return values
|
||||
Ok(res) => Ok(std::iter::once(Value::Nil).chain(res).collect()),
|
||||
|
||||
+23
-10
@@ -2,18 +2,19 @@ use mlua::{IntoLuaMulti, Lua, MultiValue, Result as LuaResult, Value};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::{
|
||||
args::Game,
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
util::{change_working_directory, get_executable_dir},
|
||||
};
|
||||
|
||||
pub fn get_user_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
Ok(Game::user_data_dir())
|
||||
pub fn get_user_path(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.script_dir().join("userdata"))
|
||||
}
|
||||
|
||||
// parent directory of Launch.lua script
|
||||
pub fn get_script_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
Ok(Game::script_dir())
|
||||
pub fn get_script_path(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.script_dir().to_owned())
|
||||
}
|
||||
|
||||
// parent directory of executable
|
||||
@@ -25,15 +26,15 @@ pub fn get_runtime_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
}
|
||||
|
||||
pub fn get_work_dir(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
Ok(socket.current_working_dir().to_path_buf())
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
Ok(ctx.current_working_dir().to_path_buf())
|
||||
}
|
||||
|
||||
// NOTE: unused
|
||||
pub fn set_work_dir(l: &Lua, path: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
if change_working_directory(&path).is_ok() {
|
||||
*socket.current_working_dir() = path.into();
|
||||
*ctx.current_working_dir() = path.into();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -46,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)?),
|
||||
}
|
||||
}
|
||||
+52
-47
@@ -3,7 +3,7 @@ use crate::{
|
||||
color::Srgba,
|
||||
dpi::Uv,
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
math::{Point, Quad, Rect, Size},
|
||||
};
|
||||
use core::ffi::{c_int, c_void};
|
||||
@@ -34,6 +34,7 @@ pub fn register_globals(lua: &Lua) -> LuaResult<()> {
|
||||
// thousands of times per frame. C functions are used to get raw access to
|
||||
// the lua stack without the overhead.
|
||||
unsafe { globals.set("SetDrawColor", lua.create_c_function(set_draw_color)?)? };
|
||||
unsafe { globals.set("GetDrawColor", lua.create_c_function(get_draw_color)?)? };
|
||||
unsafe { globals.set("SetViewport", lua.create_c_function(set_viewport)?)? };
|
||||
unsafe {
|
||||
globals.set("SetDrawLayer", lua.create_c_function(set_draw_layer)?)?;
|
||||
@@ -127,9 +128,7 @@ unsafe extern "C" fn lua_toimghandle(state: *mut ffi::lua_State, idx: c_int) ->
|
||||
unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_draw_color");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
match nargs {
|
||||
@@ -137,7 +136,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
1 => {
|
||||
let esc_str = str_from_stack!(state, -nargs);
|
||||
let color = Srgba::from_escape_code(esc_str);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
// rgb
|
||||
3 => {
|
||||
@@ -145,7 +144,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
let g = f32_from_stack!(state, -nargs + 1);
|
||||
let b = f32_from_stack!(state, -nargs + 2);
|
||||
let color = Srgba::new_f32(r, g, b, 1.0);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
// rgba
|
||||
4 => {
|
||||
@@ -154,7 +153,7 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
let b = f32_from_stack!(state, -nargs + 2);
|
||||
let a = f32_from_stack!(state, -nargs + 3);
|
||||
let color = Srgba::new_f32(r, g, b, a);
|
||||
socket.layers().set_draw_color(color);
|
||||
ctx.layers().set_draw_color(color);
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
};
|
||||
@@ -162,25 +161,37 @@ unsafe extern "C-unwind" fn set_draw_color(state: *mut ffi::lua_State) -> c_int
|
||||
0
|
||||
}
|
||||
|
||||
unsafe extern "C-unwind" fn get_draw_color(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("get_draw_color");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let color: [f32; 4] = ctx.layers().get_draw_color().into();
|
||||
unsafe { ffi::lua_pushnumber(state, color[0] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[1] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[2] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[3] as f64) };
|
||||
|
||||
4
|
||||
}
|
||||
|
||||
unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_viewport");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
match nargs {
|
||||
0 => socket
|
||||
0 => ctx
|
||||
.layers()
|
||||
.set_viewport_from_size(socket.window().logical_size()),
|
||||
.set_viewport_from_size(ctx.window().logical_size()),
|
||||
4 => {
|
||||
let x = f32_from_stack!(state, -nargs);
|
||||
let y = f32_from_stack!(state, -nargs + 1);
|
||||
let w = f32_from_stack!(state, -nargs + 2);
|
||||
let h = f32_from_stack!(state, -nargs + 3);
|
||||
let rect = Rect::from_origin_and_size(Point::new(x, y), Size::new(w, h));
|
||||
socket.layers().set_viewport(rect);
|
||||
ctx.layers().set_viewport(rect);
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
};
|
||||
@@ -191,16 +202,14 @@ unsafe extern "C-unwind" fn set_viewport(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("set_draw_layer");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
match nargs {
|
||||
1 => {
|
||||
let layer = i32_from_stack!(state, -nargs);
|
||||
socket.layers().set_draw_layer(layer, 0);
|
||||
ctx.layers().set_draw_layer(layer, 0);
|
||||
}
|
||||
2 => {
|
||||
let layer = match unsafe { ffi::lua_type(state, -nargs) } {
|
||||
@@ -213,9 +222,9 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int
|
||||
};
|
||||
let sublayer = i32_from_stack!(state, -nargs + 1);
|
||||
if let Some(layer) = layer {
|
||||
socket.layers().set_draw_layer(layer, sublayer);
|
||||
ctx.layers().set_draw_layer(layer, sublayer);
|
||||
} else {
|
||||
socket.layers().set_draw_sublayer(sublayer);
|
||||
ctx.layers().set_draw_sublayer(sublayer);
|
||||
}
|
||||
}
|
||||
_ => panic!("Unexpected number of arguments"),
|
||||
@@ -227,9 +236,7 @@ unsafe extern "C-unwind" fn set_draw_layer(state: *mut ffi::lua_State) -> c_int
|
||||
unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_image");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 5 | 6 | 7 | 9 | 10 | 11) {
|
||||
@@ -269,7 +276,7 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
0
|
||||
};
|
||||
|
||||
socket.layers().draw_rect(texture_id, rect, uv, layer_idx);
|
||||
ctx.layers().draw_rect(texture_id, rect, uv, layer_idx);
|
||||
|
||||
0
|
||||
}
|
||||
@@ -277,9 +284,7 @@ unsafe extern "C-unwind" fn draw_image(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_image_quad", format!("args: {:?}", args));
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
if !matches!(nargs, 9 | 10 | 11 | 17 | 18 | 19) {
|
||||
@@ -337,7 +342,7 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int
|
||||
0
|
||||
};
|
||||
|
||||
socket.layers().draw_quad(texture_id, quad, uv, layer_idx);
|
||||
ctx.layers().draw_quad(texture_id, quad, uv, layer_idx);
|
||||
|
||||
0
|
||||
}
|
||||
@@ -345,9 +350,7 @@ unsafe extern "C-unwind" fn draw_image_quad(state: *mut ffi::lua_State) -> c_int
|
||||
unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("draw_string");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
@@ -370,7 +373,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
let mut position = Point::new(x, y);
|
||||
let mut is_absolute_position = false;
|
||||
// the position needs to be adjusted for some alignments to match PoBs behavior
|
||||
let screen_size = socket.window().logical_size();
|
||||
let screen_size = ctx.window().logical_size();
|
||||
let halign = match alignment {
|
||||
PoBTextAlignment::Left => Alignment::Min,
|
||||
PoBTextAlignment::Center => {
|
||||
@@ -387,7 +390,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
PoBTextAlignment::RightX => Alignment::Max,
|
||||
};
|
||||
|
||||
let current_draw_color = socket.layers().get_draw_color();
|
||||
let current_draw_color = ctx.layers().get_draw_color();
|
||||
let job = build_layout_job(
|
||||
text,
|
||||
current_draw_color,
|
||||
@@ -399,12 +402,11 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
// NOTE: color escape codes modify the current draw color.
|
||||
// set current draw color to color of last segment to match PoB's behavior
|
||||
if let Some(last_segment) = job.segments.last() {
|
||||
socket.layers().set_draw_color(last_segment.color);
|
||||
ctx.layers().set_draw_color(last_segment.color);
|
||||
}
|
||||
|
||||
let layout = socket.fonts().layout(job, socket.window().scale_factor);
|
||||
socket
|
||||
.layers()
|
||||
let layout = ctx.fonts().layout(job, ctx.window().scale_factor());
|
||||
ctx.layers()
|
||||
.draw_text(position, layout, is_absolute_position);
|
||||
|
||||
0
|
||||
@@ -413,9 +415,7 @@ unsafe extern "C-unwind" fn draw_string(state: *mut ffi::lua_State) -> c_int {
|
||||
unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_int {
|
||||
//profiling::scope!("get_string_width");
|
||||
let lua_instance = unsafe { Lua::get_or_init_from_ptr(state) };
|
||||
let socket = lua_instance
|
||||
.app_data_ref::<&'static ContextSocket>()
|
||||
.unwrap();
|
||||
let ctx = lua_instance.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let nargs = unsafe { ffi::lua_gettop(state) };
|
||||
|
||||
@@ -429,9 +429,7 @@ unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) -> c_in
|
||||
};
|
||||
|
||||
let job = build_layout_job(text, Srgba::WHITE, font_type, line_height, None);
|
||||
let width = socket
|
||||
.fonts()
|
||||
.get_text_width(job, socket.window().scale_factor);
|
||||
let width = ctx.fonts().get_text_width(job, ctx.window().scale_factor());
|
||||
|
||||
unsafe { ffi::lua_pushnumber(state, width as f64) };
|
||||
1
|
||||
@@ -442,15 +440,15 @@ fn get_index_at_cur(
|
||||
(line_height, font_type, text, cur_x, cur_y): (i32, String, String, f32, f32),
|
||||
) -> LuaResult<usize> {
|
||||
//profiling::scope!("get_char_index_at_cur");
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
|
||||
let font_type = font_type.parse::<PoBFontType>()?;
|
||||
|
||||
let job = build_layout_job(&text, Srgba::WHITE, font_type, line_height, None);
|
||||
let index = socket.fonts().get_text_index_at_cursor(
|
||||
let index = ctx.fonts().get_text_index_at_cursor(
|
||||
job,
|
||||
Point::new(cur_x, cur_y),
|
||||
socket.window().scale_factor,
|
||||
ctx.window().scale_factor(),
|
||||
);
|
||||
|
||||
// convert to lua's 1-based indexing
|
||||
@@ -486,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,
|
||||
|
||||
+25
-16
@@ -1,44 +1,53 @@
|
||||
use crate::{
|
||||
dpi::{LogicalSize, PhysicalSize},
|
||||
lua::ContextSocket,
|
||||
lua::Context,
|
||||
};
|
||||
use mlua::{Lua, Result as LuaResult};
|
||||
|
||||
pub fn get_screen_size(l: &Lua, _: ()) -> LuaResult<(u32, u32)> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
let size = if *socket.is_dpi_aware() {
|
||||
let PhysicalSize { width, height, .. } = socket.window().size;
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let size = if *ctx.is_dpi_aware() {
|
||||
let PhysicalSize { width, height, .. } = ctx.window().size;
|
||||
(width, height)
|
||||
} else {
|
||||
let LogicalSize { width, height, .. } = socket.window().logical_size();
|
||||
let LogicalSize { width, height, .. } = ctx.window().logical_size();
|
||||
(width, height)
|
||||
};
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
pub fn get_screen_scale(l: &Lua, _: ()) -> LuaResult<f32> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
Ok(socket.window().scale_factor)
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
let scale_factor = ctx.window().scale_factor();
|
||||
Ok(scale_factor)
|
||||
}
|
||||
|
||||
pub fn set_window_title(l: &Lua, title: String) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.window().set_window_title(&title);
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().set_window_title(&title);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_foreground(l: &Lua, _: ()) -> LuaResult<()> {
|
||||
let socket = l.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.window().focus();
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.window().focus();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_dpi_scale_override(_: &Lua, _percent: i32) -> LuaResult<()> {
|
||||
// TODO:
|
||||
pub fn set_dpi_scale_override(l: &Lua, percent: i32) -> LuaResult<()> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
match percent {
|
||||
0 => ctx.window().scale_factor_override = None,
|
||||
p if p > 0 => ctx.window().scale_factor_override = Some(p as f32 / 100.0),
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_dpi_scale_override(_: &Lua, _: ()) -> LuaResult<i32> {
|
||||
// TODO:
|
||||
Ok(0)
|
||||
pub fn get_dpi_scale_override(l: &Lua, _: ()) -> LuaResult<i32> {
|
||||
let ctx = l.app_data_ref::<&'static Context>().unwrap();
|
||||
match ctx.window().scale_factor_override {
|
||||
Some(scale_factor) => Ok((scale_factor * 100.0) as i32),
|
||||
None => Ok(0),
|
||||
}
|
||||
}
|
||||
+178
-99
@@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
args::Game,
|
||||
dpi::{ConvertToLogical, PhysicalPoint, PhysicalSize},
|
||||
fonts::{FontData, FontDefinitions, Fonts},
|
||||
gfx::{GraphicsContext, RenderJob},
|
||||
@@ -10,18 +11,16 @@ use crate::{
|
||||
window::WindowState,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use arboard::Clipboard;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::*,
|
||||
event_loop::ActiveEventLoop,
|
||||
keyboard::{ModifiersState, PhysicalKey},
|
||||
window::Window,
|
||||
application::ApplicationHandler, event::*, event_loop::ActiveEventLoop,
|
||||
platform::modifier_supplement::KeyEventExtModifierSupplement, window::Window,
|
||||
};
|
||||
|
||||
struct FrameOutput {
|
||||
pub render_job: RenderJob,
|
||||
pub should_continue: bool,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
@@ -29,38 +28,58 @@ pub struct AppState {
|
||||
pub input: InputState,
|
||||
pub fonts: Fonts,
|
||||
pub texture_manager: WrappedTextureManager,
|
||||
pub clipboard: Clipboard,
|
||||
pub script_dir: PathBuf,
|
||||
pub should_exit: bool,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
fn set_mouse_pos(&mut self, pos: PhysicalPoint<f32>) {
|
||||
self.input
|
||||
.set_mouse_pos(pos.to_logical(self.window.scale_factor));
|
||||
.set_mouse_pos(pos.to_logical(self.window.scale_factor()));
|
||||
}
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
gfx_context: Option<GraphicsContext>,
|
||||
state: AppState,
|
||||
game: Game,
|
||||
tessellator: Tessellator,
|
||||
needs_reconfigure: bool,
|
||||
force_render: bool,
|
||||
current_mode: AppMode,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Result<Self> {
|
||||
pub fn new(game: Game, custom_script_dir: Option<PathBuf>) -> Result<Self> {
|
||||
let uses_custom_script_dir = custom_script_dir.is_some();
|
||||
let script_dir = custom_script_dir.unwrap_or_else(|| game.script_dir());
|
||||
|
||||
let mut state = AppState {
|
||||
window: WindowState::default(),
|
||||
input: InputState::default(),
|
||||
fonts: Fonts::new(pob_font_definitions()),
|
||||
texture_manager: WrappedTextureManager::new(),
|
||||
script_dir,
|
||||
should_exit: false,
|
||||
};
|
||||
|
||||
let current_mode = if uses_custom_script_dir {
|
||||
// Skip installer if custom script dir is provided.
|
||||
// Used for local testing
|
||||
let pob_mode = PoBMode::new(&mut state)?;
|
||||
AppMode::PoB(pob_mode)
|
||||
} else {
|
||||
AppMode::Install(InstallMode::new(game))
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
gfx_context: None,
|
||||
state: AppState {
|
||||
window: WindowState::default(),
|
||||
input: InputState::default(),
|
||||
fonts: Fonts::new(pob_font_definitions()),
|
||||
texture_manager: WrappedTextureManager::new(),
|
||||
clipboard: arboard::Clipboard::new()?,
|
||||
},
|
||||
state,
|
||||
game,
|
||||
tessellator: Tessellator::default(),
|
||||
force_render: false,
|
||||
current_mode: AppMode::Install(InstallMode::new()),
|
||||
needs_reconfigure: true,
|
||||
force_render: true,
|
||||
current_mode,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -97,12 +116,10 @@ impl App {
|
||||
{
|
||||
RenderJob::Skip
|
||||
} else {
|
||||
self.force_render = false;
|
||||
|
||||
let meshes = self.tessellator.convert_clipped_primitives(
|
||||
mode_output.primitives,
|
||||
font_atlas_size,
|
||||
self.state.window.scale_factor,
|
||||
self.state.window.scale_factor(),
|
||||
);
|
||||
|
||||
RenderJob::Render {
|
||||
@@ -111,7 +128,10 @@ impl App {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(FrameOutput { render_job })
|
||||
Ok(FrameOutput {
|
||||
render_job,
|
||||
should_continue: mode_output.should_continue,
|
||||
})
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, event: AppEvent) {
|
||||
@@ -119,28 +139,46 @@ impl App {
|
||||
log::error!("{err}");
|
||||
}
|
||||
}
|
||||
|
||||
fn create_window(&mut self, event_loop: &ActiveEventLoop) -> anyhow::Result<()> {
|
||||
let (title, _app_id) = match self.game {
|
||||
Game::Poe1 => ("Path of Building 1", "rusty-path-of-building-1"),
|
||||
Game::Poe2 => ("Path of Building 2", "rusty-path-of-building-2"),
|
||||
};
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut window_attributes = Window::default_attributes()
|
||||
.with_title(title)
|
||||
.with_window_icon(load_icon());
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use winit::platform::wayland::ActiveEventLoopExtWayland;
|
||||
use winit::platform::x11::ActiveEventLoopExtX11;
|
||||
|
||||
if event_loop.is_x11() {
|
||||
use winit::platform::x11::WindowAttributesExtX11;
|
||||
window_attributes = window_attributes.with_name(_app_id, _app_id);
|
||||
} else if event_loop.is_wayland() {
|
||||
use winit::platform::wayland::WindowAttributesExtWayland;
|
||||
window_attributes = window_attributes.with_name(_app_id, _app_id);
|
||||
}
|
||||
}
|
||||
|
||||
let window = event_loop.create_window(window_attributes)?;
|
||||
let window = Arc::new(window);
|
||||
self.state.window.set_window(Arc::clone(&window));
|
||||
self.gfx_context = Some(pollster::block_on(GraphicsContext::new(window))?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler<GraphicsContext> for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = match event_loop.create_window(Window::default_attributes()) {
|
||||
Ok(window) => Arc::new(window),
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.state.window.set_window(Arc::clone(&window));
|
||||
|
||||
self.gfx_context = match pollster::block_on(GraphicsContext::new(window)) {
|
||||
Ok(gfx) => Some(gfx),
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
if let Err(err) = self.create_window(event_loop) {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,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");
|
||||
@@ -164,26 +204,56 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
return;
|
||||
}
|
||||
|
||||
let render_job = match self.frame() {
|
||||
Ok(FrameOutput { render_job }) => render_job,
|
||||
Err(err) => {
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
if self.state.should_exit {
|
||||
self.handle_event(AppEvent::Exit);
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(ref mut gfx) = self.gfx_context {
|
||||
match gfx.render(render_job) {
|
||||
Ok(_) => {}
|
||||
// Reconfigure the surface if it's lost or outdated
|
||||
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
|
||||
let size = gfx.window.inner_size();
|
||||
gfx.resize(size.width, size.height);
|
||||
self.force_render = true;
|
||||
}
|
||||
if self.needs_reconfigure {
|
||||
if let Some(ref mut gfx) = self.gfx_context {
|
||||
let size = gfx.window.inner_size();
|
||||
gfx.resize(size.width, size.height);
|
||||
}
|
||||
self.needs_reconfigure = false;
|
||||
// Render at least one frame after reconfigure
|
||||
self.force_render = true;
|
||||
}
|
||||
|
||||
let is_focused = self.state.window.is_focused;
|
||||
let is_hovered = self.state.window.is_hovered;
|
||||
let should_render = is_focused || is_hovered || self.force_render;
|
||||
|
||||
if should_render {
|
||||
let FrameOutput {
|
||||
render_job,
|
||||
should_continue,
|
||||
} = match self.frame() {
|
||||
Ok(frame_output) => frame_output,
|
||||
Err(err) => {
|
||||
log::error!("Unable to render: {err}");
|
||||
log::error!("{err}");
|
||||
event_loop.exit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(ref mut gfx) = self.gfx_context {
|
||||
match gfx.render(render_job, self.state.window.scale_factor()) {
|
||||
Ok(_) => {
|
||||
self.force_render = should_continue;
|
||||
|
||||
if is_focused || is_hovered || should_continue {
|
||||
self.state.window.request_redraw();
|
||||
}
|
||||
}
|
||||
// Reconfigure the surface if it's lost or outdated
|
||||
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
|
||||
self.needs_reconfigure = true;
|
||||
self.state.window.request_redraw();
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Unable to render: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,53 +261,48 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
profiling::finish_frame!();
|
||||
}
|
||||
WindowEvent::Resized(size) => {
|
||||
if let Some(ref mut gfx) = self.gfx_context {
|
||||
gfx.resize(size.width, size.height);
|
||||
self.force_render = true;
|
||||
}
|
||||
self.state.window.size = PhysicalSize::new(size.width, size.height);
|
||||
self.needs_reconfigure = true;
|
||||
}
|
||||
WindowEvent::Focused(focused) => {
|
||||
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.scale_factor = scale_factor as f32;
|
||||
self.state.window.set_scale_factor(scale_factor as f32);
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
event:
|
||||
KeyEvent {
|
||||
physical_key: PhysicalKey::Code(code),
|
||||
logical_key,
|
||||
state,
|
||||
..
|
||||
},
|
||||
..
|
||||
} => {
|
||||
self.state.input.set_key_pressed(code, state.is_pressed());
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
let state = event.state;
|
||||
|
||||
let event = match state {
|
||||
ElementState::Pressed => AppEvent::KeyDown { code },
|
||||
ElementState::Released => AppEvent::KeyUp { code },
|
||||
// update input state
|
||||
self.state
|
||||
.input
|
||||
.set_key_pressed(event.logical_key.clone(), state.is_pressed());
|
||||
|
||||
// forward KeyUp/KeyDown events
|
||||
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 state.is_pressed() {
|
||||
match logical_key {
|
||||
winit::keyboard::Key::Character(text) => {
|
||||
// only emit event if no modifier except Shift is pressed.
|
||||
let modifiers = self.state.input.key_modifiers;
|
||||
if modifiers.difference(ModifiersState::SHIFT).is_empty() {
|
||||
for ch in text.chars() {
|
||||
let event = AppEvent::CharacterInput { ch };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
winit::keyboard::Key::Named(named) => {
|
||||
if named == winit::keyboard::NamedKey::Space {
|
||||
let event = AppEvent::CharacterInput { ch: ' ' };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if let Some(text) = event.text_with_all_modifiers()
|
||||
&& state.is_pressed()
|
||||
{
|
||||
for ch in text.chars() {
|
||||
let event = AppEvent::CharacterInput { ch };
|
||||
self.handle_event(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,6 +328,13 @@ impl ApplicationHandler<GraphicsContext> for App {
|
||||
let pos = PhysicalPoint::new(position.x as f32, position.y as f32);
|
||||
self.state.set_mouse_pos(pos);
|
||||
}
|
||||
WindowEvent::CursorEntered { .. } => {
|
||||
self.state.window.is_hovered = true;
|
||||
self.state.window.request_redraw();
|
||||
}
|
||||
WindowEvent::CursorLeft { .. } => {
|
||||
self.state.window.is_hovered = false;
|
||||
}
|
||||
WindowEvent::MouseWheel { delta, .. } => {
|
||||
let delta = match delta {
|
||||
MouseScrollDelta::LineDelta(_, y) => y,
|
||||
@@ -342,3 +414,10 @@ fn pob_font_definitions() -> FontDefinitions {
|
||||
|
||||
definitions
|
||||
}
|
||||
|
||||
fn load_icon() -> Option<winit::window::Icon> {
|
||||
let image_data = include_bytes!("../assets/icon.png");
|
||||
let image = image::load_from_memory(image_data).ok()?.into_rgba8();
|
||||
let (width, height) = image.dimensions();
|
||||
winit::window::Icon::from_rgba(image.into_raw(), width, height).ok()
|
||||
}
|
||||
+23
-20
@@ -1,49 +1,52 @@
|
||||
//! `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,
|
||||
|
||||
pub build_path: Option<String>,
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, ValueEnum)]
|
||||
/// 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,
|
||||
}
|
||||
|
||||
static GAME_CONFIG: std::sync::OnceLock<Game> = std::sync::OnceLock::new();
|
||||
|
||||
impl Game {
|
||||
pub fn init(game: Game) {
|
||||
GAME_CONFIG.set(game).expect("Game should be uninitialized");
|
||||
}
|
||||
|
||||
pub fn current() -> &'static Game {
|
||||
GAME_CONFIG.get().expect("Game should be initialized")
|
||||
}
|
||||
|
||||
pub fn data_dir() -> PathBuf {
|
||||
let directory_name = match Self::current() {
|
||||
/// 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",
|
||||
Game::Poe2 => "RustyPathOfBuilding2",
|
||||
};
|
||||
BaseDirs::new().unwrap().data_dir().join(directory_name)
|
||||
}
|
||||
|
||||
pub fn script_dir() -> PathBuf {
|
||||
Game::data_dir()
|
||||
}
|
||||
|
||||
pub fn user_data_dir() -> PathBuf {
|
||||
Game::data_dir().join("userdata")
|
||||
/// Returns the path to the user's data directory. Calls [`Self::data_dir`].
|
||||
pub fn script_dir(&self) -> PathBuf {
|
||||
self.data_dir()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
use raw_window_handle::RawDisplayHandle;
|
||||
|
||||
/// Abstraction over clipboard crates
|
||||
///
|
||||
/// `smithay_clipboard`: Used on wayland
|
||||
/// `arboard`: All other platforms (check arboard docs for platform support)
|
||||
pub struct Clipboard {
|
||||
#[cfg(target_family = "unix")]
|
||||
smithay: Option<smithay_clipboard::Clipboard>,
|
||||
arboard: Option<arboard::Clipboard>,
|
||||
// fallback if everything else fails. only supports intra-application copy/paste
|
||||
fallback: Option<String>,
|
||||
}
|
||||
|
||||
impl Clipboard {
|
||||
pub fn new(_raw_display_handle: Option<RawDisplayHandle>) -> Self {
|
||||
Self {
|
||||
#[cfg(target_family = "unix")]
|
||||
smithay: create_smithay_clipboard(_raw_display_handle),
|
||||
arboard: create_arboard_clipboard(),
|
||||
fallback: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the text content of clipboard
|
||||
pub fn set_text(&mut self, text: String) {
|
||||
#[cfg(target_family = "unix")]
|
||||
if let Some(clipboard) = &mut self.smithay {
|
||||
clipboard.store(text);
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
let _ = clipboard.set_text(text);
|
||||
return;
|
||||
}
|
||||
|
||||
self.fallback = Some(text);
|
||||
}
|
||||
|
||||
/// Gets the text content of clipboard
|
||||
pub fn get_text(&mut self) -> Option<String> {
|
||||
#[cfg(target_family = "unix")]
|
||||
if let Some(clipboard) = &mut self.smithay {
|
||||
return clipboard.load().ok();
|
||||
}
|
||||
|
||||
if let Some(clipboard) = &mut self.arboard {
|
||||
return clipboard.get_text().ok();
|
||||
}
|
||||
|
||||
if let Some(text) = &self.fallback {
|
||||
return Some(text.clone());
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
fn create_smithay_clipboard(
|
||||
raw_display_handle: Option<RawDisplayHandle>,
|
||||
) -> Option<smithay_clipboard::Clipboard> {
|
||||
if let Some(RawDisplayHandle::Wayland(handle)) = raw_display_handle {
|
||||
log::debug!("Creating smithay clipboard...");
|
||||
Some(unsafe { smithay_clipboard::Clipboard::new(handle.display.as_ptr()) })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn create_arboard_clipboard() -> Option<arboard::Clipboard> {
|
||||
log::debug!("Creating arboard clipboard...");
|
||||
match arboard::Clipboard::new() {
|
||||
Ok(clipboard) => Some(clipboard),
|
||||
Err(err) => {
|
||||
log::warn!("Failed to create arboard clipboard: {err}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,20 @@ impl From<Srgba> for image::Rgba<u8> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Srgba> for [f32; 4] {
|
||||
fn from(value: Srgba) -> Self {
|
||||
value.0.map(u8_to_f32)
|
||||
}
|
||||
}
|
||||
|
||||
/// f32 [0.0, 1.0] -> u8 [0, 255]
|
||||
#[inline(always)]
|
||||
const fn f32_to_u8(c: f32) -> u8 {
|
||||
((c * 255.0) + 0.5) as u8
|
||||
}
|
||||
|
||||
/// u8 [0, 255] -> f32 [0.0, 1.0]
|
||||
#[inline(always)]
|
||||
const fn u8_to_f32(c: u8) -> f32 {
|
||||
c as f32 / 255.0
|
||||
}
|
||||
+8
-7
@@ -144,11 +144,13 @@ impl GraphicsContext {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self, render_job: RenderJob) -> Result<(), wgpu::SurfaceError> {
|
||||
pub fn render(
|
||||
&mut self,
|
||||
render_job: RenderJob,
|
||||
scale_factor: f32,
|
||||
) -> Result<(), wgpu::SurfaceError> {
|
||||
profiling::scope!("render");
|
||||
|
||||
self.window.request_redraw();
|
||||
|
||||
if !self.is_surface_configured {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -174,7 +176,6 @@ impl GraphicsContext {
|
||||
} = render_job
|
||||
{
|
||||
let screen_size = PhysicalSize::new(self.config.width, self.config.height);
|
||||
let pixels_per_point = self.window.as_ref().scale_factor() as f32;
|
||||
|
||||
// upload new textures
|
||||
self.renderer
|
||||
@@ -186,7 +187,7 @@ impl GraphicsContext {
|
||||
&self.queue,
|
||||
&meshes,
|
||||
screen_size,
|
||||
pixels_per_point,
|
||||
scale_factor,
|
||||
);
|
||||
|
||||
let rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
@@ -214,10 +215,10 @@ impl GraphicsContext {
|
||||
&mut rpass.forget_lifetime(),
|
||||
&meshes,
|
||||
screen_size,
|
||||
pixels_per_point,
|
||||
scale_factor,
|
||||
);
|
||||
|
||||
self.renderer.free_textures(&textures_delta)
|
||||
self.renderer.free_textures(&textures_delta);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
+167
-182
@@ -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,
|
||||
})
|
||||
}
|
||||
+283
-19
@@ -6,12 +6,11 @@ use crate::{
|
||||
fonts::{Alignment, FontStyle, LayoutJob},
|
||||
mode::{AppEvent, ModeFrameOutput, ModeTransition},
|
||||
renderer::primitives::{ClippedPrimitive, DrawPrimitive, TextPrimitive},
|
||||
util::replace_in_matching_lines,
|
||||
};
|
||||
use anyhow::bail;
|
||||
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),
|
||||
}
|
||||
|
||||
@@ -49,12 +56,12 @@ pub struct InstallMode {
|
||||
}
|
||||
|
||||
impl InstallMode {
|
||||
pub fn new() -> Self {
|
||||
let script_dir = Game::script_dir();
|
||||
pub fn new(game: Game) -> Self {
|
||||
let script_dir = game.script_dir();
|
||||
let (progress_tx, progress_rx) = mpsc::channel();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(err) = install(script_dir.as_path(), &progress_tx) {
|
||||
if let Err(err) = install(script_dir.as_path(), game, &progress_tx) {
|
||||
progress_tx.send(Progress::Error(err)).unwrap();
|
||||
return;
|
||||
}
|
||||
@@ -73,6 +80,7 @@ impl InstallMode {
|
||||
Ok(ModeFrameOutput {
|
||||
primitives,
|
||||
can_elide: false,
|
||||
should_continue: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,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));
|
||||
}
|
||||
@@ -125,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;
|
||||
@@ -137,7 +149,7 @@ impl InstallMode {
|
||||
};
|
||||
job.append(&progress_text, Srgba::WHITE);
|
||||
|
||||
let layout = app_state.fonts.layout(job, app_state.window.scale_factor);
|
||||
let layout = app_state.fonts.layout(job, app_state.window.scale_factor());
|
||||
|
||||
// center text vertically and horizontally
|
||||
let screen_size = app_state.window.logical_size().cast::<f32>();
|
||||
@@ -157,13 +169,14 @@ impl InstallMode {
|
||||
|
||||
fn install<P: AsRef<Path>>(
|
||||
target_dir: P,
|
||||
game: Game,
|
||||
progress_tx: &mpsc::Sender<Progress>,
|
||||
) -> anyhow::Result<()> {
|
||||
// Skip installation if version file exists
|
||||
let current_version = env!("CARGO_PKG_VERSION");
|
||||
let version_file_path = target_dir.as_ref().join("rpob.version");
|
||||
if version_file_path.exists() {
|
||||
let old_version = fs::read_to_string(&version_file_path).unwrap();
|
||||
let current_version = env!("CARGO_PKG_VERSION");
|
||||
|
||||
if old_version != current_version {
|
||||
log::info!("New version detected: {old_version} -> {current_version}");
|
||||
@@ -173,30 +186,115 @@ fn install<P: AsRef<Path>>(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
download_path_of_building(&target_dir, progress_tx)?;
|
||||
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(())
|
||||
}
|
||||
|
||||
/// Downloads latest release of Path of Building
|
||||
#[derive(Debug)]
|
||||
struct VersionReq {
|
||||
pob_ver: String,
|
||||
min_rpob_ver: String,
|
||||
}
|
||||
|
||||
/// Fetches and evaluates compatibility table
|
||||
fn fetch_compatibility_info(game: Game) -> anyhow::Result<Vec<VersionReq>> {
|
||||
let compatibility_info_file_name = match game {
|
||||
Game::Poe1 => "Compatibility_pob1.lua",
|
||||
Game::Poe2 => "Compatibility_pob2.lua",
|
||||
};
|
||||
|
||||
let compatibility_info_file_url = &format!(
|
||||
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
|
||||
compatibility_info_file_name
|
||||
);
|
||||
|
||||
let compatibility_info_file = download_file_contents(compatibility_info_file_url)?;
|
||||
|
||||
// Load and evaluate compatibility file contents as Lua code
|
||||
let lua = mlua::Lua::new();
|
||||
let compatibility_table = lua.load(compatibility_info_file).eval::<mlua::Table>()?;
|
||||
|
||||
// Compatibility table maps PoB version to minimum required Rusty PoB version
|
||||
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,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Determines highest PoB version supported by given Rusty PoB version
|
||||
fn highest_supported_pob_version<'a>(
|
||||
compatibility_info: &'a Vec<VersionReq>,
|
||||
rpob_version: &str,
|
||||
) -> Option<&'a str> {
|
||||
let mut highest_pob_version = None;
|
||||
for VersionReq {
|
||||
pob_ver,
|
||||
min_rpob_ver,
|
||||
} in compatibility_info
|
||||
{
|
||||
if is_higher_version(min_rpob_ver, rpob_version).unwrap_or(false) {
|
||||
// found PoB version that meets our minimum requirements
|
||||
match highest_pob_version {
|
||||
// make sure it is the highest PoB version possible
|
||||
Some(h_pob_version) => {
|
||||
if is_higher_version(h_pob_version, pob_ver).unwrap_or(false) {
|
||||
highest_pob_version = Some(pob_ver.as_str());
|
||||
}
|
||||
}
|
||||
None => highest_pob_version = Some(pob_ver.as_str()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highest_pob_version
|
||||
}
|
||||
|
||||
/// Downloads specified version of Path of Building
|
||||
fn download_path_of_building<P: AsRef<Path>>(
|
||||
target_dir: P,
|
||||
game: Game,
|
||||
pob_version: &str,
|
||||
progress_tx: &mpsc::Sender<Progress>,
|
||||
) -> anyhow::Result<()> {
|
||||
log::info!("Downloading Path of Building assets...");
|
||||
|
||||
let repo = match Game::current() {
|
||||
let repo = match game {
|
||||
Game::Poe1 => "PathOfBuildingCommunity/PathOfBuilding",
|
||||
Game::Poe2 => "PathOfBuildingCommunity/PathOfBuilding-PoE2",
|
||||
};
|
||||
let url = format!(
|
||||
"https://github.com/{}/archive/refs/heads/master.tar.gz",
|
||||
repo
|
||||
"https://github.com/{}/archive/refs/tags/v{}.tar.gz",
|
||||
repo, pob_version
|
||||
);
|
||||
|
||||
let mut response = http_get_with_backoff(&url)?;
|
||||
@@ -267,10 +365,8 @@ fn download_path_of_building<P: AsRef<Path>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Replaces UpdateCheck with rusty-path-of-building's custom version of it.
|
||||
/// Replaces UpdateCheck with rusty-path-of-building's modified version
|
||||
fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
|
||||
log::info!("Downloading custom UpdateCheck.lua script...");
|
||||
|
||||
download_file(
|
||||
&format!(
|
||||
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
|
||||
@@ -279,6 +375,31 @@ fn replace_updatecheck<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()> {
|
||||
target_dir.as_ref().join("UpdateCheck.lua"),
|
||||
)?;
|
||||
|
||||
// Replace original checksum with checksum of modified update script
|
||||
let new_checksum = download_file_contents(&format!(
|
||||
"https://raw.githubusercontent.com/{REPO_NAME}/main/{}",
|
||||
"UpdateCheck.lua.sha1"
|
||||
))?;
|
||||
|
||||
// file contains checksum followed by filename (separated by whitespace)
|
||||
// we only need the checksum
|
||||
let new_checksum = new_checksum
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid checksum file"))?;
|
||||
|
||||
let filename = target_dir.as_ref().join("manifest.xml");
|
||||
let manifest = fs::read_to_string(&filename)?;
|
||||
|
||||
let new_manifest = replace_in_matching_lines(
|
||||
&manifest,
|
||||
r#"name="UpdateCheck.lua""#,
|
||||
r#"sha1="([0-9A-Za-z]+)""#,
|
||||
&format!(r#"sha1="{}""#, new_checksum),
|
||||
);
|
||||
|
||||
fs::write(&filename, &new_manifest)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -302,6 +423,7 @@ fn set_branch_and_platform<P: AsRef<Path>>(target_dir: P) -> anyhow::Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Downloads file and saves it to given path
|
||||
fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()> {
|
||||
let mut response = http_get_with_backoff(url)?;
|
||||
|
||||
@@ -311,7 +433,19 @@ fn download_file<P: AsRef<Path>>(url: &str, file_path: P) -> anyhow::Result<()>
|
||||
copy(&mut body.as_reader(), &mut file)?;
|
||||
Ok(())
|
||||
} else {
|
||||
bail!("Unable to download: {}", url);
|
||||
anyhow::bail!("Unable to download: {}", url);
|
||||
}
|
||||
}
|
||||
|
||||
/// Downloads file and returns contents as string
|
||||
fn download_file_contents(url: &str) -> anyhow::Result<String> {
|
||||
let mut response = http_get_with_backoff(url)?;
|
||||
|
||||
if response.status().is_success() {
|
||||
let body = response.body_mut();
|
||||
Ok(body.read_to_string()?)
|
||||
} else {
|
||||
anyhow::bail!("Unable to download: {}", url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,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();
|
||||
|
||||
@@ -432,3 +573,126 @@ fn http_get_with_backoff(url: &str) -> anyhow::Result<Response<ureq::Body>> {
|
||||
return Ok(resp);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 parse_version = |v: &str| -> anyhow::Result<(u32, u32, u32)> {
|
||||
let caps = VERSION_RE
|
||||
.captures(v)
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid semver format: {}", v))?;
|
||||
|
||||
let major = caps[1].parse::<u32>().unwrap();
|
||||
let minor = caps[2].parse::<u32>().unwrap();
|
||||
let patch = caps[3].parse::<u32>().unwrap();
|
||||
|
||||
Ok((major, minor, patch))
|
||||
};
|
||||
|
||||
let (major1, minor1, patch1) = parse_version(v1)?;
|
||||
let (major2, minor2, patch2) = parse_version(v2)?;
|
||||
|
||||
Ok(major2 > major1
|
||||
|| (major2 == major1 && minor2 > minor1)
|
||||
|| (major2 == major1 && minor2 == minor1 && patch2 >= patch1))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_major_version() {
|
||||
assert_eq!(is_higher_version("1.0.0", "2.0.0").unwrap(), true);
|
||||
assert_eq!(is_higher_version("2.0.0", "1.0.0").unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minor_version() {
|
||||
assert_eq!(is_higher_version("1.5.0", "1.6.0").unwrap(), true);
|
||||
assert_eq!(is_higher_version("1.10.0", "1.9.0").unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_patch_version() {
|
||||
assert_eq!(is_higher_version("1.0.3", "1.0.4").unwrap(), true);
|
||||
assert_eq!(is_higher_version("1.0.10", "1.0.9").unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_same_version() {
|
||||
assert_eq!(is_higher_version("1.5.3", "1.5.3").unwrap(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_semver_format() {
|
||||
assert!(is_higher_version("1.0", "2.0.0").is_err());
|
||||
assert!(is_higher_version("1.0.0", "2.0").is_err());
|
||||
assert!(is_higher_version("invalid", "2.0.0").is_err());
|
||||
assert!(is_higher_version("1.0.0", "a.bb.ccc").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_highest_supported_pob_ver() {
|
||||
let compat_info = vec![
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.56.0"),
|
||||
min_rpob_ver: String::from("0.1.0"),
|
||||
},
|
||||
// compat info might not be sorted by pob_version
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.58.0"),
|
||||
min_rpob_ver: String::from("0.2.6"),
|
||||
},
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.57.0"),
|
||||
min_rpob_ver: String::from("0.2.6"),
|
||||
},
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.58.1"),
|
||||
min_rpob_ver: String::from("0.2.8"),
|
||||
},
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.59.0"),
|
||||
min_rpob_ver: String::from("0.2.9"),
|
||||
},
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.59.1"),
|
||||
min_rpob_ver: String::from("0.2.10"),
|
||||
},
|
||||
VersionReq {
|
||||
pob_ver: String::from("2.59.2"),
|
||||
min_rpob_ver: String::from("0.2.10"),
|
||||
},
|
||||
];
|
||||
assert_eq!(highest_supported_pob_version(&compat_info, "0.0.2"), None);
|
||||
assert_eq!(highest_supported_pob_version(&compat_info, "a.b.c"), None);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.1.0"),
|
||||
Some("2.56.0")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.0"),
|
||||
Some("2.56.0")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.6"),
|
||||
Some("2.58.0")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.7"),
|
||||
Some("2.58.0")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.8"),
|
||||
Some("2.58.1")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.9"),
|
||||
Some("2.59.0")
|
||||
);
|
||||
assert_eq!(
|
||||
highest_supported_pob_version(&compat_info, "0.2.10"),
|
||||
Some("2.59.2")
|
||||
);
|
||||
}
|
||||
}
|
||||
+98
-57
@@ -1,5 +1,4 @@
|
||||
use crate::{
|
||||
Game,
|
||||
api::{self, get_callback},
|
||||
app::AppState,
|
||||
args::Args,
|
||||
@@ -12,16 +11,16 @@ use crate::{
|
||||
util::change_working_directory,
|
||||
window::WindowState,
|
||||
};
|
||||
use arboard::Clipboard;
|
||||
use clap::Parser;
|
||||
use mlua::{Lua, Result as LuaResult, Table};
|
||||
use mlua::{Function, Lua, Result as LuaResult, Table, ThreadStatus};
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
path::PathBuf,
|
||||
rc::Rc,
|
||||
};
|
||||
use winit::keyboard::SmolStr;
|
||||
|
||||
macro_rules! socket_accessor {
|
||||
macro_rules! ctx_accessor {
|
||||
($field:ident: & $ty:ty) => {
|
||||
pub fn $field(&self) -> &$ty {
|
||||
let ptr = self.$field.get();
|
||||
@@ -42,77 +41,82 @@ macro_rules! socket_accessor {
|
||||
|
||||
/// A collection of pointers needed by the API funtions.
|
||||
///
|
||||
/// Before executing any lua code, we need to "plug" the [`PoBContext`] into
|
||||
/// the ContextSocket and "unplug" them afterwards.
|
||||
pub struct ContextSocket {
|
||||
window: Cell<*const WindowState>,
|
||||
/// Before executing any lua code, we need to "plug" the references into
|
||||
/// the Context and "unplug" them afterwards.
|
||||
pub struct Context {
|
||||
window: Cell<*mut WindowState>,
|
||||
input: Cell<*const InputState>,
|
||||
fonts: Cell<*mut Fonts>,
|
||||
texture_manager: Cell<*mut WrappedTextureManager>,
|
||||
clipboard: Cell<*mut Clipboard>,
|
||||
script_dir: Cell<*const PathBuf>,
|
||||
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>,
|
||||
}
|
||||
|
||||
impl ContextSocket {
|
||||
impl Context {
|
||||
pub fn new() -> &'static Self {
|
||||
Box::leak(Box::new(Self {
|
||||
window: Cell::new(std::ptr::null()),
|
||||
window: Cell::new(std::ptr::null_mut()),
|
||||
input: Cell::new(std::ptr::null()),
|
||||
fonts: Cell::new(std::ptr::null_mut()),
|
||||
texture_manager: Cell::new(std::ptr::null_mut()),
|
||||
clipboard: Cell::new(std::ptr::null_mut()),
|
||||
script_dir: Cell::new(std::ptr::null()),
|
||||
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()),
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn set(&self, ctx: &mut PoBContext) {
|
||||
self.window.set(&ctx.app.window);
|
||||
self.window.set(&mut ctx.app.window);
|
||||
self.input.set(&ctx.app.input);
|
||||
self.fonts.set(&mut ctx.app.fonts);
|
||||
self.texture_manager.set(&mut ctx.app.texture_manager);
|
||||
self.clipboard.set(&mut ctx.app.clipboard);
|
||||
self.script_dir.set(&mut ctx.app.script_dir);
|
||||
self.current_working_dir
|
||||
.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);
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
self.window.set(std::ptr::null());
|
||||
self.window.set(std::ptr::null_mut());
|
||||
self.input.set(std::ptr::null());
|
||||
self.fonts.set(std::ptr::null_mut());
|
||||
self.texture_manager.set(std::ptr::null_mut());
|
||||
self.clipboard.set(std::ptr::null_mut());
|
||||
self.script_dir.set(std::ptr::null());
|
||||
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());
|
||||
}
|
||||
|
||||
socket_accessor!(window: &WindowState);
|
||||
socket_accessor!(input: &InputState);
|
||||
socket_accessor!(fonts: &mut Fonts);
|
||||
socket_accessor!(texture_manager: &mut WrappedTextureManager);
|
||||
socket_accessor!(clipboard: &mut Clipboard);
|
||||
socket_accessor!(current_working_dir: &mut PathBuf);
|
||||
socket_accessor!(layers: &mut Layers);
|
||||
socket_accessor!(needs_restart: &mut bool);
|
||||
socket_accessor!(is_dpi_aware: &mut bool);
|
||||
ctx_accessor!(window: &mut WindowState);
|
||||
ctx_accessor!(input: &InputState);
|
||||
ctx_accessor!(fonts: &mut Fonts);
|
||||
ctx_accessor!(texture_manager: &mut WrappedTextureManager);
|
||||
ctx_accessor!(script_dir: &PathBuf);
|
||||
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);
|
||||
}
|
||||
|
||||
pub enum PoBEvent {
|
||||
Init,
|
||||
Exit,
|
||||
Frame,
|
||||
KeyDown(&'static str, bool),
|
||||
KeyUp(&'static str),
|
||||
KeyDown(SmolStr, bool),
|
||||
KeyUp(SmolStr),
|
||||
Char(char),
|
||||
SubFinished {
|
||||
id: u64,
|
||||
@@ -160,10 +164,10 @@ pub struct LuaInstance {
|
||||
}
|
||||
|
||||
impl LuaInstance {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
let subscript_manager = Rc::new(RefCell::new(SubscriptManager::new()));
|
||||
pub fn new(script_dir: &PathBuf) -> anyhow::Result<Self> {
|
||||
let subscript_manager = Rc::new(RefCell::new(SubscriptManager::new(script_dir.to_owned())));
|
||||
|
||||
let lua = Self::create_lua_state()?;
|
||||
let lua = Self::create_lua_state(script_dir)?;
|
||||
register_subscript_globals(&lua, &subscript_manager)?;
|
||||
|
||||
Ok(Self {
|
||||
@@ -172,20 +176,20 @@ impl LuaInstance {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_lua_state() -> LuaResult<Lua> {
|
||||
fn create_lua_state(script_dir: &PathBuf) -> LuaResult<Lua> {
|
||||
// SAFETY: use `unsafe_new` to allow loading of C modules
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
|
||||
// expose build arg to lua
|
||||
// expose import url to lua
|
||||
let args = Args::parse();
|
||||
let args_table = lua.create_sequence_from(std::iter::once(args.build_path))?;
|
||||
let args_table = lua.create_sequence_from(std::iter::once(args.import_url))?;
|
||||
lua.globals().set("arg", args_table)?;
|
||||
|
||||
Self::register_package_paths(&lua)?;
|
||||
Self::register_package_paths(&lua, script_dir)?;
|
||||
|
||||
// register "socket"
|
||||
let socket = ContextSocket::new();
|
||||
lua.set_app_data(socket);
|
||||
// register context
|
||||
let ctx = Context::new();
|
||||
lua.set_app_data(ctx);
|
||||
|
||||
// register callbacks
|
||||
api::register_globals(&lua)?;
|
||||
@@ -194,52 +198,90 @@ impl LuaInstance {
|
||||
}
|
||||
|
||||
/// Loads and executes PoB's Launch.lua script
|
||||
pub fn launch(&self, ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
let socket = self.lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.set(ctx);
|
||||
pub fn launch(&self, pob_ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.set(pob_ctx);
|
||||
|
||||
let script_dir = Game::script_dir();
|
||||
change_working_directory(script_dir.as_path())?;
|
||||
let script_dir = pob_ctx.app.script_dir.as_path();
|
||||
change_working_directory(script_dir)?;
|
||||
self.load(script_dir.join("Launch.lua")).exec()?;
|
||||
|
||||
socket.clear();
|
||||
ctx.clear();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn restart(&mut self, ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
self.lua = Self::create_lua_state()?;
|
||||
self.lua = Self::create_lua_state(&ctx.app.script_dir)?;
|
||||
register_subscript_globals(&self.lua, &self.subscript_manager)?;
|
||||
self.launch(ctx)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run functions for subscripts and handle their completion/failure.
|
||||
pub fn handle_subscripts(&self, ctx: &mut PoBContext) {
|
||||
pub fn handle_subscripts(&self, pob_ctx: &mut PoBContext) {
|
||||
profiling::scope!("handle_subscripts");
|
||||
|
||||
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.set(pob_ctx);
|
||||
let subscript_events = self.subscript_manager.borrow_mut().process(self);
|
||||
ctx.clear();
|
||||
|
||||
// Handle finished/errored subscripts.
|
||||
for event in subscript_events {
|
||||
match event {
|
||||
SubscriptResult::SubscriptFinished { id, return_values } => {
|
||||
self.handle_event(PoBEvent::SubFinished { id, return_values }, ctx)
|
||||
self.handle_event(PoBEvent::SubFinished { id, return_values }, pob_ctx)
|
||||
.unwrap();
|
||||
}
|
||||
SubscriptResult::SubscriptError { id, error } => {
|
||||
self.handle_event(PoBEvent::SubError { id, error }, ctx)
|
||||
self.handle_event(PoBEvent::SubError { id, error }, pob_ctx)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_event(&self, event: PoBEvent, ctx: &mut PoBContext) -> LuaResult<()> {
|
||||
pub fn has_running_subscripts(&self) -> bool {
|
||||
self.subscript_manager.borrow().has_running_subscripts()
|
||||
}
|
||||
|
||||
pub fn has_active_coroutine(&self) -> bool {
|
||||
self.get_coroutines().is_ok_and(|coroutines| {
|
||||
coroutines.pairs::<mlua::Thread, bool>().any(|pair| {
|
||||
pair.is_ok_and(|(thread, _)| {
|
||||
matches!(
|
||||
thread.status(),
|
||||
ThreadStatus::Resumable | ThreadStatus::Running
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn get_coroutines(&self) -> LuaResult<Table> {
|
||||
let coroutine_module: Table = self.lua.globals().get("coroutine")?;
|
||||
let list_func: Function = coroutine_module.get("_list")?;
|
||||
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));
|
||||
|
||||
// "Plug" references into "socket"
|
||||
let socket = self.lua.app_data_ref::<&'static ContextSocket>().unwrap();
|
||||
socket.set(ctx);
|
||||
// "Plug" references into context
|
||||
let ctx = self.lua.app_data_ref::<&'static Context>().unwrap();
|
||||
ctx.set(pob_ctx);
|
||||
|
||||
// Call event handler in PoB application code
|
||||
let handler_result = match event {
|
||||
@@ -247,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))
|
||||
@@ -259,15 +301,14 @@ impl LuaInstance {
|
||||
}
|
||||
};
|
||||
|
||||
// "Unplug" references from "socket"
|
||||
socket.clear();
|
||||
// "Unplug" references from context
|
||||
ctx.clear();
|
||||
|
||||
handler_result
|
||||
}
|
||||
|
||||
/// Adds "${script_dir}/lua" to package path
|
||||
pub fn register_package_paths(lua: &Lua) -> LuaResult<()> {
|
||||
let script_dir = Game::script_dir();
|
||||
pub fn register_package_paths(lua: &Lua, script_dir: &PathBuf) -> LuaResult<()> {
|
||||
let package: Table = lua.globals().get("package")?;
|
||||
let mut package_path: String = package.get("path")?;
|
||||
package_path.push(';');
|
||||
|
||||
+26
-6
@@ -1,13 +1,12 @@
|
||||
use crate::{
|
||||
app::App,
|
||||
args::{Args, Game},
|
||||
};
|
||||
use crate::{app::App, args::Args};
|
||||
use clap::Parser;
|
||||
use std::path::{Path, PathBuf};
|
||||
use winit::event_loop::EventLoop;
|
||||
|
||||
mod api;
|
||||
mod app;
|
||||
mod args;
|
||||
mod clipboard;
|
||||
mod color;
|
||||
mod dpi;
|
||||
mod fonts;
|
||||
@@ -39,12 +38,33 @@ fn main() -> anyhow::Result<()> {
|
||||
};
|
||||
|
||||
let args = Args::parse();
|
||||
Game::init(args.game);
|
||||
let script_dir = find_nearby_launch_script();
|
||||
|
||||
let mut app = App::new()?;
|
||||
let mut app = App::new(args.game, script_dir)?;
|
||||
|
||||
let event_loop = EventLoop::with_user_event().build()?;
|
||||
event_loop.run_app(&mut app)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Search for the Launch.lua file in nearby locations
|
||||
fn find_nearby_launch_script() -> Option<PathBuf> {
|
||||
let mut candidates = vec![Path::new("Launch.lua"), Path::new("src/Launch.lua")];
|
||||
|
||||
if let Ok(cwd) = std::env::current_dir()
|
||||
&& cwd.ends_with("runtime")
|
||||
{
|
||||
candidates.push(Path::new("../src/Launch.lua"));
|
||||
}
|
||||
|
||||
for candidate in candidates {
|
||||
if candidate.try_exists().is_ok_and(|exists| exists) {
|
||||
if let Some(Ok(candidate)) = candidate.parent().map(Path::canonicalize) {
|
||||
return Some(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
+13
-3
@@ -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,
|
||||
@@ -34,6 +34,9 @@ pub enum ModeTransition {
|
||||
pub struct ModeFrameOutput {
|
||||
pub primitives: Box<dyn Iterator<Item = ClippedPrimitive>>,
|
||||
pub can_elide: bool,
|
||||
/// Indicates that this should be redrawn again next frame even if user is not interacting with
|
||||
/// window
|
||||
pub should_continue: bool,
|
||||
}
|
||||
|
||||
pub enum AppMode {
|
||||
@@ -62,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),
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-10
@@ -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},
|
||||
@@ -34,7 +34,7 @@ impl PoBMode {
|
||||
is_dpi_aware: false,
|
||||
};
|
||||
|
||||
let lua_instance = LuaInstance::new()?;
|
||||
let lua_instance = LuaInstance::new(&app_state.script_dir)?;
|
||||
|
||||
let mut pob_ctx = PoBContext::new(app_state, &mut state);
|
||||
lua_instance.launch(&mut pob_ctx)?;
|
||||
@@ -68,9 +68,14 @@ impl PoBMode {
|
||||
let identical = layers_hash == self.previous_layers_hash;
|
||||
self.previous_layers_hash = layers_hash;
|
||||
|
||||
let has_active_subscript = self.lua_instance.has_running_subscripts();
|
||||
let has_active_coroutine = self.lua_instance.has_active_coroutine();
|
||||
let should_continue = has_active_subscript || has_active_coroutine;
|
||||
|
||||
Ok(ModeFrameOutput {
|
||||
primitives: self.state.layers.consume_layers(),
|
||||
can_elide: identical,
|
||||
should_continue,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,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)?;
|
||||
}
|
||||
@@ -122,17 +127,18 @@ 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 } => {
|
||||
let ch = if ch.is_ascii() { ch } else { '?' };
|
||||
self.lua_instance
|
||||
.handle_event(PoBEvent::Char(ch), &mut ctx)?;
|
||||
}
|
||||
@@ -141,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
|
||||
|
||||
+21
-13
@@ -1,14 +1,14 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{Receiver, Sender, TryRecvError};
|
||||
use std::{collections::VecDeque, sync::mpsc::channel, thread::JoinHandle};
|
||||
|
||||
use crate::{api::get_callback, lua::LuaInstance};
|
||||
use anyhow::{Result, anyhow};
|
||||
use mlua::{Function, IntoLuaMulti, Lua, Value};
|
||||
use mlua::{Integer, MultiValue, Number, Result as LuaResult};
|
||||
|
||||
use crate::api::get_callback;
|
||||
use crate::lua::LuaInstance;
|
||||
use mlua::{Function, Integer, IntoLuaMulti, Lua, MultiValue, Number, Result as LuaResult, Value};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::VecDeque,
|
||||
path::PathBuf,
|
||||
rc::Rc,
|
||||
sync::mpsc::{Receiver, Sender, TryRecvError, channel},
|
||||
thread::JoinHandle,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SubscriptResult {
|
||||
@@ -25,13 +25,15 @@ pub enum SubscriptResult {
|
||||
pub struct SubscriptManager {
|
||||
current_id: u64,
|
||||
scripts: Vec<Subscript>,
|
||||
script_dir: PathBuf,
|
||||
}
|
||||
|
||||
impl SubscriptManager {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(script_dir: PathBuf) -> Self {
|
||||
Self {
|
||||
current_id: 0,
|
||||
scripts: Vec::new(),
|
||||
script_dir,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +53,7 @@ impl SubscriptManager {
|
||||
blocking_calls,
|
||||
nonblocking_calls,
|
||||
arguments,
|
||||
self.script_dir.clone(),
|
||||
);
|
||||
self.scripts.push(subscript);
|
||||
id
|
||||
@@ -74,6 +77,10 @@ impl SubscriptManager {
|
||||
|
||||
results
|
||||
}
|
||||
|
||||
pub fn has_running_subscripts(&self) -> bool {
|
||||
!self.scripts.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
enum SubscriptCall {
|
||||
@@ -115,6 +122,7 @@ impl Subscript {
|
||||
blocking_calls: Vec<String>,
|
||||
nonblocking_calls: Vec<String>,
|
||||
arguments: NativeMultiValue,
|
||||
script_dir: PathBuf,
|
||||
) -> Self {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
@@ -125,7 +133,7 @@ impl Subscript {
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
|
||||
// add ./lua to package.path and package.cpath
|
||||
LuaInstance::register_package_paths(&lua)?;
|
||||
LuaInstance::register_package_paths(&lua, &script_dir)?;
|
||||
|
||||
for function_name in blocking_calls {
|
||||
let thread_tx = tx.clone();
|
||||
@@ -305,7 +313,7 @@ pub fn register_subscript_globals(
|
||||
"IsSubScriptRunning",
|
||||
lua.create_function(is_subscript_running)?,
|
||||
)?;
|
||||
globals.set("IsSubScriptRunning", lua.create_function(abort_subscript)?)?;
|
||||
globals.set("AbortSubScript", lua.create_function(abort_subscript)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+25
@@ -27,3 +27,28 @@ pub fn calculate_hash<T: Hash>(t: &T) -> u64 {
|
||||
t.hash(&mut state);
|
||||
state.finish()
|
||||
}
|
||||
|
||||
/// Performs replacement only in lines that match a given pattern
|
||||
pub fn replace_in_matching_lines(
|
||||
input: &str,
|
||||
match_pattern: &str,
|
||||
replace_pattern: &str,
|
||||
replacement_text: &str,
|
||||
) -> String {
|
||||
let match_re = regex::Regex::new(match_pattern).expect("Invalid match regex");
|
||||
let replace_re = regex::Regex::new(replace_pattern).expect("Invalid replace regex");
|
||||
|
||||
let mut output = String::new();
|
||||
for line in input.lines() {
|
||||
if match_re.is_match(line) {
|
||||
// if line matches the pattern, replace
|
||||
let replaced_line = replace_re.replace_all(line, replacement_text);
|
||||
output.push_str(&replaced_line);
|
||||
} else {
|
||||
// otherwise, keep original line
|
||||
output.push_str(line);
|
||||
}
|
||||
output.push('\n');
|
||||
}
|
||||
output
|
||||
}
|
||||
+50
-5
@@ -1,14 +1,21 @@
|
||||
use crate::{
|
||||
clipboard::Clipboard,
|
||||
dpi::{ConvertToLogical, LogicalSize, PhysicalSize},
|
||||
};
|
||||
use raw_window_handle::HasDisplayHandle;
|
||||
use std::sync::Arc;
|
||||
|
||||
use winit::window::Window;
|
||||
|
||||
use crate::dpi::{ConvertToLogical, LogicalSize, PhysicalSize};
|
||||
|
||||
pub struct WindowState {
|
||||
// NOTE: clipboard needs to be destroyed before window
|
||||
clipboard: Option<Clipboard>,
|
||||
pub window: Option<Arc<Window>>,
|
||||
pub size: PhysicalSize<u32>,
|
||||
pub scale_factor: f32,
|
||||
scale_factor: f32,
|
||||
pub scale_factor_override: Option<f32>,
|
||||
pending_window_title: std::cell::Cell<Option<String>>,
|
||||
pub is_hovered: bool,
|
||||
pub is_focused: bool,
|
||||
}
|
||||
|
||||
impl Default for WindowState {
|
||||
@@ -17,7 +24,11 @@ impl Default for WindowState {
|
||||
window: None,
|
||||
size: Default::default(),
|
||||
scale_factor: 1.0,
|
||||
scale_factor_override: None,
|
||||
pending_window_title: std::cell::Cell::new(None),
|
||||
clipboard: None,
|
||||
is_hovered: true,
|
||||
is_focused: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +39,12 @@ impl WindowState {
|
||||
window.set_title(&title);
|
||||
}
|
||||
|
||||
let winit::dpi::PhysicalSize { width, height } = window.inner_size();
|
||||
self.size = PhysicalSize::new(width, height);
|
||||
self.scale_factor = window.scale_factor() as f32;
|
||||
|
||||
let raw_display_handle = window.display_handle().ok().map(|h| h.as_raw());
|
||||
self.clipboard = Some(Clipboard::new(raw_display_handle));
|
||||
self.window = Some(window);
|
||||
}
|
||||
|
||||
@@ -40,7 +57,15 @@ impl WindowState {
|
||||
}
|
||||
|
||||
pub fn logical_size(&self) -> LogicalSize<u32> {
|
||||
self.size.to_logical(self.scale_factor)
|
||||
self.size.to_logical(self.scale_factor())
|
||||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f32 {
|
||||
self.scale_factor_override.unwrap_or(self.scale_factor)
|
||||
}
|
||||
|
||||
pub fn set_scale_factor(&mut self, scale_factor: f32) {
|
||||
self.scale_factor = scale_factor;
|
||||
}
|
||||
|
||||
pub fn focus(&self) {
|
||||
@@ -48,4 +73,24 @@ impl WindowState {
|
||||
window.focus_window();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_clipboard_text(&mut self, text: String) {
|
||||
if let Some(clipboard) = &mut self.clipboard {
|
||||
clipboard.set_text(text);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_clipboard_text(&mut self) -> Option<String> {
|
||||
if let Some(clipboard) = &mut self.clipboard {
|
||||
clipboard.get_text()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_redraw(&self) {
|
||||
if let Some(ref window) = self.window {
|
||||
window.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user