diff --git a/Cargo.lock b/Cargo.lock index dd5deb7..aabed1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5237,7 +5237,7 @@ dependencies = [ [[package]] name = "zaapy" -version = "1.1.0" +version = "1.2.0" dependencies = [ "serde", "serde_json", @@ -5255,7 +5255,7 @@ dependencies = [ [[package]] name = "zaapy-core" -version = "1.1.0" +version = "1.2.0" dependencies = [ "serde", "serde_json", @@ -5264,7 +5264,7 @@ dependencies = [ [[package]] name = "zaapy-platform" -version = "1.1.0" +version = "1.2.0" dependencies = [ "objc2", "objc2-app-kit", diff --git a/Cargo.toml b/Cargo.toml index cfed24b..46e866d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/zaapy-core", "crates/zaapy-platform", "src-tauri"] [workspace.package] -version = "1.1.0" +version = "1.2.0" edition = "2021" license = "MIT" repository = "https://github.com/Miniluchi/zaapy" diff --git a/README.md b/README.md index 11976ae..bf23fb4 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ Download the latest version from the | System | File | | ------- | ----------------------------------------------------- | -| Windows | `Zaapy_1.1.0_x64-setup.exe` | -| macOS | `Zaapy_1.1.0_universal.dmg` (Intel and Apple Silicon) | +| Windows | `Zaapy_1.2.0_x64-setup.exe` | +| macOS | `Zaapy_1.2.0_universal.dmg` (Intel and Apple Silicon) | Zaapy isn't code signed — the certificates cost more per year than this free project does — so both systems will warn you the first time. @@ -66,8 +66,8 @@ settings. By default the Dofus chat keeps the keyboard after a command. Tick **Press Escape** in the settings to hand it back to the game. -`/zaap` is greyed out for now. Ankama has announced the command but it does not -exist in the game yet; Zaapy will support it when it ships. +`/zaap` commands, chained `/travel` included, are relayed the same way. Turn +them off with **/zaap** in the settings. ## Privacy diff --git a/crates/zaapy-core/src/bridge.rs b/crates/zaapy-core/src/bridge.rs index ecf1e6d..88c687f 100644 --- a/crates/zaapy-core/src/bridge.rs +++ b/crates/zaapy-core/src/bridge.rs @@ -65,7 +65,7 @@ pub enum IgnoreReason { verb: Verb, foreground: Option, }, - /// A known command the user has switched off — `/zaap` until it ships. + /// A known command the user has switched off. CommandDisabled { verb: Verb, }, diff --git a/crates/zaapy-core/src/command.rs b/crates/zaapy-core/src/command.rs index 9c1609f..679ade1 100644 --- a/crates/zaapy-core/src/command.rs +++ b/crates/zaapy-core/src/command.rs @@ -47,11 +47,12 @@ pub enum GameCommand { x: i32, y: i32, }, - /// Announced by Ankama but not yet live in game. Parsed so that enabling it - /// later is a configuration switch rather than a redesign; the argument - /// grammar is intentionally loose until the real one exists. + /// Teleport to the zaap nearest `x,y`. Guides may chain a `/travel` for the + /// last leg, which the game runs once the teleport lands. Zaap { - destination: String, + x: i32, + y: i32, + then: Option<(i32, i32)>, }, Item { name: String, @@ -74,7 +75,12 @@ impl GameCommand { pub fn canonical(&self) -> String { match self { GameCommand::Travel { x, y } => format!("/travel {x},{y}"), - GameCommand::Zaap { destination } => format!("/zaap {destination}"), + GameCommand::Zaap { x, y, then: None } => format!("/zaap {x} {y}"), + GameCommand::Zaap { + x, + y, + then: Some((tx, ty)), + } => format!("/zaap {x} {y} ; /travel {tx} {ty}"), GameCommand::Item { name } => name.clone(), } } @@ -134,7 +140,12 @@ pub fn parse(raw: &str) -> Result { } fn parse_travel(args: &str) -> Result { - let bad = || Rejection::BadArguments { verb: Verb::Travel }; + let (x, y) = parse_coordinates(args, Verb::Travel)?; + Ok(GameCommand::Travel { x, y }) +} + +fn parse_coordinates(args: &str, verb: Verb) -> Result<(i32, i32), Rejection> { + let bad = || Rejection::BadArguments { verb }; // Guides write `1,2`; the treasure-hunt overlay writes `1 2`. let (x, y) = match args.split_once(',') { Some((x, y)) => (x.trim(), y.trim()), @@ -145,25 +156,23 @@ fn parse_travel(args: &str) -> Result { if x.abs() > COORDINATE_BOUND || y.abs() > COORDINATE_BOUND { return Err(bad()); } - Ok(GameCommand::Travel { x, y }) + Ok((x, y)) } +/// `/zaap x y`, optionally chained with `; /travel x y` — and nothing else may +/// follow the `;`, since the game runs whatever command sits there. fn parse_zaap(args: &str) -> Result { - let bad = || Rejection::BadArguments { verb: Verb::Zaap }; - if args.is_empty() { - return Err(bad()); - } - // Until the real grammar ships, accept what a place name plausibly contains - // and nothing that could be read as punctuation by the chat parser. - let acceptable = args - .chars() - .all(|c| c.is_alphanumeric() || matches!(c, ' ' | '-' | '_' | '\'' | ',')); - if !acceptable { - return Err(bad()); - } - Ok(GameCommand::Zaap { - destination: args.to_string(), - }) + let (head, tail) = match args.split_once(';') { + Some((head, tail)) => (head, Some(tail)), + None => (args, None), + }; + let (x, y) = parse_coordinates(head.trim(), Verb::Zaap)?; + let then = match tail.map(parse) { + None => None, + Some(Ok(GameCommand::Travel { x, y })) => Some((x, y)), + Some(_) => return Err(Rejection::BadArguments { verb: Verb::Zaap }), + }; + Ok(GameCommand::Zaap { x, y, then }) } /// Text with no letter in it — a number, a stray symbol — is not an item name. @@ -293,17 +302,45 @@ mod tests { } #[test] - fn parses_zaap_ahead_of_its_release() { + fn accepts_ganymede_zaap_commands() { assert_eq!( - parse("/zaap Astrub"), + parse("/zaap 5 7"), Ok(GameCommand::Zaap { - destination: "Astrub".to_string() + x: 5, + y: 7, + then: None }) ); + let chained = parse("/zaap -31 -56 ; /travel -32 -57").unwrap(); assert_eq!( - parse("/zaap"), - Err(Rejection::BadArguments { verb: Verb::Zaap }) + chained, + GameCommand::Zaap { + x: -31, + y: -56, + then: Some((-32, -57)) + } ); + assert_eq!(parse(&chained.canonical()), Ok(chained)); + } + + #[test] + fn rejects_malformed_zaap_commands() { + for payload in [ + "/zaap", + "/zaap Astrub", + "/zaap 1 2 ;", + "/zaap 1 2 ; /who", + "/zaap 1 2 ; /zaap 3 4", + "/zaap 1 2 ; /travel 3 4 ; /travel 5 6", + "/zaap 1 2 ; Bottes", + "/zaap 99999 0", + ] { + assert_eq!( + parse(payload), + Err(Rejection::BadArguments { verb: Verb::Zaap }), + "payload: {payload}" + ); + } } #[test] diff --git a/crates/zaapy-core/src/config.rs b/crates/zaapy-core/src/config.rs index 1c10f48..03f550e 100644 --- a/crates/zaapy-core/src/config.rs +++ b/crates/zaapy-core/src/config.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::command::Verb; use crate::platform::{Key, Modifier, SendStep, WindowRef}; -pub const CONFIG_VERSION: u32 = 1; +pub const CONFIG_VERSION: u32 = 2; /// Bounds on the focus confirmation wait. Below the floor the game has no time /// to come forward; above the ceiling the user is just staring at a frozen guide. @@ -77,6 +77,12 @@ impl Config { self.paste_sequence = default_paste_sequence(); } self.source_processes.retain(|name| !name.trim().is_empty()); + // Version 1 saved `/zaap` off while it was not in the game yet, behind a + // toggle the user could not reach. + if self.version < 2 { + self.commands.zaap = true; + } + self.version = CONFIG_VERSION; self } @@ -125,8 +131,6 @@ impl TargetSelector { #[serde(default)] pub struct EnabledCommands { pub travel: bool, - /// Off by default: the command does not exist in game yet, so relaying it - /// would only type a rejected line into the chat. pub zaap: bool, /// Item names clicked in Ganymède, pasted without opening the chat. pub items: bool, @@ -136,7 +140,7 @@ impl Default for EnabledCommands { fn default() -> Self { Self { travel: true, - zaap: false, + zaap: true, items: true, } } @@ -230,10 +234,22 @@ mod tests { } #[test] - fn zaap_stays_off_until_ankama_ships_it() { + fn travel_and_zaap_are_on_by_default() { let config = Config::default(); assert!(config.commands.allows(Verb::Travel)); - assert!(!config.commands.allows(Verb::Zaap)); + assert!(config.commands.allows(Verb::Zaap)); + } + + #[test] + fn zaap_is_switched_on_once_for_a_version_1_file() { + let saved = r#"{"version":1,"commands":{"travel":true,"zaap":false,"items":true}}"#; + let config = serde_json::from_str::(saved).unwrap().sanitised(); + assert!(config.commands.zaap); + assert_eq!(config.version, CONFIG_VERSION); + + let saved = r#"{"version":2,"commands":{"travel":true,"zaap":false,"items":true}}"#; + let config = serde_json::from_str::(saved).unwrap().sanitised(); + assert!(!config.commands.zaap); } #[test] diff --git a/crates/zaapy-core/tests/bridge.rs b/crates/zaapy-core/tests/bridge.rs index befcdb4..db40694 100644 --- a/crates/zaapy-core/tests/bridge.rs +++ b/crates/zaapy-core/tests/bridge.rs @@ -282,33 +282,35 @@ fn text_that_is_neither_a_command_nor_an_item_is_ignored() { } #[test] -fn zaap_is_recognised_but_not_relayed_until_it_ships() { +fn a_chained_zaap_is_relayed_through_the_chat() { let (rig, mut bridge) = armed(config()); - rig.clipboard.copy("/zaap Astrub"); + rig.clipboard.copy("/zaap -31 -56 ; /travel -32 -57"); let report = bridge.tick().unwrap(); - assert_eq!( + assert!(matches!( report.outcome, - Outcome::Ignored { - reason: IgnoreReason::CommandDisabled { verb: Verb::Zaap } - } - ); - assert!(rig.input.sends().is_empty()); + Outcome::Sent { ref command, .. } if command == "/zaap -31 -56 ; /travel -32 -57" + )); + assert_eq!(rig.input.sends(), vec![config().send_sequence]); } #[test] -fn enabling_zaap_is_a_single_switch() { +fn zaap_can_be_switched_off() { let mut config = config(); - config.commands.zaap = true; + config.commands.zaap = false; let (rig, mut bridge) = armed(config); - rig.clipboard.copy("/zaap Astrub"); - assert!(matches!( - bridge.tick().unwrap().outcome, - Outcome::Sent { .. } - )); - assert_eq!(rig.input.sends().len(), 1); + rig.clipboard.copy("/zaap 5 7"); + let report = bridge.tick().unwrap(); + + assert_eq!( + report.outcome, + Outcome::Ignored { + reason: IgnoreReason::CommandDisabled { verb: Verb::Zaap } + } + ); + assert!(rig.input.sends().is_empty()); } /// Clipboard notifications like to fire twice for one copy. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 6ec54ad..db801fd 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -157,8 +157,8 @@ key's `i` marker, which is a mark in a line of text rather than a control — fallback face. Explanations too long for a label go in a native `title` tooltip, which both -WKWebView and WebView2 render themselves: the `/zaap` row says why it is greyed -out, and the chat key says which keybind it has to match. A tooltip nobody hovers +WKWebView and WebView2 render themselves: the Items row says where the name +lands, and the chat key says which keybind it has to match. A tooltip nobody hovers is invisible, so the ones worth reading are marked. Nothing is offered that cannot be acted on: `HostStatus::can_request_permission` diff --git a/docs/VISION.md b/docs/VISION.md index d0505a8..7459652 100644 --- a/docs/VISION.md +++ b/docs/VISION.md @@ -42,7 +42,7 @@ A Dofus 3 player following a Ganymède guide, on **Windows or macOS**, possibly | macOS permissions | **Accessibility**, asked for from the settings window. The source gate works without it, so nothing is ever sent from an unpermitted install — the panel says what is missing instead | | Trigger | Fully automatic and immediate, **gated**: the command is only bridged if Ganymède was the foreground window when it appeared in the clipboard | | Source app | Ganymède **desktop app** (detected by process/window, no browser support) | -| Commands relayed | `/travel` today, from guides and from the treasure-hunt overlay; `/zaap` designed for but not active (see open questions) | +| Commands relayed | `/travel`, from guides and from the treasure-hunt overlay; `/zaap x y`, optionally chained with `; /travel x y`, since Dofus 3.7 | | Items | An item name clicked in Ganymède is **pasted** into Dofus as is — no chat, no `Enter` — into whatever field is open there, typically the auction house search | | Dofus target | **Manual selection** of the client window inside Zaapy — the user picks it, Zaapy remembers it | | Focus after send | **Stays on Dofus** — no automatic return to Ganymède | @@ -66,8 +66,7 @@ A Dofus 3 player following a Ganymède guide, on **Windows or macOS**, possibly These are deliberately left undecided here: -1. **`/zaap` support.** Announced but not yet implemented in-game. Only `/travel` works today, so the command handling must be able to accept `/zaap` later without a redesign — but the exact trigger and formatting cannot be locked in until Ankama ships it. -2. **Distribution.** Signed installers, notarization, and auto-update only become relevant at the public-release step — but they constrain packaging choices made earlier. +1. **Distribution.** Signed installers, notarization, and auto-update only become relevant at the public-release step — but they constrain packaging choices made earlier. ## 9. Beyond v1 — non-committal directions @@ -88,6 +87,6 @@ That said, whether this kind of tooling is acceptable under Ankama's terms of se - **Ganymède** — companion app providing Dofus guides; copies `/travel` commands, and item names, to the clipboard on click. - **Dofus 3** — the game client Zaapy sends commands to. - **`/travel x,y`** — in-game chat command that sends the character to the map at those coordinates. -- **Zaap** — in-game teleportation network; the basis for the announced `/zaap` command. +- **Zaap** — in-game teleportation network; the basis for the `/zaap` command. - **Bridge** — Zaapy's core job: turning a clipboard event in one window into a keyboard event in another. - **Target window** — the specific Dofus client the user selected to receive commands. diff --git a/src/App.svelte b/src/App.svelte index b4d2440..678298b 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -219,11 +219,17 @@ /> /travel - -