ravensight-playtest 0.19.0 → 0.20.1

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.
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Slow motion through the SDK pause hook's `time_scale` (the platform's
3
+ * docs/playtest/PAUSE_HOOK_CONTRACT.md, sections 3 and 6).
4
+ *
5
+ * A model takes a second or more to decide. A game whose clock keeps running
6
+ * through that gap plays an action game far faster than the playtester can
7
+ * answer it. The pause hook already freezes the game between decisions by
8
+ * default, and then the decision costs no game time at all, so slow motion is
9
+ * not needed. It is for a run where the game keeps running while the
10
+ * playtester decides:
11
+ *
12
+ * - `--realtime` on an action game (a twitch, first person, third person or
13
+ * vehicle game, or a shoot em up, twin stick, fighting or racing style): the
14
+ * game runs at a quarter of its speed while the playtester decides, once the
15
+ * playtester has said what kind of game it is.
16
+ * - `--time-scale <n>` on any game: the game runs at that share of its speed
17
+ * while the playtester decides, from the first frame, instead of being
18
+ * paused. A game whose hook cannot slow it is paused as before.
19
+ * - `--no-slow-motion` keeps `--realtime` at full speed for every game.
20
+ *
21
+ * Inputs and waits always play at the game's own speed (the runner sets the
22
+ * scale back to 1 for them), so a held key or a 2 second wait is the game time
23
+ * the playtester asked for. Only the decision gap is slowed. The video and the
24
+ * step log stay in real time: the runner never rescales a timestamp, and it
25
+ * keeps the game's own clock apart (`slowed_game_ms` against `slowed_wall_ms`).
26
+ *
27
+ * A game that cannot be slowed (no hook, a hook without `time_scale`, a game
28
+ * that refuses the scale) plays at its normal speed and the report says so.
29
+ * That is a limit of the runner and the game's SDK set up, never a finding.
30
+ */
31
+
32
+ /** The share of its speed a game runs at while the playtester decides, by default. */
33
+ export const DEFAULT_TIME_SCALE = 0.25;
34
+ /** The bounds of `--time-scale`. Full speed is `--realtime`; slower than a tenth makes a run crawl. */
35
+ export const MIN_TIME_SCALE = 0.1;
36
+ export const MAX_TIME_SCALE = 0.9;
37
+
38
+ /** The drivers that reach a game's SDK pause hook (../commands/run.js driverOptions). */
39
+ export const HOOK_DRIVERS = Object.freeze(['desktop_driver', 'unity_driver', 'unreal_driver', 'cli_stdio', 'android_driver', 'ios_driver']);
40
+
41
+ /** Kinds of game (./anygame/genre.js) played in real time, where a second of thinking matters. Rhythm is left out: slowing a song breaks it. */
42
+ export const ACTION_KINDS = Object.freeze(['twitch', 'first_person', 'third_person', 'vehicle']);
43
+ /** 2D styles (./anygame/genre2d.js) that are real-time action. */
44
+ export const ACTION_STYLES = Object.freeze(['shmup', 'twin_stick', 'fighting', 'racing']);
45
+
46
+ /**
47
+ * Whether a settled kind and style is an action game that slow motion helps.
48
+ *
49
+ * @param {{kind?: string|null, style2d?: string|null}|null} digest the genre's digest
50
+ * @returns {boolean}
51
+ */
52
+ export function isActionStyle(digest) {
53
+ if (!digest || typeof digest !== 'object') return false;
54
+ if (digest.kind === 'rhythm') return false;
55
+ return ACTION_KINDS.includes(digest.kind) || ACTION_STYLES.includes(digest.style2d);
56
+ }
57
+
58
+ /**
59
+ * What a run asked for: `mode` is `auto` (slow an action game on a run that
60
+ * keeps the game running), `on` (`--time-scale`) or `off` (`--no-slow-motion`).
61
+ *
62
+ * @param {{timeScale?: number, noSlowMotion?: boolean}} options
63
+ * @returns {{mode: 'auto'|'on'|'off', scale: number}}
64
+ */
65
+ export function slowMotionPlan(options = {}) {
66
+ if (options && options.noSlowMotion === true) return { mode: 'off', scale: DEFAULT_TIME_SCALE };
67
+ if (options && options.timeScale !== undefined && validScale(options.timeScale)) return { mode: 'on', scale: options.timeScale };
68
+ return { mode: 'auto', scale: DEFAULT_TIME_SCALE };
69
+ }
70
+
71
+ const validScale = value => typeof value === 'number' && Number.isFinite(value) && value >= MIN_TIME_SCALE && value <= MAX_TIME_SCALE;
72
+
73
+ /**
74
+ * What is wrong with `--time-scale` and `--no-slow-motion`, one sentence each.
75
+ *
76
+ * @param {Object} options
77
+ * @param {string} driverName
78
+ * @returns {string[]}
79
+ */
80
+ export function slowMotionProblems(options = {}, driverName = '') {
81
+ const problems = [];
82
+ const asked = options.timeScale !== undefined;
83
+ if (asked && !validScale(options.timeScale)) problems.push(`Choose --time-scale from ${MIN_TIME_SCALE} to ${MAX_TIME_SCALE}, the share of its speed the game runs at while the playtester decides (0.25 is a quarter). For full speed pass --realtime.`);
84
+ if (asked && options.noSlowMotion === true) problems.push('Pass --time-scale or --no-slow-motion, not both.');
85
+ if ((asked || options.noSlowMotion === true) && driverName && !HOOK_DRIVERS.includes(driverName)) {
86
+ problems.push(`${asked ? '--time-scale' : '--no-slow-motion'} slows a game through its Ravensight SDK's pause hook, which ${HOOK_DRIVERS.join(', ')} reach, and this run uses ${driverName}.`);
87
+ }
88
+ return problems;
89
+ }
90
+
91
+ /** A scale in plain words: "a quarter of its speed", "half its speed", "40% of its speed". */
92
+ export function speedWords(scale) {
93
+ if (!(typeof scale === 'number' && Number.isFinite(scale) && scale > 0)) return 'its normal speed';
94
+ if (Math.abs(scale - 0.25) < 1e-9) return 'a quarter of its speed';
95
+ if (Math.abs(scale - 0.5) < 1e-9) return 'half its speed';
96
+ if (Math.abs(scale - 0.75) < 1e-9) return 'three quarters of its speed';
97
+ return `${Math.round(scale * 100)}% of its speed`;
98
+ }
99
+
100
+ /** The line a driver adds to each observation while the game is slowed. */
101
+ export function slowedObservationLine(scale) {
102
+ return `The game runs at ${speedWords(scale)} while you decide, and at its full speed while your inputs and waits play.`;
103
+ }
104
+
105
+ const seconds = ms => `${Math.round(ms / 100) / 10} s`;
106
+
107
+ /**
108
+ * The sentence the run's report and log carry about the game's speed, or null
109
+ * when nothing was asked of slow motion. Plain words; never a finding.
110
+ *
111
+ * @param {Object|null} timeControl the time control summary (./pauseHook.js)
112
+ * @returns {string|null}
113
+ */
114
+ export function speedSentence(timeControl) {
115
+ const slow = timeControl && timeControl.slow_motion;
116
+ if (!slow || typeof slow !== 'object') return null;
117
+ const why = slow.reason === 'flag' ? 'as --time-scale asked' : 'because it is an action game';
118
+ switch (slow.status) {
119
+ case 'on': {
120
+ const measured = Number.isFinite(slow.slowed_wall_ms) && slow.slowed_wall_ms >= 1000 && Number.isFinite(slow.slowed_game_ms)
121
+ ? ` The game's own clock moved ${seconds(slow.slowed_game_ms)} in ${seconds(slow.slowed_wall_ms)} of those decisions.` : '';
122
+ return `Played at ${speedWords(slow.scale)} while the playtester decided, ${why}, so the playtester could keep up. Inputs and waits played at full speed, and the video is in real time.${measured}`;
123
+ }
124
+ case 'not_supported':
125
+ return `The game's Ravensight SDK did not offer slow motion (the pause hook's time scale), so it played at its normal speed${timeControl.used ? ' and was paused between decisions instead' : ''}.`;
126
+ case 'refused':
127
+ return `The game refused slow motion when the run asked for it, so it played at its normal speed${timeControl.used ? ' and was paused between decisions instead' : ''}.`;
128
+ case 'not_needed':
129
+ return 'The game was paused while the playtester decided, so it did not need slow motion.';
130
+ case 'switched_off':
131
+ return 'Slow motion was switched off for this run (--no-slow-motion), so the game played at its normal speed while the playtester decided.';
132
+ default:
133
+ return null;
134
+ }
135
+ }
136
+
137
+ /** The line report.md carries when the run says how fast the game played. */
138
+ export const SPEED_LABEL = '**Game speed:**';
139
+
140
+ /** report.md with the speed line after the generated-at, played and start lines. */
141
+ export function withSpeedLine(markdown, line) {
142
+ const lines = String(markdown || '').split('\n').filter(entry => !entry.startsWith(SPEED_LABEL));
143
+ if (!line) return lines.join('\n');
144
+ let where = -1;
145
+ lines.forEach((entry, index) => { if (/^\*\*(Generated at|What was played|Where this run started):\*\*/.test(entry)) where = index + 1; });
146
+ if (where === -1) { const heading = lines.findIndex(entry => /^# /.test(entry)); where = heading !== -1 ? heading + 1 : 0; }
147
+ lines.splice(where, 0, `${SPEED_LABEL} ${line}`);
148
+ return lines.join('\n');
149
+ }
150
+
151
+ export default { SPEED_LABEL, withSpeedLine, DEFAULT_TIME_SCALE, MIN_TIME_SCALE, MAX_TIME_SCALE, HOOK_DRIVERS, ACTION_KINDS, ACTION_STYLES, isActionStyle, slowMotionPlan, slowMotionProblems, speedWords, slowedObservationLine, speedSentence };
@@ -3,7 +3,8 @@
3
3
  * game reads them, and a start spec (a level, a turn, a named save) handed to
4
4
  * the game. docs/hosted-direct/NATIVE_GPU_PLAN.md section 5 in the platform
5
5
  * repository is the design; this is its local half for `godot_driver`,
6
- * `android_driver` and `ios_driver`.
6
+ * `android_driver`, `ios_driver`, and the desktop drivers on a Mac
7
+ * (`desktop_driver`, `unity_driver`, `unreal_driver`).
7
8
  *
8
9
  * A cloud web playtest has its own save path (`hosted run --save`,
9
10
  * ../hosted/recordedRun.js: one file, browser storage). This file never
@@ -13,6 +14,9 @@
13
14
  * --save-target <where> the root and the path inside it:
14
15
  * godot:user://<path> Godot's user:// folder
15
16
  * unity:persistent://<path> Unity's Application.persistentDataPath
17
+ * unreal:saved://<path> an Unreal game's Saved folder (SaveGames/ inside it)
18
+ * desktop:appdata://<path> Library/Application Support in a desktop run's own home
19
+ * desktop:home://<path> a desktop run's own home folder
16
20
  * a path ending in "/" is a folder, and each file keeps its own name
17
21
  * --start-spec <text> free text up to 1,000 characters, such as {"level":"12"} or turn=150
18
22
  *
@@ -23,8 +27,24 @@
23
27
  * | godot:user:// | a user folder of the run's own, never the developer's | /data/data/<package>/files (a debuggable build, through run-as) | the app's Documents |
24
28
  * | unity:persistent:// | not a local path | /sdcard/Android/data/<package>/files | the app's Documents |
25
29
  *
30
+ * A desktop run on a Mac (./drivers/desktop/runHome.js) that starts from a
31
+ * save, or plays several sessions, starts the game on a folder of the run's
32
+ * own, removed when the run ends; the developer's own saves are never read or
33
+ * written. desktop_driver and unity_driver give the game a home of its own
34
+ * (HOME and CFFIXED_USER_HOME, which macOS reads for the user's Library);
35
+ * unreal_driver gives an Unreal game its own user folder (-userdir), inside
36
+ * its container when it is in the App Sandbox. Under that folder:
37
+ *
38
+ * | Root | desktop_driver | unity_driver | unreal_driver |
39
+ * |---|---|---|---|
40
+ * | desktop:home:// | the home | the home | no |
41
+ * | desktop:appdata:// | Library/Application Support | the same | no |
42
+ * | unity:persistent:// | no | Library/Application Support/<bundle id> | no |
43
+ * | unreal:saved:// | no | no | Saved |
44
+ *
26
45
  * The start spec reaches the game as RAVENSIGHT_PLAYTEST_START (the Godot
27
- * process's environment, the simulator app's environment), as the intent
46
+ * process's environment, a desktop game's environment, the simulator app's
47
+ * environment), as the intent
28
48
  * extra `ravensight_playtest_start` on Android, and on Godot through the
29
49
  * driver addon's `playtest_start` call to a method the game defines,
30
50
  * `_ravensight_playtest_start(spec)`, whose answer (what it loaded) the
@@ -42,14 +62,27 @@ export const MAX_SAVE_TOTAL_BYTES = 256 * 1024 * 1024;
42
62
  export const MAX_SAVE_PATH_CHARS = 200;
43
63
  export const MAX_START_SPEC_CHARS = 1000;
44
64
 
65
+ /** The desktop drivers on a Mac, which start the game on a folder of the run's own (./drivers/desktop/runHome.js). */
66
+ export const DESKTOP_START_DRIVERS = Object.freeze(['desktop_driver', 'unity_driver', 'unreal_driver']);
67
+ /** The desktop drivers that give the game a whole home folder of the run's own. */
68
+ const HOME_DRIVERS = Object.freeze(['desktop_driver', 'unity_driver']);
69
+
45
70
  /** The roots a save may be placed under, and the drivers that can place each. */
46
71
  export const SAVE_ROOTS = Object.freeze({
47
72
  godot_user: { prefix: 'godot:user://', drivers: ['godot_driver', 'android_driver', 'ios_driver'] },
48
- unity_persistent: { prefix: 'unity:persistent://', drivers: ['android_driver', 'ios_driver'] }
73
+ unity_persistent: { prefix: 'unity:persistent://', drivers: ['android_driver', 'ios_driver', 'unity_driver'] },
74
+ unreal_saved: { prefix: 'unreal:saved://', drivers: ['unreal_driver'] },
75
+ desktop_appdata: { prefix: 'desktop:appdata://', drivers: HOME_DRIVERS },
76
+ desktop_home: { prefix: 'desktop:home://', drivers: HOME_DRIVERS }
49
77
  });
50
78
 
51
79
  /** The drivers a run can start from a save or a start spec on. */
52
- export const START_DRIVERS = Object.freeze(['godot_driver', 'android_driver', 'ios_driver']);
80
+ export const START_DRIVERS = Object.freeze(['godot_driver', 'android_driver', 'ios_driver', ...DESKTOP_START_DRIVERS]);
81
+
82
+ /** The save roots a driver can place files under, as the studio writes them. */
83
+ export function rootsFor(driverName) {
84
+ return Object.values(SAVE_ROOTS).filter(root => root.drivers.includes(driverName)).map(root => root.prefix);
85
+ }
53
86
 
54
87
  /** The environment variable, intent extra and addon method names the game reads. */
55
88
  export const START_ENV = 'RAVENSIGHT_PLAYTEST_START';
@@ -99,7 +132,7 @@ export function saveTargetOf(value) {
99
132
  const checked = relativeSavePath(rest, { folder });
100
133
  return checked.error ? { error: checked.error } : { root, path: checked.path, folder };
101
134
  }
102
- return { error: 'Choose --save-target as godot:user://<path> or unity:persistent://<path>.' };
135
+ return { error: `Choose --save-target as ${Object.values(SAVE_ROOTS).map(root => `${root.prefix}<path>`).join(', ')}.` };
103
136
  }
104
137
 
105
138
  /** A save target as the studio wrote it, for lines a person reads. */
@@ -121,17 +154,17 @@ export function startProblems(options = {}, driverName = '') {
121
154
  const asked = saves.length > 0 || options.saveTarget !== undefined || options.startSpec !== undefined;
122
155
  if (!asked) return problems;
123
156
  if (!START_DRIVERS.includes(driverName)) {
124
- problems.push(`--save and --start-spec start a native local run (Godot, an Android emulator or an iOS simulator), and this run uses ${driverName || 'no driver'}. A web build starts at --start, or from a save with hosted run --save.`);
157
+ problems.push(`--save and --start-spec start a native local run (Godot, a desktop game on this Mac, an Android emulator or an iOS simulator), and this run uses ${driverName || 'no driver'}. A web build starts at --start, or from a save with hosted run --save.`);
125
158
  return problems;
126
159
  }
127
160
  if (saves.length > MAX_SAVE_FILES) problems.push(`Give --save at most ${MAX_SAVE_FILES} times.`);
128
- if (saves.length > 0 && options.saveTarget === undefined) problems.push('Say where the game reads the save with --save-target, such as godot:user://saves/slot1.sav or unity:persistent://saves/.');
161
+ if (saves.length > 0 && options.saveTarget === undefined) problems.push(`Say where the game reads the save with --save-target, such as ${rootsFor(driverName).slice(0, 2).map(prefix => `${prefix}saves/`).join(' or ')}.`);
129
162
  if (options.saveTarget !== undefined && saves.length === 0) problems.push('--save-target says where a save goes. Name the file with --save.');
130
163
  if (options.saveTarget !== undefined) {
131
164
  const target = saveTargetOf(options.saveTarget);
132
165
  if (target.error) problems.push(`--save-target: ${target.error}.`);
133
166
  else {
134
- if (!SAVE_ROOTS[target.root].drivers.includes(driverName)) problems.push(`${SAVE_ROOTS[target.root].prefix} is not a folder ${driverName} can reach on this machine. A Godot game run here reads godot:user://.`);
167
+ if (!SAVE_ROOTS[target.root].drivers.includes(driverName)) problems.push(`${SAVE_ROOTS[target.root].prefix} is not a folder ${driverName} can reach on this machine. It places saves under ${rootsFor(driverName).join(' or ')}.`);
135
168
  if (saves.length > 1 && !target.folder) problems.push('With several --save files, --save-target names a folder: end it with /.');
136
169
  }
137
170
  }
@@ -412,4 +445,4 @@ export function withStartLine(markdown, line) {
412
445
  return lines.join('\n');
413
446
  }
414
447
 
415
- export default { startReportLine, withStartLine, relativeSavePath, saveTargetOf, startProblems, resolveStart, startRecord, startLines, briefWithStart, godotDataDir, shellWord, placeSavesInFolder, androidSavePath, placeSavesOnAndroid };
448
+ export default { rootsFor, startReportLine, withStartLine, relativeSavePath, saveTargetOf, startProblems, resolveStart, startRecord, startLines, briefWithStart, godotDataDir, shellWord, placeSavesInFolder, androidSavePath, placeSavesOnAndroid };