ravensight-playtest 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -16
- package/addons/desktop/RavensightDesktop.swift +367 -0
- package/addons/mobile/UITests/MobileInputTests.swift +67 -1
- package/addons/ravensight_driver/driver.gd +557 -4
- package/docs/ADAPTERS.md +37 -7
- package/docs/DESKTOP.md +117 -0
- package/docs/MOBILE.md +30 -3
- package/docs/UNITY.md +149 -0
- package/docs/UNREAL.md +123 -0
- package/docs/godot-driver.md +98 -1
- package/package.json +15 -5
- package/src/cli.js +26 -10
- package/src/commands/build.js +40 -0
- package/src/commands/fakeCore.js +1 -1
- package/src/commands/feature.js +1 -1
- package/src/commands/hosted.js +78 -9
- package/src/commands/run.js +47 -13
- package/src/commands/validate.js +1 -1
- package/src/commands/validateHosted.js +4 -1
- package/src/hosted/archivePreflight.js +31 -4
- package/src/hosted/buildStatus.js +26 -0
- package/src/hosted/buildUpload.js +39 -22
- package/src/hosted/nativeBuild.js +87 -0
- package/src/hosted/recordedRun.js +15 -3
- package/src/run/anygame/genre.js +98 -24
- package/src/run/anygame/genre2d.js +108 -0
- package/src/run/anygame/index.js +33 -7
- package/src/run/anygame/memory.js +31 -0
- package/src/run/anygame/scene3d.js +562 -0
- package/src/run/anygame/shared-hashes.json +5 -3
- package/src/run/anygame/shared.js +3 -3
- package/src/run/args.js +15 -4
- package/src/run/drivers/desktop/app.js +104 -0
- package/src/run/drivers/desktop/common.js +336 -0
- package/src/run/drivers/desktop/driver.js +383 -0
- package/src/run/drivers/desktop/helper.js +98 -0
- package/src/run/drivers/desktop/keys.js +124 -0
- package/src/run/drivers/desktop/output.js +107 -0
- package/src/run/drivers/desktop/preflight.js +134 -0
- package/src/run/drivers/desktop3d.js +106 -0
- package/src/run/drivers/desktopSequence.js +72 -0
- package/src/run/drivers/godot-3d.js +298 -0
- package/src/run/drivers/godot.js +465 -30
- package/src/run/drivers/index.js +6 -0
- package/src/run/drivers/mobile/adb.js +25 -1
- package/src/run/drivers/mobile/frame.js +3 -2
- package/src/run/drivers/mobile/gestures.js +76 -0
- package/src/run/drivers/mobile/lock.js +51 -11
- package/src/run/drivers/mobile/multitouch.js +150 -0
- package/src/run/drivers/mobile/native.js +229 -31
- package/src/run/drivers/mobile/preflight.js +14 -1
- package/src/run/drivers/mobile/target.js +21 -1
- package/src/run/drivers/stdio.js +150 -12
- package/src/run/drivers/unity/app.js +72 -0
- package/src/run/drivers/unity/engine.js +58 -0
- package/src/run/drivers/unity/link.js +108 -0
- package/src/run/drivers/unity/logs.js +76 -0
- package/src/run/drivers/unreal/app.js +40 -0
- package/src/run/drivers/unreal/driver.js +686 -0
- package/src/run/drivers/unreal/frames.js +243 -0
- package/src/run/drivers/unreal/logs.js +276 -0
- package/src/run/drivers/unreal/preflight.js +61 -0
- package/src/run/drivers/web.js +211 -13
- package/src/run/drivers/webdriver.js +79 -12
- package/src/run/endScreen.js +88 -0
- package/src/run/engineErrors.js +16 -0
- package/src/run/featureLoop.js +1 -1
- package/src/run/fingers.js +99 -0
- package/src/run/focusForKeys.js +54 -0
- package/src/run/gameMemory.js +4 -3
- package/src/run/godotTesterProbes.js +21 -2
- package/src/run/honesty.js +11 -1
- package/src/run/inputs.js +3 -3
- package/src/run/intent.js +12 -0
- package/src/run/pauseHook.js +494 -0
- package/src/run/personaLoop.js +139 -10
- package/src/run/pixels.js +22 -10
- package/src/run/planGuard.js +103 -0
- package/src/run/replay.js +5 -1
- package/src/run/reportChecks.js +17 -4
- package/src/run/resume.js +6 -2
- package/src/run/sessions.js +170 -0
- package/src/run/startFrom.js +415 -0
- package/src/run/testerProbes.js +36 -5
- package/src/run/tools.js +191 -10
- package/src/run/view3dState.js +125 -0
- package/src/run/web3d.js +375 -0
- package/src/run/world3d.js +164 -0
- package/src/upload/host.js +40 -0
- package/src/upload/index.js +15 -1
- package/templates/godot-3d/README.md +3 -2
package/README.md
CHANGED
|
@@ -11,15 +11,23 @@
|
|
|
11
11
|
--device ID`). A Unity, Godot or native mobile build works the same way. See
|
|
12
12
|
[Native mobile on this machine](#native-mobile-on-this-machine) and
|
|
13
13
|
[docs/MOBILE.md](docs/MOBILE.md).
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
`
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
- **Unreal games on a Mac**, as the packaged Mac app in a window
|
|
15
|
+
(`run --driver unreal_driver --native-build MyGame.app`). See
|
|
16
|
+
[docs/UNREAL.md](docs/UNREAL.md).
|
|
17
|
+
- **Unity games on a Mac**, 2D or 3D, as the macOS player in a window
|
|
18
|
+
(`run --driver unity_driver --native-build MyGame.app`). See
|
|
19
|
+
[docs/UNITY.md](docs/UNITY.md).
|
|
20
|
+
|
|
21
|
+
The cloud accepts web builds. Android builds in the cloud
|
|
22
|
+
(`hosted run --native-build game.apk`) are not available yet for most studios;
|
|
23
|
+
see [Android builds in the cloud](#android-builds-in-the-cloud). Physical phones and tablets, App Store or
|
|
24
|
+
device builds (`.ipa`), and Windows and Linux desktop builds cannot be
|
|
25
|
+
playtested. Unity and Unreal Mac players play locally with `--native-build`
|
|
26
|
+
(see docs/UNITY.md and docs/UNREAL.md). The W3C native adapters (`desktop_driver`, and
|
|
27
|
+
`unity_driver`, `unreal_driver`, `android_driver` or `ios_driver` given
|
|
28
|
+
`--driver-config`) are experimental: each needs a separate automation server
|
|
29
|
+
that you run yourself and that Ravensight does not provide, and none of them
|
|
30
|
+
has been tested against a real automation server.
|
|
23
31
|
|
|
24
32
|
Cloud playtests run your uploaded build on our machines instead of yours, with
|
|
25
33
|
one playtester per persona: Geri and Freki play your game together, Geri
|
|
@@ -49,6 +57,7 @@ funding requirement stops before the question, and nothing is charged.
|
|
|
49
57
|
| Flag | Effect |
|
|
50
58
|
|---|---|
|
|
51
59
|
| `--build <id>` | Use this build instead of the newest ready one. |
|
|
60
|
+
| `--native-build <path>` | Upload this Android APK and playtest it on an Android device in the cloud. Not yet available for most studios; see below. |
|
|
52
61
|
| `--personas <list>` | More personas to add, comma separated. `fresh-eyes`, a first time player, is always included; each persona adds its own price. `ravensight-playtest personas` lists them. |
|
|
53
62
|
| `--tier <name>` | `jam`, `small`, `medium` or `large`. The default is the tier your build's size needs; a smaller one is refused before any charge. |
|
|
54
63
|
| `--minutes <n>` | Minutes of play per persona, from the tier's own length up to 120. Geri's thinking budget and the action limit grow with it, and so does the price. |
|
|
@@ -87,6 +96,32 @@ play), that persona stops early. It keeps the machine time and model spend it
|
|
|
87
96
|
used plus the quote's under-scope fee, the rest of its price is refunded, and
|
|
88
97
|
the report names the tier to choose.
|
|
89
98
|
|
|
99
|
+
### Android builds in the cloud
|
|
100
|
+
|
|
101
|
+
```sh
|
|
102
|
+
ravensight-playtest hosted run --native-build game.apk --tier jam
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`--native-build` uploads the APK as it is and playtests it on an Android
|
|
106
|
+
device in the cloud, one per persona. The build must be a signed APK with a
|
|
107
|
+
launcher activity. An Android App Bundle (`.aab`) cannot be installed: upload
|
|
108
|
+
the `.apk` built from it. The device runs with its network off, so the game
|
|
109
|
+
has to play offline.
|
|
110
|
+
|
|
111
|
+
Before anything is sent, the CLI checks that the file is an `.apk`, that it is
|
|
112
|
+
a ZIP and that it has an `AndroidManifest.xml` at its root. It then uploads the
|
|
113
|
+
APK under the same $0.49 validation hold as a web build, waits for the
|
|
114
|
+
server's check (signature, launcher activity, manifest and permissions; a
|
|
115
|
+
refused build shows the reason) and quotes the playtest as for any cloud
|
|
116
|
+
playtest. The same APK uploaded before is used again, with no second upload
|
|
117
|
+
or hold. `--build` names a build already uploaded, so it does not go with
|
|
118
|
+
`--native-build`. `--start`, `--save` and `--save-target` are refused for an
|
|
119
|
+
Android build; `--focus` and `--avoid` goals are taken.
|
|
120
|
+
|
|
121
|
+
This is not available yet for most studios. When it is not available for
|
|
122
|
+
yours, `hosted run --native-build` says so before anything is uploaded or
|
|
123
|
+
charged, and exits 3.
|
|
124
|
+
|
|
90
125
|
### Build size, tier and video
|
|
91
126
|
|
|
92
127
|
A build's tier follows what it unpacks to: Jam up to 50 MB, Small up to 250
|
|
@@ -189,6 +224,7 @@ The hosted build command source adds a local check before a paid upload:
|
|
|
189
224
|
ravensight-playtest build preflight ./game.zip --format web
|
|
190
225
|
ravensight-playtest build upload ./game.zip --game GAME --dry-run
|
|
191
226
|
ravensight-playtest build status --game GAME
|
|
227
|
+
ravensight-playtest build delete BUILD_ID --game GAME
|
|
192
228
|
```
|
|
193
229
|
|
|
194
230
|
`--entrypoint` names the file the game starts from. Without it, an `index.html`
|
|
@@ -205,7 +241,11 @@ asks for the separate $0.49 validation hold before requesting it. Without a
|
|
|
205
241
|
terminal to ask in, pass `--yes`: a piped answer is never taken as consent.
|
|
206
242
|
`build status` shows each build's state and, for a build the server's check
|
|
207
243
|
refused, the reason in one sentence and whether its validation hold is still
|
|
208
|
-
to be returned after cleanup.
|
|
244
|
+
to be returned after cleanup. `build delete BUILD_ID` removes a build you no
|
|
245
|
+
longer need, after asking (pass `--yes` without a terminal; `--json` needs
|
|
246
|
+
`--yes`). The build can no longer be quoted or played, and its validation hold
|
|
247
|
+
comes back once cleanup finishes; `build status` shows where it stands. A
|
|
248
|
+
declined prompt exits 10 and deletes nothing. The server’s isolated validator remains
|
|
209
249
|
authoritative. A passing local check does not establish engine, GPU or license
|
|
210
250
|
compatibility.
|
|
211
251
|
|
|
@@ -728,7 +768,7 @@ splitting the job in two is what gets everything played.
|
|
|
728
768
|
|---|---|
|
|
729
769
|
| `--game <gameId>` | The game, when this repo is not linked. |
|
|
730
770
|
| `--personas <list>` | Comma separated persona slugs. Defaults to one, `fresh-eyes`; `ravensight-playtest personas` lists them. |
|
|
731
|
-
| `--driver <name>` | `playwright_web`, `godot_driver`, `cli_stdio`, `android_driver` or `
|
|
771
|
+
| `--driver <name>` | `playwright_web`, `godot_driver`, `cli_stdio`, `android_driver`, `ios_driver`, `unreal_driver` or `unity_driver`. `android_driver` and `ios_driver` play a local emulator or simulator build given with `--native-build` and `--device` ([docs/MOBILE.md](docs/MOBILE.md)); `unreal_driver` plays a packaged Unreal Mac app ([docs/UNREAL.md](docs/UNREAL.md)) and `unity_driver` a Unity Mac player ([docs/UNITY.md](docs/UNITY.md)) given with `--native-build`. `desktop_driver`, and the Unity, Unreal and mobile drivers given `--driver-config`, are experimental: they need an automation server you run yourself and are untested against a real one. |
|
|
732
772
|
| `--native-build <path>` | An Android APK for an emulator, or an iOS Simulator APP (not an `.ipa`). |
|
|
733
773
|
| `--device <id>` | The exact emulator serial or AVD name, or simulator UDID or name. A name that matches more than one device is refused. |
|
|
734
774
|
| `--package <id>`, `--bundle-id <id>` | The Android package or iOS bundle identifier you expect. Checked against the build; it cannot point the run at another installed app. |
|
|
@@ -747,6 +787,10 @@ splitting the job in two is what gets everything played.
|
|
|
747
787
|
| `--focus <goal>` | A goal every persona puts first, such as "beat the first boss". Up to five times. |
|
|
748
788
|
| `--avoid <thing>` | Something every persona stays out of, such as "the settings menu". Up to five times. |
|
|
749
789
|
| `--start <query>` | Open a web build with this query or hash, such as `?level=3` or `#boss`. |
|
|
790
|
+
| `--save <file>` | `godot_driver`, `android_driver` and `ios_driver`. A save file the game starts from, placed before it starts. Up to eight, 256 MiB in all; read before the price. See [Starting a native game from a save or a level](#starting-a-native-game-from-a-save-or-a-level). |
|
|
791
|
+
| `--save-target <where>` | Where the game reads `--save`: `godot:user://<path>` or `unity:persistent://<path>`. A path ending in `/` is a folder, and each file keeps its name. |
|
|
792
|
+
| `--start-spec <text>` | A level, a turn or a named save for the game to start at, such as `{"level":"12"}`, up to 1,000 characters. The game reads it; see the section below. |
|
|
793
|
+
| `--sessions <n>` | `godot_driver`, `android_driver` and `ios_driver`. Play each persona's run as 2 or 3 launches of the game: it is closed the way a player closes it and started again on its own saved data, inside the same actions, clock and price. Each session has at least 10 actions. See [Several sessions in one run](#several-sessions-in-one-run). |
|
|
750
794
|
| `--concurrency <n>` | Personas at once. Default the number `init` wrote, which is what `check` recommends for this machine. |
|
|
751
795
|
| `--no-record-video` | Do not keep a video. A `playwright_web` or `godot_driver` run records one on this machine by default (`session.webm`, or `session.mp4` where ffmpeg is installed); it is never uploaded without `--upload-video`. |
|
|
752
796
|
| `--record-video` | Record with the upload limits (15 minutes, 200 MB). Does not upload the video. |
|
|
@@ -1470,6 +1514,105 @@ container, so stitching needs ffmpeg and ffmpeg stays optional.
|
|
|
1470
1514
|
|
|
1471
1515
|
`docs/godot-driver.md` has the protocol, the method set and the error codes.
|
|
1472
1516
|
|
|
1517
|
+
### 3D Godot games
|
|
1518
|
+
|
|
1519
|
+
Since 0.19.0 (driver addon 1.9.0) a persona can play the usual kinds of 3D game
|
|
1520
|
+
on this machine, in lockstep and with `--realtime`:
|
|
1521
|
+
|
|
1522
|
+
- **Mouse look, with the mouse captured or not.** The `hover` tool takes `dx`
|
|
1523
|
+
and `dy` and moves the mouse by that much, which turns a first or third person
|
|
1524
|
+
camera, steers a plane or orbits a view. `with_keys` walks while it turns.
|
|
1525
|
+
- **Aiming at something that moves.** `hover` with `aim_at` naming a 3D node
|
|
1526
|
+
turns the view onto it in small mouse moves, reading from the game after each
|
|
1527
|
+
how far the view turned, and follows it if it moves. Then a click fires.
|
|
1528
|
+
- **Orbit and RTS cameras.** A drag with the right or middle button, the mouse
|
|
1529
|
+
wheel (`scroll`) to zoom, held keys to pan and turn.
|
|
1530
|
+
- **Platforming, driving and flight.** Held keys and chords, and timed key
|
|
1531
|
+
sequences for a jump at the right moment.
|
|
1532
|
+
- **Moving and turning objects.** The screen lists what is on it and where it
|
|
1533
|
+
is drawn, so a drag starts on the object.
|
|
1534
|
+
- **Interaction prompts, HUD and menus.** The screen says what the middle of the
|
|
1535
|
+
screen points at and how far, a prompt drawn in the world is read like a HUD
|
|
1536
|
+
label, and a 3D thing (a sign, a unit) is clicked by its name.
|
|
1537
|
+
- **A gamepad only game.** The `gamepad` tool presses buttons and pushes both
|
|
1538
|
+
sticks by any amount. It is offered when the game reads a gamepad.
|
|
1539
|
+
|
|
1540
|
+
Every look at a 3D scene includes what the game's own state says: where the
|
|
1541
|
+
camera is and faces, what is in the middle of the screen, the player's place,
|
|
1542
|
+
speed and whether it is on the floor, and the bodies on screen. From the same
|
|
1543
|
+
numbers, with no model call, the runner files four kinds of finding: something
|
|
1544
|
+
fell out of the world, the player is stuck on the level's geometry, the camera
|
|
1545
|
+
went inside a wall or turned upside down, and moves that got nowhere. A Godot 3D
|
|
1546
|
+
run replays like a 2D one, mouse look and the gamepad included.
|
|
1547
|
+
|
|
1548
|
+
What it cannot do yet: a game that reads the mouse position itself (edge
|
|
1549
|
+
scrolling at the side of the screen) sees the desktop's pointer, which the runner
|
|
1550
|
+
never moves, so pan such a game with keys or a drag; a game that waits for a
|
|
1551
|
+
gamepad to appear in its list of connected pads before it reads one does not see
|
|
1552
|
+
the runner's. `docs/godot-driver.md` has the details.
|
|
1553
|
+
|
|
1554
|
+
### Starting a native game from a save or a level
|
|
1555
|
+
|
|
1556
|
+
`--save`, `--save-target` and `--start-spec` start every persona of a local
|
|
1557
|
+
Godot, Android emulator or iOS Simulator run somewhere other than the
|
|
1558
|
+
beginning: turn 150, level 12, a full inventory. Nothing is uploaded; the
|
|
1559
|
+
files stay on this machine. They are read and hashed before the price, and a
|
|
1560
|
+
file that changed by the time the game starts is refused.
|
|
1561
|
+
|
|
1562
|
+
```sh
|
|
1563
|
+
ravensight-playtest run --driver godot_driver --godot-project . \
|
|
1564
|
+
--save ./saves/turn150.sav --save-target godot:user://saves/slot1.sav --start-spec '{"turn":150}'
|
|
1565
|
+
```
|
|
1566
|
+
|
|
1567
|
+
| Root | Godot on this machine | Android emulator | iOS Simulator |
|
|
1568
|
+
|---|---|---|---|
|
|
1569
|
+
| `godot:user://` | A user folder of the run's own, never yours, removed when the run ends. | The app's internal files folder, through `run-as` (a debuggable build). | The app's Documents. |
|
|
1570
|
+
| `unity:persistent://` | Not a local path. | `Application.persistentDataPath`, the app's external files folder. | `Application.persistentDataPath`, the app's Documents. |
|
|
1571
|
+
|
|
1572
|
+
On an emulator or simulator a file already at that path is kept and put back
|
|
1573
|
+
when the run ends, and a placed save that was not there before is removed.
|
|
1574
|
+
The save is placed during the free preflight too, so a build that does not let
|
|
1575
|
+
it be placed is refused before any charge.
|
|
1576
|
+
|
|
1577
|
+
The start spec reaches the game:
|
|
1578
|
+
|
|
1579
|
+
- **Godot on this machine:** in the environment as `RAVENSIGHT_PLAYTEST_START`, and through a method of your own. Give any autoload, or any node in the group `ravensight_playtest_start`, `func _ravensight_playtest_start(spec: Dictionary)`. The driver calls it once after boot with `{"spec": "...", "saves": [...]}`; load what it names and answer with what you loaded, a String or `{"loaded": "...", "where": "..."}`. The report says what the game answered. In lockstep the call is part of the recorded start, so a replay starts the same way.
|
|
1580
|
+
- **Android:** the intent extra `ravensight_playtest_start` (in Unity, read the activity's intent with `AndroidJavaObject` and call `getStringExtra("ravensight_playtest_start")`).
|
|
1581
|
+
- **iOS Simulator:** the app's environment, `RAVENSIGHT_PLAYTEST_START`.
|
|
1582
|
+
|
|
1583
|
+
A game that reads none of them still gets the files. The persona is told the run
|
|
1584
|
+
does not start at the beginning, and report.md says where it started under
|
|
1585
|
+
**Where this run started**.
|
|
1586
|
+
|
|
1587
|
+
### Several sessions in one run
|
|
1588
|
+
|
|
1589
|
+
`--sessions 2` or `--sessions 3` plays each persona's run as that many launches
|
|
1590
|
+
of the game, the way a player stops for the day and comes back. A session ends
|
|
1591
|
+
at an even share of the run's actions, or of its minutes on a tier, whichever is
|
|
1592
|
+
used first; the persona is told a turn or two ahead and asked to save the way a
|
|
1593
|
+
player would. Then the game is closed (Godot gets a close request, so a game
|
|
1594
|
+
that saves on quit saves; a mobile game is sent to the background first, where
|
|
1595
|
+
it gets its pause event) and started again cold on the same data. The persona
|
|
1596
|
+
remembers everything, its notes included; the game keeps only what it saved, and
|
|
1597
|
+
the persona is asked to check what came back.
|
|
1598
|
+
|
|
1599
|
+
Sessions share the run's own action budget, model budget and clock: nothing is
|
|
1600
|
+
bought for a session, and the price is the same as one session. A game that
|
|
1601
|
+
does not start again is a blocker finding and ends the run. A Godot run's replay
|
|
1602
|
+
starts the game once, so only first-session findings are replayed. A start spec
|
|
1603
|
+
goes with the first launch only.
|
|
1604
|
+
|
|
1605
|
+
### A plan of several inputs
|
|
1606
|
+
|
|
1607
|
+
A persona may send several inputs in one turn, such as "hold right, jump, hold
|
|
1608
|
+
right": they are played back to back with one model call, and on Godot the game
|
|
1609
|
+
runs only while they play. Each input is checked against the screen after it,
|
|
1610
|
+
with no model call: when an input that said what it expected changed nothing,
|
|
1611
|
+
did not reach the game, or the game moved to another scene or counted a death,
|
|
1612
|
+
the inputs after it are not sent and cost nothing, and the persona plans again
|
|
1613
|
+
from the screen as it is. The step log's `plan_guard` line counts the plans,
|
|
1614
|
+
the steps played and why any stopped.
|
|
1615
|
+
|
|
1473
1616
|
## What a report has to contain
|
|
1474
1617
|
|
|
1475
1618
|
`report.json` is validated against the pack schema before it is sent, and
|
|
@@ -1753,7 +1896,7 @@ feedback and timing-sensitive gameplay.
|
|
|
1753
1896
|
|
|
1754
1897
|
## Build adapters
|
|
1755
1898
|
|
|
1756
|
-
Web builds (`playwright_web`, locally or in the cloud), Godot projects (`godot_driver`, locally)
|
|
1899
|
+
Web builds (`playwright_web`, locally or in the cloud), Godot projects (`godot_driver`, locally), Android emulator and iOS Simulator builds (`android_driver` and `ios_driver` with `--native-build`, locally, see [docs/MOBILE.md](docs/MOBILE.md)) packaged Unreal Mac apps (`unreal_driver` with `--native-build`, locally on a Mac, see [docs/UNREAL.md](docs/UNREAL.md)) and Unity Mac players (`unity_driver` with `--native-build`, locally on a Mac, see [docs/UNITY.md](docs/UNITY.md)) are what can be playtested. The desktop driver, and the Unity, Unreal and mobile drivers given `--driver-config`, are experimental: each needs a separate automation server that you run yourself and that Ravensight does not provide, and none has been tested against a real automation server. The custom JSON-RPC bridge (`cli_stdio`) is for text games and your own integrations. See [adapter setup and validation boundaries](docs/ADAPTERS.md); the [native runner starter](docs/NATIVE_RUNNER.md) is kept as an untested reference.
|
|
1757
1900
|
|
|
1758
1901
|
## Validate changes (Labs beta)
|
|
1759
1902
|
|
|
@@ -1956,7 +2099,7 @@ ravensight-playtest validate <branch> --base main --alpha-3d
|
|
|
1956
2099
|
|
|
1957
2100
|
**`--alpha-3d`** is how you ask. Without it, `feature` and `validate` refuse a project whose main scene has a 3D root, for free. With it on a 2D project they refuse too, and a specification written for one kind of project does not build on the other.
|
|
1958
2101
|
|
|
1959
|
-
**What works differently.** A persona reads positions as `@(x,y,z)` in world units, and can click a node by its path, where the active camera draws it. It plays with keys
|
|
2102
|
+
**What works differently.** A persona reads positions as `@(x,y,z)` in world units, and can click a node by its path, where the active camera draws it. It plays with keys, input actions, mouse look, aiming and a gamepad, as [3D Godot games](#3d-godot-games) says. Headless, as in 2D, no mouse input reaches the game, so mouse look needs a window. Your own models are listed by `assets` by type and size, are never read by the model, and the checks confirm that Godot imports the ones a change names. See [docs/REPLAY.md](docs/REPLAY.md) for what replays on 3D.
|
|
1960
2103
|
|
|
1961
2104
|
## Simulation Runner
|
|
1962
2105
|
|
|
@@ -1987,9 +2130,10 @@ ravensight-playtest run --driver android_driver --native-build ./game.apk --devi
|
|
|
1987
2130
|
ravensight-playtest run --driver ios_driver --native-build ./Game.app --device <UDID> --landscape
|
|
1988
2131
|
```
|
|
1989
2132
|
|
|
1990
|
-
The game runs in real time while the playtester thinks. Pinch
|
|
1991
|
-
devices
|
|
1992
|
-
|
|
2133
|
+
The game runs in real time while the playtester thinks. Pinch and physical
|
|
2134
|
+
devices are not available. Cloud runs of an Android APK
|
|
2135
|
+
(`hosted run --native-build game.apk`) are not available yet for most studios;
|
|
2136
|
+
see [Android builds in the cloud](#android-builds-in-the-cloud). The video stays on this machine unless you pass
|
|
1993
2137
|
`--upload-video`. Prices, budgets and refunds are those of any local persona
|
|
1994
2138
|
run. Setup, every flag and the limits are in [docs/MOBILE.md](docs/MOBILE.md).
|
|
1995
2139
|
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// Ravensight desktop input helper for macOS.
|
|
2
|
+
//
|
|
3
|
+
// The playtest CLI compiles this file once with swiftc and runs it for the
|
|
4
|
+
// length of one local desktop run. It reads one JSON request per line on
|
|
5
|
+
// stdin and answers one JSON line per request on stdout. It only ever:
|
|
6
|
+
// - reads the on-screen windows of ONE process id (bounds, never contents),
|
|
7
|
+
// - posts keyboard events and pointer moves to that same process id
|
|
8
|
+
// (CGEvent.postToPid): keys, hovers and moves by an amount (mouse look),
|
|
9
|
+
// - sends mouse presses, drags and the wheel at the pointer, as a hand
|
|
10
|
+
// would, only after checking that this process's window is the one on
|
|
11
|
+
// top at that point (a window reads its own buttons; see post below),
|
|
12
|
+
// moving the cursor to each click's point the way a player's hand would, and
|
|
13
|
+
// - brings that process's window to the front before a click.
|
|
14
|
+
// It opens no network connection and writes no file.
|
|
15
|
+
import AppKit
|
|
16
|
+
import ApplicationServices
|
|
17
|
+
import CoreGraphics
|
|
18
|
+
import Foundation
|
|
19
|
+
|
|
20
|
+
setvbuf(stdout, nil, _IOLBF, 0)
|
|
21
|
+
|
|
22
|
+
func reply(_ value: [String: Any]) {
|
|
23
|
+
guard let data = try? JSONSerialization.data(withJSONObject: value),
|
|
24
|
+
let line = String(data: data, encoding: .utf8) else { return }
|
|
25
|
+
print(line)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func number(_ value: Any?) -> Double? {
|
|
29
|
+
if let n = value as? NSNumber { return n.doubleValue }
|
|
30
|
+
return nil
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func gameWindow(_ pid: pid_t) -> [String: Any]? {
|
|
34
|
+
guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { return nil }
|
|
35
|
+
var best: [String: Any]? = nil
|
|
36
|
+
var bestArea = 0.0
|
|
37
|
+
for info in list {
|
|
38
|
+
guard let owner = info[kCGWindowOwnerPID as String] as? NSNumber, owner.int32Value == pid else { continue }
|
|
39
|
+
guard let layer = info[kCGWindowLayer as String] as? NSNumber, layer.intValue == 0 else { continue }
|
|
40
|
+
guard let bounds = info[kCGWindowBounds as String] as? [String: Any],
|
|
41
|
+
let w = number(bounds["Width"]), let h = number(bounds["Height"]), w >= 64, h >= 64 else { continue }
|
|
42
|
+
let area = w * h
|
|
43
|
+
if area > bestArea {
|
|
44
|
+
bestArea = area
|
|
45
|
+
best = [
|
|
46
|
+
"windowId": (info[kCGWindowNumber as String] as? NSNumber)?.intValue ?? 0,
|
|
47
|
+
"x": number(bounds["X"]) ?? 0, "y": number(bounds["Y"]) ?? 0, "width": w, "height": h
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return best
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The process that owns the frontmost ordinary window at a screen point.
|
|
55
|
+
// (Owner and bounds only: reading them needs no Screen Recording.)
|
|
56
|
+
func ownerOnTop(at point: CGPoint) -> pid_t? {
|
|
57
|
+
guard let list = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] else { return nil }
|
|
58
|
+
for info in list {
|
|
59
|
+
guard let layer = info[kCGWindowLayer as String] as? NSNumber, layer.intValue == 0,
|
|
60
|
+
let bounds = info[kCGWindowBounds as String] as? [String: Any],
|
|
61
|
+
let x = number(bounds["X"]), let y = number(bounds["Y"]), let w = number(bounds["Width"]), let h = number(bounds["Height"]) else { continue }
|
|
62
|
+
if CGRect(x: x, y: y, width: w, height: h).contains(point) { return (info[kCGWindowOwnerPID as String] as? NSNumber)?.int32Value }
|
|
63
|
+
}
|
|
64
|
+
return nil
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// How a press reaches the game. By default every event is posted to the
|
|
68
|
+
// game's process (CGEvent.postToPid), which an engine that reads the system's
|
|
69
|
+
// events itself (Unreal) takes. A window that reads its own buttons (SDL,
|
|
70
|
+
// GLFW, any NSView based engine) never sees a press posted to its process, so
|
|
71
|
+
// a request with "via": "pointer" sends presses, drags and the wheel as the
|
|
72
|
+
// hand's own input at the pointer instead, and only while the game's window
|
|
73
|
+
// is the one on top there: the owner under the point is read again right
|
|
74
|
+
// before every such event, and the whole gesture stops (a held button let go)
|
|
75
|
+
// the moment it is not the game's.
|
|
76
|
+
var viaPointer = false
|
|
77
|
+
let windowEvents: Set<CGEventType> = [.leftMouseDown, .leftMouseUp, .rightMouseDown, .rightMouseUp, .otherMouseDown, .otherMouseUp, .leftMouseDragged, .rightMouseDragged, .otherMouseDragged, .scrollWheel]
|
|
78
|
+
let releaseFor: [CGEventType: CGEventType] = [.leftMouseDown: .leftMouseUp, .rightMouseDown: .rightMouseUp, .otherMouseDown: .otherMouseUp]
|
|
79
|
+
// The button the hand holds down right now, to let go if a gesture stops.
|
|
80
|
+
var held: (type: CGEventType, at: CGPoint, button: CGMouseButton)? = nil
|
|
81
|
+
|
|
82
|
+
func environmentHas(_ pid: pid_t, _ entry: String) -> Bool {
|
|
83
|
+
var mib: [Int32] = [CTL_KERN, KERN_PROCARGS2, pid]
|
|
84
|
+
var size = 0
|
|
85
|
+
guard sysctl(&mib, 3, nil, &size, nil, 0) == 0, size > 0 else { return false }
|
|
86
|
+
var buffer = [UInt8](repeating: 0, count: size)
|
|
87
|
+
guard sysctl(&mib, 3, &buffer, &size, nil, 0) == 0 else { return false }
|
|
88
|
+
// argc, the executable path, then argv and the environment as C strings.
|
|
89
|
+
let target = Array(entry.utf8)
|
|
90
|
+
var start = 4
|
|
91
|
+
for i in 4..<size where buffer[i] == 0 {
|
|
92
|
+
if i - start == target.count && Array(buffer[start..<i]) == target { return true }
|
|
93
|
+
start = i + 1
|
|
94
|
+
}
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func launchedPids(executable: String, marker: String) -> [Int] {
|
|
99
|
+
let count = proc_listallpids(nil, 0)
|
|
100
|
+
guard count > 0 else { return [] }
|
|
101
|
+
var pids = [pid_t](repeating: 0, count: Int(count) * 2)
|
|
102
|
+
let found = proc_listallpids(&pids, Int32(pids.count * MemoryLayout<pid_t>.size))
|
|
103
|
+
var out: [Int] = []
|
|
104
|
+
var path = [CChar](repeating: 0, count: 4096)
|
|
105
|
+
for pid in pids.prefix(Int(max(0, found))) where pid > 0 {
|
|
106
|
+
guard proc_pidpath(pid, &path, UInt32(path.count)) > 0, String(cString: path) == executable else { continue }
|
|
107
|
+
var info = proc_bsdinfo()
|
|
108
|
+
guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, Int32(MemoryLayout<proc_bsdinfo>.size)) > 0, info.pbi_ppid == 1, info.pbi_uid == getuid() else { continue }
|
|
109
|
+
if environmentHas(pid, "RAVENSIGHT_DESKTOP_LAUNCH=" + marker) { out.append(Int(pid)) }
|
|
110
|
+
}
|
|
111
|
+
return out
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func post(_ event: CGEvent?, _ pid: pid_t) throws {
|
|
115
|
+
guard let event = event else { throw NSError(domain: "ravensight", code: 1, userInfo: [NSLocalizedDescriptionKey: "macOS refused to create the input event"]) }
|
|
116
|
+
guard viaPointer && windowEvents.contains(event.type) else { event.postToPid(pid); return }
|
|
117
|
+
guard ownerOnTop(at: event.location) == pid else { throw NSError(domain: "ravensight", code: 11, userInfo: [NSLocalizedDescriptionKey: "another window came over the game at that point; the input was stopped"]) }
|
|
118
|
+
event.post(tap: .cghidEventTap)
|
|
119
|
+
if let up = releaseFor[event.type] {
|
|
120
|
+
held = (up, event.location, CGMouseButton(rawValue: UInt32(event.getIntegerValueField(.mouseEventButtonNumber))) ?? .left)
|
|
121
|
+
} else if releaseFor.values.contains(event.type) { held = nil }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// One press, drag or wheel turn: with "via": "pointer" the game's window is
|
|
125
|
+
// brought forward at the start point first, and a gesture that stops part way
|
|
126
|
+
// lets go of its button where it was pressed.
|
|
127
|
+
func gesture(_ pid: pid_t, at start: CGPoint, _ body: () throws -> Void) throws {
|
|
128
|
+
if viaPointer && !raiseWindow(pid, at: start) { throw NSError(domain: "ravensight", code: 11, userInfo: [NSLocalizedDescriptionKey: "another window covers the game at that point; the input was not sent"]) }
|
|
129
|
+
do { try body() } catch {
|
|
130
|
+
if let h = held { CGEvent(mouseEventSource: nil, mouseType: h.type, mouseCursorPosition: h.at, mouseButton: h.button)?.post(tap: .cghidEventTap); held = nil }
|
|
131
|
+
throw error
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
func pause(_ ms: Double) { if ms > 0 { usleep(useconds_t(min(ms, 10000) * 1000)) } }
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
func mouseTypes(_ button: String) -> (CGEventType, CGEventType, CGEventType, CGMouseButton) {
|
|
139
|
+
switch button {
|
|
140
|
+
case "right": return (.rightMouseDown, .rightMouseUp, .rightMouseDragged, .right)
|
|
141
|
+
case "middle": return (.otherMouseDown, .otherMouseUp, .otherMouseDragged, .center)
|
|
142
|
+
default: return (.leftMouseDown, .leftMouseUp, .leftMouseDragged, .left)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let flagFor: [Int: CGEventFlags] = [56: .maskShift, 60: .maskShift, 59: .maskControl, 62: .maskControl, 58: .maskAlternate, 61: .maskAlternate, 55: .maskCommand, 54: .maskCommand]
|
|
147
|
+
|
|
148
|
+
// Brings the game's window to the front at a point, through Accessibility. A
|
|
149
|
+
// busy Mac can take a moment, so this tries three times before giving up.
|
|
150
|
+
func raiseWindow(_ pid: pid_t, at point: CGPoint) -> Bool {
|
|
151
|
+
if ownerOnTop(at: point) == pid { return true }
|
|
152
|
+
for _ in 0..<3 {
|
|
153
|
+
let app = AXUIElementCreateApplication(pid)
|
|
154
|
+
AXUIElementSetAttributeValue(app, kAXFrontmostAttribute as CFString, kCFBooleanTrue)
|
|
155
|
+
var windows: CFTypeRef?
|
|
156
|
+
if AXUIElementCopyAttributeValue(app, kAXWindowsAttribute as CFString, &windows) == .success, let list = windows as? [AXUIElement] {
|
|
157
|
+
for element in list {
|
|
158
|
+
AXUIElementPerformAction(element, kAXRaiseAction as CFString)
|
|
159
|
+
AXUIElementSetAttributeValue(element, kAXMainAttribute as CFString, kCFBooleanTrue)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
NSRunningApplication(processIdentifier: pid)?.activate(options: [.activateAllWindows])
|
|
163
|
+
for _ in 0..<30 { if ownerOnTop(at: point) == pid { return true }; pause(25) }
|
|
164
|
+
}
|
|
165
|
+
return ownerOnTop(at: point) == pid
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func handle(_ request: [String: Any]) throws -> [String: Any] {
|
|
169
|
+
let kind = request["kind"] as? String ?? ""
|
|
170
|
+
if kind == "access" {
|
|
171
|
+
return ["accessibility": AXIsProcessTrusted(), "screenCapture": CGPreflightScreenCaptureAccess()]
|
|
172
|
+
}
|
|
173
|
+
if kind == "find" {
|
|
174
|
+
// The game app LaunchServices just started: the one process whose executable
|
|
175
|
+
// is exactly this path, whose parent is launchd and whose environment holds
|
|
176
|
+
// this launch's own marker. More than one is refused by the caller.
|
|
177
|
+
guard let executable = request["executable"] as? String, let marker = request["marker"] as? String, marker.count >= 32 else { throw NSError(domain: "ravensight", code: 12, userInfo: [NSLocalizedDescriptionKey: "find needs an executable and a marker"]) }
|
|
178
|
+
return ["pids": launchedPids(executable: executable, marker: marker)]
|
|
179
|
+
}
|
|
180
|
+
guard let rawPid = number(request["pid"]), rawPid >= 1, rawPid < 1_000_000 else { throw NSError(domain: "ravensight", code: 2, userInfo: [NSLocalizedDescriptionKey: "a process id is required"]) }
|
|
181
|
+
let pid = pid_t(rawPid)
|
|
182
|
+
viaPointer = (request["via"] as? String) == "pointer"
|
|
183
|
+
held = nil
|
|
184
|
+
switch kind {
|
|
185
|
+
case "status":
|
|
186
|
+
return ["running": kill(pid, 0) == 0]
|
|
187
|
+
case "window":
|
|
188
|
+
guard let window = gameWindow(pid) else { return ["found": false] }
|
|
189
|
+
return window.merging(["found": true]) { a, _ in a }
|
|
190
|
+
case "raise":
|
|
191
|
+
// A click lands on whatever window is on top at that point, so the game
|
|
192
|
+
// window is brought to the front first, through Accessibility. A busy Mac
|
|
193
|
+
// can take a moment, so this tries three times before giving up.
|
|
194
|
+
guard let window = gameWindow(pid), let wx = number(window["x"]), let wy = number(window["y"]), let ww = number(window["width"]), let wh = number(window["height"]) else { return ["onTop": false] }
|
|
195
|
+
let point = CGPoint(x: number(request["x"]) ?? wx + ww / 2, y: number(request["y"]) ?? wy + wh / 2)
|
|
196
|
+
return ["onTop": raiseWindow(pid, at: point)]
|
|
197
|
+
case "click":
|
|
198
|
+
guard let x = number(request["x"]), let y = number(request["y"]) else { throw NSError(domain: "ravensight", code: 4, userInfo: [NSLocalizedDescriptionKey: "a point is required"]) }
|
|
199
|
+
let (down, up, _, button) = mouseTypes(request["button"] as? String ?? "left")
|
|
200
|
+
let point = CGPoint(x: x, y: y)
|
|
201
|
+
let hold = number(request["holdMs"]) ?? 0
|
|
202
|
+
let clicks = (request["double"] as? Bool ?? false) ? 2 : 1
|
|
203
|
+
try gesture(pid, at: point) {
|
|
204
|
+
CGWarpMouseCursorPosition(point)
|
|
205
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left), pid)
|
|
206
|
+
pause(30)
|
|
207
|
+
for count in 1...clicks {
|
|
208
|
+
let press = CGEvent(mouseEventSource: nil, mouseType: down, mouseCursorPosition: point, mouseButton: button)
|
|
209
|
+
press?.setIntegerValueField(.mouseEventClickState, value: Int64(count))
|
|
210
|
+
try post(press, pid)
|
|
211
|
+
pause(max(hold, 40))
|
|
212
|
+
let release = CGEvent(mouseEventSource: nil, mouseType: up, mouseCursorPosition: point, mouseButton: button)
|
|
213
|
+
release?.setIntegerValueField(.mouseEventClickState, value: Int64(count))
|
|
214
|
+
try post(release, pid)
|
|
215
|
+
if count < clicks { pause(80) }
|
|
216
|
+
}
|
|
217
|
+
pause(30)
|
|
218
|
+
}
|
|
219
|
+
return [:]
|
|
220
|
+
case "drag":
|
|
221
|
+
guard let points = request["points"] as? [[String: Any]], points.count >= 2 else { throw NSError(domain: "ravensight", code: 5, userInfo: [NSLocalizedDescriptionKey: "a drag needs two points or more"]) }
|
|
222
|
+
let (down, up, dragged, button) = mouseTypes(request["button"] as? String ?? "left")
|
|
223
|
+
let path = points.compactMap { p -> CGPoint? in
|
|
224
|
+
guard let x = number(p["x"]), let y = number(p["y"]) else { return nil }
|
|
225
|
+
return CGPoint(x: x, y: y)
|
|
226
|
+
}
|
|
227
|
+
let step = (number(request["durationMs"]) ?? 400) / Double(max(1, path.count - 1))
|
|
228
|
+
try gesture(pid, at: path[0]) {
|
|
229
|
+
CGWarpMouseCursorPosition(path[0])
|
|
230
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: path[0], mouseButton: .left), pid)
|
|
231
|
+
pause(30)
|
|
232
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: down, mouseCursorPosition: path[0], mouseButton: button), pid)
|
|
233
|
+
pause(max(number(request["holdMs"]) ?? 0, 30))
|
|
234
|
+
for p in path.dropFirst() {
|
|
235
|
+
pause(step)
|
|
236
|
+
CGWarpMouseCursorPosition(p)
|
|
237
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: dragged, mouseCursorPosition: p, mouseButton: button), pid)
|
|
238
|
+
}
|
|
239
|
+
pause(30)
|
|
240
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: up, mouseCursorPosition: path[path.count - 1], mouseButton: button), pid)
|
|
241
|
+
pause(30)
|
|
242
|
+
}
|
|
243
|
+
return [:]
|
|
244
|
+
case "move":
|
|
245
|
+
// The pointer over a point, no button: a hover.
|
|
246
|
+
guard let x = number(request["x"]), let y = number(request["y"]) else { throw NSError(domain: "ravensight", code: 4, userInfo: [NSLocalizedDescriptionKey: "a point is required"]) }
|
|
247
|
+
let point = CGPoint(x: x, y: y)
|
|
248
|
+
CGWarpMouseCursorPosition(point)
|
|
249
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left), pid)
|
|
250
|
+
return [:]
|
|
251
|
+
case "look":
|
|
252
|
+
// The mouse moved by an amount, as mouse look reads it: each step is a
|
|
253
|
+
// move event carrying its own delta, from a point that stays inside the
|
|
254
|
+
// window, so a game reading relative motion and one reading positions
|
|
255
|
+
// both see the same turn.
|
|
256
|
+
guard let steps = request["steps"] as? [[String: Any]], !steps.isEmpty, steps.count <= 64,
|
|
257
|
+
let x = number(request["x"]), let y = number(request["y"]) else { throw NSError(domain: "ravensight", code: 9, userInfo: [NSLocalizedDescriptionKey: "a look needs a start point and one to 64 steps"]) }
|
|
258
|
+
let bounds = gameWindow(pid)
|
|
259
|
+
var at = CGPoint(x: x, y: y)
|
|
260
|
+
let stepMs = number(request["stepMs"]) ?? 16
|
|
261
|
+
// Keys held through the whole move, to walk and turn at once.
|
|
262
|
+
let held = (request["codes"] as? [NSNumber] ?? []).prefix(6)
|
|
263
|
+
var flags: CGEventFlags = []
|
|
264
|
+
for code in held { flags.insert(flagFor[code.intValue] ?? []) }
|
|
265
|
+
for code in held {
|
|
266
|
+
let event = CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(code.uint16Value), keyDown: true)
|
|
267
|
+
event?.flags = flags
|
|
268
|
+
try post(event, pid)
|
|
269
|
+
}
|
|
270
|
+
if !held.isEmpty { pause(50) }
|
|
271
|
+
defer {
|
|
272
|
+
for code in held.reversed() {
|
|
273
|
+
let event = CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(code.uint16Value), keyDown: false)
|
|
274
|
+
try? post(event, pid)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
for step in steps {
|
|
278
|
+
let dx = number(step["dx"]) ?? 0, dy = number(step["dy"]) ?? 0
|
|
279
|
+
var next = CGPoint(x: at.x + dx, y: at.y + dy)
|
|
280
|
+
if let w = bounds, let wx = number(w["x"]), let wy = number(w["y"]), let ww = number(w["width"]), let wh = number(w["height"]) {
|
|
281
|
+
next.x = min(max(next.x, wx + 2), wx + ww - 2)
|
|
282
|
+
next.y = min(max(next.y, wy + 30), wy + wh - 2)
|
|
283
|
+
}
|
|
284
|
+
let event = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: next, mouseButton: .left)
|
|
285
|
+
event?.setIntegerValueField(.mouseEventDeltaX, value: Int64(dx))
|
|
286
|
+
event?.setIntegerValueField(.mouseEventDeltaY, value: Int64(dy))
|
|
287
|
+
try post(event, pid)
|
|
288
|
+
at = next
|
|
289
|
+
pause(stepMs)
|
|
290
|
+
}
|
|
291
|
+
return ["x": at.x, "y": at.y]
|
|
292
|
+
case "wheel":
|
|
293
|
+
// The wheel at a point, in notches: positive dy scrolls down, as a
|
|
294
|
+
// browser counts it, which is a negative wheel delta.
|
|
295
|
+
guard let x = number(request["x"]), let y = number(request["y"]) else { throw NSError(domain: "ravensight", code: 4, userInfo: [NSLocalizedDescriptionKey: "a point is required"]) }
|
|
296
|
+
let lines = Int32(max(-100, min(100, number(request["dy"]) ?? 0)))
|
|
297
|
+
let side = Int32(max(-100, min(100, number(request["dx"]) ?? 0)))
|
|
298
|
+
if lines == 0 && side == 0 { throw NSError(domain: "ravensight", code: 10, userInfo: [NSLocalizedDescriptionKey: "a wheel turn needs dy or dx"]) }
|
|
299
|
+
let point = CGPoint(x: x, y: y)
|
|
300
|
+
// The wheel turns under the pointer, so the pointer goes there first.
|
|
301
|
+
CGWarpMouseCursorPosition(point)
|
|
302
|
+
try post(CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left), pid)
|
|
303
|
+
let event = CGEvent(scrollWheelEvent2Source: nil, units: .line, wheelCount: 2, wheel1: -lines, wheel2: -side, wheel3: 0)
|
|
304
|
+
event?.location = point
|
|
305
|
+
try gesture(pid, at: point) { try post(event, pid) }
|
|
306
|
+
return [:]
|
|
307
|
+
case "keys":
|
|
308
|
+
// Hold every key code together for holdMs, the modifiers first, then let go in reverse.
|
|
309
|
+
guard let codes = request["codes"] as? [NSNumber], !codes.isEmpty, codes.count <= 6 else { throw NSError(domain: "ravensight", code: 6, userInfo: [NSLocalizedDescriptionKey: "one to six key codes are required"]) }
|
|
310
|
+
let hold = number(request["holdMs"]) ?? 0
|
|
311
|
+
var flags: CGEventFlags = []
|
|
312
|
+
for code in codes { flags.insert(flagFor[code.intValue] ?? []) }
|
|
313
|
+
for code in codes {
|
|
314
|
+
let event = CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(code.uint16Value), keyDown: true)
|
|
315
|
+
event?.flags = flags
|
|
316
|
+
try post(event, pid)
|
|
317
|
+
}
|
|
318
|
+
// A held key repeats as a keyboard does: after 500 ms, about thirty times a second.
|
|
319
|
+
if hold > 0, let last = codes.last, flagFor[last.intValue] == nil {
|
|
320
|
+
var waited = 0.0
|
|
321
|
+
while waited < hold {
|
|
322
|
+
let slice = min(waited < 500 ? 500 - waited : 33, hold - waited)
|
|
323
|
+
pause(slice); waited += slice
|
|
324
|
+
if waited >= 500 && waited < hold {
|
|
325
|
+
let repeatEvent = CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(last.uint16Value), keyDown: true)
|
|
326
|
+
repeatEvent?.flags = flags
|
|
327
|
+
repeatEvent?.setIntegerValueField(.keyboardEventAutorepeat, value: 1)
|
|
328
|
+
try post(repeatEvent, pid)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} else { pause(max(hold, 40)) }
|
|
332
|
+
for code in codes.reversed() {
|
|
333
|
+
flags.remove(flagFor[code.intValue] ?? [])
|
|
334
|
+
let event = CGEvent(keyboardEventSource: nil, virtualKey: CGKeyCode(code.uint16Value), keyDown: false)
|
|
335
|
+
event?.flags = flags
|
|
336
|
+
try post(event, pid)
|
|
337
|
+
}
|
|
338
|
+
return [:]
|
|
339
|
+
case "type":
|
|
340
|
+
guard let text = request["text"] as? String, !text.isEmpty, text.count <= 2000 else { throw NSError(domain: "ravensight", code: 7, userInfo: [NSLocalizedDescriptionKey: "type needs 1 to 2000 characters"]) }
|
|
341
|
+
for scalar in text.utf16 {
|
|
342
|
+
var unit = scalar
|
|
343
|
+
for isDown in [true, false] {
|
|
344
|
+
let event = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: isDown)
|
|
345
|
+
event?.keyboardSetUnicodeString(stringLength: 1, unicodeString: &unit)
|
|
346
|
+
try post(event, pid)
|
|
347
|
+
}
|
|
348
|
+
pause(12)
|
|
349
|
+
}
|
|
350
|
+
return [:]
|
|
351
|
+
default:
|
|
352
|
+
throw NSError(domain: "ravensight", code: 8, userInfo: [NSLocalizedDescriptionKey: "unknown request"])
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
reply(["ready": true])
|
|
357
|
+
while let line = readLine(strippingNewline: true) {
|
|
358
|
+
if line.utf8.count > 65536 { reply(["ok": false, "error": "request too large"]); continue }
|
|
359
|
+
guard let data = line.data(using: .utf8),
|
|
360
|
+
let request = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else {
|
|
361
|
+
reply(["ok": false, "error": "invalid request"]); continue
|
|
362
|
+
}
|
|
363
|
+
let id = request["id"] ?? NSNull()
|
|
364
|
+
if (request["kind"] as? String) == "shutdown" { reply(["id": id, "ok": true]); break }
|
|
365
|
+
do { reply(try handle(request).merging(["id": id, "ok": true]) { a, _ in a }) }
|
|
366
|
+
catch { reply(["id": id, "ok": false, "error": error.localizedDescription]) }
|
|
367
|
+
}
|