@datamoc/mw_games 0.11.0 → 0.13.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/CHANGELOG.md +84 -0
- package/dist/audio/Playable.d.ts +2 -0
- package/dist/audio/Playable.d.ts.map +1 -1
- package/dist/audio/Playable.js.map +1 -1
- package/dist/audio/Sound.d.ts +7 -1
- package/dist/audio/Sound.d.ts.map +1 -1
- package/dist/audio/Sound.js +8 -1
- package/dist/audio/Sound.js.map +1 -1
- package/dist/core/DialogueText.d.ts +47 -0
- package/dist/core/DialogueText.d.ts.map +1 -0
- package/dist/core/DialogueText.js +43 -0
- package/dist/core/DialogueText.js.map +1 -0
- package/dist/core/Twee.d.ts +67 -0
- package/dist/core/Twee.d.ts.map +1 -0
- package/dist/core/Twee.js +140 -0
- package/dist/core/Twee.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/mw_games.global.js +116 -115
- package/dist/rpg/EventRunner.d.ts +24 -0
- package/dist/rpg/EventRunner.d.ts.map +1 -1
- package/dist/rpg/EventRunner.js +56 -15
- package/dist/rpg/EventRunner.js.map +1 -1
- package/dist/rpg/GridMover.d.ts +6 -0
- package/dist/rpg/GridMover.d.ts.map +1 -1
- package/dist/rpg/GridMover.js +17 -0
- package/dist/rpg/GridMover.js.map +1 -1
- package/dist/rpg/MoveRoute.d.ts +87 -0
- package/dist/rpg/MoveRoute.d.ts.map +1 -0
- package/dist/rpg/MoveRoute.js +110 -0
- package/dist/rpg/MoveRoute.js.map +1 -0
- package/dist/rpg/dialogue-text.d.ts +81 -0
- package/dist/rpg/dialogue-text.d.ts.map +1 -0
- package/dist/rpg/dialogue-text.js +88 -0
- package/dist/rpg/dialogue-text.js.map +1 -0
- package/dist/rpg/index.d.ts +6 -1
- package/dist/rpg/index.d.ts.map +1 -1
- package/dist/rpg/index.js +3 -0
- package/dist/rpg/index.js.map +1 -1
- package/dist/rpg/twee-events.d.ts +48 -0
- package/dist/rpg/twee-events.d.ts.map +1 -0
- package/dist/rpg/twee-events.js +35 -0
- package/dist/rpg/twee-events.js.map +1 -0
- package/dist/two-d/stage/dialogue-text.d.ts +81 -0
- package/dist/two-d/stage/dialogue-text.d.ts.map +1 -0
- package/dist/two-d/stage/dialogue-text.js +95 -0
- package/dist/two-d/stage/dialogue-text.js.map +1 -0
- package/dist/two-d/stage/index.d.ts +1 -0
- package/dist/two-d/stage/index.d.ts.map +1 -1
- package/dist/two-d/stage/index.js +1 -0
- package/dist/two-d/stage/index.js.map +1 -1
- package/dist/two-d/stage/twee.d.ts +7 -25
- package/dist/two-d/stage/twee.d.ts.map +1 -1
- package/dist/two-d/stage/twee.js +10 -162
- package/dist/two-d/stage/twee.js.map +1 -1
- package/dist/two-d/ui/EventDialogue.d.ts.map +1 -1
- package/dist/two-d/ui/EventDialogue.js +7 -1
- package/dist/two-d/ui/EventDialogue.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -6,11 +6,15 @@ export interface EventChoice {
|
|
|
6
6
|
text: string;
|
|
7
7
|
value?: unknown;
|
|
8
8
|
disabled?: boolean;
|
|
9
|
+
/** the passage to jump to when this choice is picked, in an `EventRunner.runStory` story */
|
|
10
|
+
goto?: string;
|
|
9
11
|
}
|
|
10
12
|
/** what the runner wants shown; how it looks is the presenter's business entirely */
|
|
11
13
|
export interface DialogueRequest {
|
|
12
14
|
text: string;
|
|
13
15
|
speaker?: string;
|
|
16
|
+
/** an opaque, renderer-specific portrait image; `two-d/ui.messageBoxPresenter` expects a `Texture2D` */
|
|
17
|
+
portrait?: unknown;
|
|
14
18
|
/** present when the runner is asking rather than telling; resolve with the chosen `value` */
|
|
15
19
|
choices?: EventChoice[];
|
|
16
20
|
}
|
|
@@ -41,9 +45,11 @@ export interface MoveStep {
|
|
|
41
45
|
export type EventCommand = {
|
|
42
46
|
say: string;
|
|
43
47
|
speaker?: string;
|
|
48
|
+
portrait?: unknown;
|
|
44
49
|
} | {
|
|
45
50
|
ask: string;
|
|
46
51
|
speaker?: string;
|
|
52
|
+
portrait?: unknown;
|
|
47
53
|
choices: EventChoice[];
|
|
48
54
|
store?: string;
|
|
49
55
|
} | {
|
|
@@ -66,9 +72,18 @@ export type EventCommand = {
|
|
|
66
72
|
target: string;
|
|
67
73
|
steps: MoveStep[];
|
|
68
74
|
};
|
|
75
|
+
} | {
|
|
76
|
+
goto: string;
|
|
69
77
|
} | {
|
|
70
78
|
call: (state: EventRunnerState) => void | Promise<void>;
|
|
71
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* A branching event script: named passages, the same graph shape `two-d/stage`'s
|
|
82
|
+
* `StoryScript` is - a passage runs until it falls off the end, a `{ goto }` command or a
|
|
83
|
+
* choice's own `goto` jumps to a different one. `EventRunner.runStory` follows it the same
|
|
84
|
+
* way `StageScript.runStory` follows a `StoryScript`.
|
|
85
|
+
*/
|
|
86
|
+
export type EventStoryScript = Record<string, readonly EventCommand[]>;
|
|
72
87
|
export interface EventRunnerState {
|
|
73
88
|
game: GameState;
|
|
74
89
|
/** whatever `ask` commands have stored, keyed by their `store` name */
|
|
@@ -102,6 +117,15 @@ export declare class EventRunner {
|
|
|
102
117
|
constructor(options: EventRunnerOptions);
|
|
103
118
|
cancel(): void;
|
|
104
119
|
run(commands: readonly EventCommand[]): Promise<EventRunnerState>;
|
|
120
|
+
/**
|
|
121
|
+
* Runs a graph of passages starting at `start`, following `goto` commands and choice
|
|
122
|
+
* jumps until a passage runs out or the script is cancelled - the `EventCommand`
|
|
123
|
+
* counterpart to `StageScript.runStory`.
|
|
124
|
+
*/
|
|
125
|
+
runStory(story: EventStoryScript, start: string): Promise<EventRunnerState>;
|
|
126
|
+
/** runs a plain list of commands, returning the passage to jump to, if any */
|
|
127
|
+
private runList;
|
|
128
|
+
/** runs one command; returns the passage to jump to, if the command jumps anywhere */
|
|
105
129
|
private step;
|
|
106
130
|
private speak;
|
|
107
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventRunner.d.ts","sourceRoot":"","sources":["../../src/rpg/EventRunner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"EventRunner.d.ts","sourceRoot":"","sources":["../../src/rpg/EventRunner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,6FAA6F;IAC7F,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/E,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACX;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GACrB;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;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sF;IACtF,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,QAAQ,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,OAAO,CAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,OAAO,CAAC,SAAS,CAAS;IAE1B,YAAY,OAAO,EAAE,kBAAkB,EAGtC;IAED,MAAM,IAAI,IAAI,CAEb;IAEK,GAAG,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAMtE;IAED;;;;OAIG;IACG,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmBhF;IAED,8EAA8E;YAChE,OAAO;IASrB,sFAAsF;YACxE,IAAI;IAsDlB,OAAO,CAAC,KAAK;CAQb"}
|
package/dist/rpg/EventRunner.js
CHANGED
|
@@ -23,56 +23,97 @@ export class EventRunner {
|
|
|
23
23
|
this.cancelled = true;
|
|
24
24
|
}
|
|
25
25
|
async run(commands) {
|
|
26
|
-
|
|
26
|
+
const jump = await this.runList(commands);
|
|
27
|
+
if (jump !== undefined) {
|
|
28
|
+
throw new Error(`a "goto ${jump}" only runs inside runStory, not a straight run`);
|
|
29
|
+
}
|
|
30
|
+
return this.state;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Runs a graph of passages starting at `start`, following `goto` commands and choice
|
|
34
|
+
* jumps until a passage runs out or the script is cancelled - the `EventCommand`
|
|
35
|
+
* counterpart to `StageScript.runStory`.
|
|
36
|
+
*/
|
|
37
|
+
async runStory(story, start) {
|
|
38
|
+
if (!Object.prototype.hasOwnProperty.call(story, start)) {
|
|
39
|
+
throw new Error(`this event story has no passage named "${start}"`);
|
|
40
|
+
}
|
|
41
|
+
let commands = story[start];
|
|
42
|
+
let index = 0;
|
|
43
|
+
while (index < commands.length) {
|
|
27
44
|
if (this.cancelled)
|
|
28
45
|
break;
|
|
29
|
-
await this.step(
|
|
46
|
+
const jump = await this.step(commands[index]);
|
|
47
|
+
index++;
|
|
48
|
+
if (jump !== undefined) {
|
|
49
|
+
if (!Object.prototype.hasOwnProperty.call(story, jump)) {
|
|
50
|
+
throw new Error(`this event story has no passage named "${jump}"`);
|
|
51
|
+
}
|
|
52
|
+
commands = story[jump];
|
|
53
|
+
index = 0;
|
|
54
|
+
}
|
|
30
55
|
}
|
|
31
56
|
return this.state;
|
|
32
57
|
}
|
|
58
|
+
/** runs a plain list of commands, returning the passage to jump to, if any */
|
|
59
|
+
async runList(commands) {
|
|
60
|
+
for (const command of commands) {
|
|
61
|
+
if (this.cancelled)
|
|
62
|
+
break;
|
|
63
|
+
const jump = await this.step(command);
|
|
64
|
+
if (jump !== undefined)
|
|
65
|
+
return jump;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/** runs one command; returns the passage to jump to, if the command jumps anywhere */
|
|
33
70
|
async step(command) {
|
|
34
71
|
if ('say' in command) {
|
|
35
|
-
await this.speak(command.say, command.speaker);
|
|
36
|
-
return;
|
|
72
|
+
await this.speak(command.say, command.speaker, command.portrait);
|
|
73
|
+
return undefined;
|
|
37
74
|
}
|
|
38
75
|
if ('ask' in command) {
|
|
39
|
-
const chosen = await this.speak(command.ask, command.speaker, command.choices);
|
|
76
|
+
const chosen = await this.speak(command.ask, command.speaker, command.portrait, command.choices);
|
|
40
77
|
if (command.store)
|
|
41
78
|
this.state.answers[command.store] = chosen;
|
|
42
|
-
|
|
79
|
+
//a MessageBox resolves with the chosen value, which defaults to the text
|
|
80
|
+
return command.choices.find((c) => (c.value ?? c.text) === chosen)?.goto;
|
|
43
81
|
}
|
|
44
82
|
if ('wait' in command) {
|
|
45
83
|
await new Promise((resolve) => setTimeout(resolve, command.wait * 1000));
|
|
46
|
-
return;
|
|
84
|
+
return undefined;
|
|
47
85
|
}
|
|
48
86
|
if ('setSwitch' in command) {
|
|
49
87
|
this.state.game.setSwitch(command.setSwitch, command.value);
|
|
50
|
-
return;
|
|
88
|
+
return undefined;
|
|
51
89
|
}
|
|
52
90
|
if ('setVariable' in command) {
|
|
53
91
|
this.state.game.setVariable(command.setVariable, command.value);
|
|
54
|
-
return;
|
|
92
|
+
return undefined;
|
|
55
93
|
}
|
|
56
94
|
if ('addVariable' in command) {
|
|
57
95
|
const current = this.state.game.variable(command.addVariable);
|
|
58
96
|
this.state.game.setVariable(command.addVariable, current + command.amount);
|
|
59
|
-
return;
|
|
97
|
+
return undefined;
|
|
60
98
|
}
|
|
61
99
|
if ('if' in command) {
|
|
62
100
|
const holds = conditionHolds(command.if, this.state.game);
|
|
63
|
-
|
|
64
|
-
return;
|
|
101
|
+
return this.runList(holds ? command.then : (command.else ?? []));
|
|
65
102
|
}
|
|
66
103
|
if ('move' in command) {
|
|
67
104
|
await this.options.move?.(command.move.target, command.move.steps);
|
|
68
|
-
return;
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
if ('goto' in command) {
|
|
108
|
+
return command.goto;
|
|
69
109
|
}
|
|
70
110
|
if ('call' in command) {
|
|
71
111
|
await command.call(this.state);
|
|
72
112
|
}
|
|
113
|
+
return undefined;
|
|
73
114
|
}
|
|
74
|
-
speak(text, speaker, choices) {
|
|
75
|
-
return this.options.present({ text, speaker, choices });
|
|
115
|
+
speak(text, speaker, portrait, choices) {
|
|
116
|
+
return this.options.present({ text, speaker, portrait, choices });
|
|
76
117
|
}
|
|
77
118
|
}
|
|
78
119
|
//# sourceMappingURL=EventRunner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventRunner.js","sourceRoot":"","sources":["../../src/rpg/EventRunner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EventRunner.js","sourceRoot":"","sources":["../../src/rpg/EventRunner.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C1D,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnE,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,IAAI,CAAC;QACrB,CAAC;QAED,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACvB,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAEO,KAAK,CACZ,IAAY,EACZ,OAA2B,EAC3B,QAAkB,EAClB,OAAuB;QAEvB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC;CACD"}
|
package/dist/rpg/GridMover.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export declare class GridMover {
|
|
|
57
57
|
turnTo(dx: number, dy: number): void;
|
|
58
58
|
/** starts moving one tile in the given direction; false when already moving */
|
|
59
59
|
moveBy(dx: number, dy: number): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Repositions by a delta instantly, with no tween and no walk animation - what a "jump"
|
|
62
|
+
* move-route step is, as opposed to `moveBy`'s glide. Refuses while a `moveBy` is still in
|
|
63
|
+
* flight, the same as `moveBy` itself does, rather than fighting over `x`/`y` mid-tween.
|
|
64
|
+
*/
|
|
65
|
+
jumpBy(dx: number, dy: number): boolean;
|
|
60
66
|
update(dt: number): void;
|
|
61
67
|
private place;
|
|
62
68
|
private playWalk;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridMover.d.ts","sourceRoot":"","sources":["../../src/rpg/GridMover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAsB,MAAM,oBAAoB,CAAC;AAE5E,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IAEnB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,sFAAsF;IACtF,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,MAAM,CAAC;IAElD,2EAA2E;IAC3E,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,KAAK,MAAM,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,SAAS;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,EAAE,UAAU,CAAU;IAE5B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAmB;IAElC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,QAAQ,CAAK;IAErB,YAAY,MAAM,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAWjF;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;;OAKG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,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ErB,YAAY,MAAM,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAWjF;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;;OAKG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAInC;IAED,+EAA+E;IAC/E,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAUtC;IAED;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAWtC;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAcvB;IAED,OAAO,CAAC,KAAK;IAKb,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,QAAQ;CAGhB"}
|
package/dist/rpg/GridMover.js
CHANGED
|
@@ -64,6 +64,23 @@ export class GridMover {
|
|
|
64
64
|
this.playWalk();
|
|
65
65
|
return true;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Repositions by a delta instantly, with no tween and no walk animation - what a "jump"
|
|
69
|
+
* move-route step is, as opposed to `moveBy`'s glide. Refuses while a `moveBy` is still in
|
|
70
|
+
* flight, the same as `moveBy` itself does, rather than fighting over `x`/`y` mid-tween.
|
|
71
|
+
*/
|
|
72
|
+
jumpBy(dx, dy) {
|
|
73
|
+
if (this.target)
|
|
74
|
+
return false;
|
|
75
|
+
this.facing = directionOf(dx, dy);
|
|
76
|
+
this.x += dx;
|
|
77
|
+
this.y += dy;
|
|
78
|
+
this.fromX = this.x;
|
|
79
|
+
this.fromY = this.y;
|
|
80
|
+
this.place();
|
|
81
|
+
this.playIdle();
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
67
84
|
update(dt) {
|
|
68
85
|
this.sprite.update?.(dt);
|
|
69
86
|
if (!this.target)
|
|
@@ -1 +1 @@
|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CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { GridMover, type Direction4 } from './GridMover.ts';
|
|
2
|
+
/**
|
|
3
|
+
* One step of a `MoveRoute`, run in order against a `GridMover`. Unlike `GridMover.moveBy`
|
|
4
|
+
* itself, a route step does not always know its own `dx`/`dy` up front - `random`, `toward`
|
|
5
|
+
* and `away` resolve a direction only when the runner actually reaches that step, against
|
|
6
|
+
* wherever the mover and (for `toward`/`away`) the target happen to be at that moment.
|
|
7
|
+
*/
|
|
8
|
+
export type MoveRouteStep = {
|
|
9
|
+
dir: Direction4;
|
|
10
|
+
} | {
|
|
11
|
+
dir: 'random';
|
|
12
|
+
} | {
|
|
13
|
+
dir: 'toward' | 'away';
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
} | {
|
|
17
|
+
turn: Direction4 | 'random';
|
|
18
|
+
} | {
|
|
19
|
+
jump: {
|
|
20
|
+
dx: number;
|
|
21
|
+
dy: number;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
wait: number;
|
|
25
|
+
};
|
|
26
|
+
export interface MoveRoute {
|
|
27
|
+
steps: readonly MoveRouteStep[];
|
|
28
|
+
/** loops back to the first step once the last one finishes, rather than stopping there */
|
|
29
|
+
repeat?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* when a directional step's target tile is refused by `canMove`, move on to the next step
|
|
32
|
+
* immediately rather than retrying the same step every tick until it opens up
|
|
33
|
+
*/
|
|
34
|
+
skippable?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface MoveRouteOptions {
|
|
37
|
+
/** asked before every directional/jump step, the same contract `GridMover` itself expects of its caller */
|
|
38
|
+
canMove?: (dx: number, dy: number) => boolean;
|
|
39
|
+
/** source of randomness for `random` steps; defaults to `Math.random` */
|
|
40
|
+
random?: () => number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Drives a `GridMover` through a `MoveRoute` over successive `update(dt)` calls - the piece
|
|
44
|
+
* `GridMover`'s own one-step-at-a-time `moveBy`/`turnTo` deliberately leaves out (see its own
|
|
45
|
+
* doc comment: whether a step is passable is the caller's question, not the mover's). Works
|
|
46
|
+
* against any `GridMover`, not only the player's - an NPC's wandering or patrol route is the
|
|
47
|
+
* same shape as a scripted cutscene walk.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { GridMover, MoveRouteRunner, type MoveRoute } from '@datamoc/mw_games/rpg';
|
|
52
|
+
* import type { MovableSprite } from '@datamoc/mw_games/rpg';
|
|
53
|
+
*
|
|
54
|
+
* declare const npcSprite: MovableSprite;
|
|
55
|
+
* declare function tilePassable(x: number, y: number): boolean;
|
|
56
|
+
*
|
|
57
|
+
* const mover = new GridMover(npcSprite, 3, 3, { tileWidth: 32, tileHeight: 32 });
|
|
58
|
+
* const patrol: MoveRoute = {
|
|
59
|
+
* steps: [{ dir: 'right' }, { dir: 'right' }, { wait: 1 }, { dir: 'left' }, { dir: 'left' }],
|
|
60
|
+
* repeat: true,
|
|
61
|
+
* };
|
|
62
|
+
* const route = new MoveRouteRunner(mover, patrol, {
|
|
63
|
+
* canMove: (dx, dy) => tilePassable(mover.x + dx, mover.y + dy),
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // in the game loop:
|
|
67
|
+
* mover.update(1 / 60);
|
|
68
|
+
* route.update(1 / 60);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare class MoveRouteRunner {
|
|
72
|
+
private mover;
|
|
73
|
+
private route;
|
|
74
|
+
private options;
|
|
75
|
+
private index;
|
|
76
|
+
private waiting;
|
|
77
|
+
constructor(mover: GridMover, route: MoveRoute, options?: MoveRouteOptions);
|
|
78
|
+
/** true once a non-repeating route has run every step */
|
|
79
|
+
get done(): boolean;
|
|
80
|
+
update(dt: number): void;
|
|
81
|
+
/** @returns whether the step actually moved/turned/waited, so the runner can decide to skip it */
|
|
82
|
+
private runStep;
|
|
83
|
+
private resolveDirection;
|
|
84
|
+
private attempt;
|
|
85
|
+
private pickDirection;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=MoveRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoveRoute.d.ts","sourceRoot":"","sources":["../../src/rpg/MoveRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAW5D;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GACtB;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,GACnB;IAAE,GAAG,EAAE,QAAQ,CAAA;CAAE,GACjB;IAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpB,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAEhC,0FAA0F;IAC1F,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAChC,2GAA2G;IAC3G,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IAE9C,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,KAAK,CAAY;IACzB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,OAAO,CAAK;IAEpB,YAAY,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,gBAAqB,EAI7E;IAED,yDAAyD;IACzD,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAevB;IAED,kGAAkG;IAClG,OAAO,CAAC,OAAO;IAqBf,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,aAAa;CAIrB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { GridMover } from './GridMover.js';
|
|
2
|
+
const DIRECTIONS = ['up', 'down', 'left', 'right'];
|
|
3
|
+
const DELTA = {
|
|
4
|
+
up: { dx: 0, dy: -1 },
|
|
5
|
+
down: { dx: 0, dy: 1 },
|
|
6
|
+
left: { dx: -1, dy: 0 },
|
|
7
|
+
right: { dx: 1, dy: 0 },
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Drives a `GridMover` through a `MoveRoute` over successive `update(dt)` calls - the piece
|
|
11
|
+
* `GridMover`'s own one-step-at-a-time `moveBy`/`turnTo` deliberately leaves out (see its own
|
|
12
|
+
* doc comment: whether a step is passable is the caller's question, not the mover's). Works
|
|
13
|
+
* against any `GridMover`, not only the player's - an NPC's wandering or patrol route is the
|
|
14
|
+
* same shape as a scripted cutscene walk.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { GridMover, MoveRouteRunner, type MoveRoute } from '@datamoc/mw_games/rpg';
|
|
19
|
+
* import type { MovableSprite } from '@datamoc/mw_games/rpg';
|
|
20
|
+
*
|
|
21
|
+
* declare const npcSprite: MovableSprite;
|
|
22
|
+
* declare function tilePassable(x: number, y: number): boolean;
|
|
23
|
+
*
|
|
24
|
+
* const mover = new GridMover(npcSprite, 3, 3, { tileWidth: 32, tileHeight: 32 });
|
|
25
|
+
* const patrol: MoveRoute = {
|
|
26
|
+
* steps: [{ dir: 'right' }, { dir: 'right' }, { wait: 1 }, { dir: 'left' }, { dir: 'left' }],
|
|
27
|
+
* repeat: true,
|
|
28
|
+
* };
|
|
29
|
+
* const route = new MoveRouteRunner(mover, patrol, {
|
|
30
|
+
* canMove: (dx, dy) => tilePassable(mover.x + dx, mover.y + dy),
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // in the game loop:
|
|
34
|
+
* mover.update(1 / 60);
|
|
35
|
+
* route.update(1 / 60);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export class MoveRouteRunner {
|
|
39
|
+
constructor(mover, route, options = {}) {
|
|
40
|
+
this.index = 0;
|
|
41
|
+
this.waiting = 0;
|
|
42
|
+
this.mover = mover;
|
|
43
|
+
this.route = route;
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
46
|
+
/** true once a non-repeating route has run every step */
|
|
47
|
+
get done() {
|
|
48
|
+
return !this.route.repeat && this.index >= this.route.steps.length;
|
|
49
|
+
}
|
|
50
|
+
update(dt) {
|
|
51
|
+
if (this.mover.isMoving || this.done)
|
|
52
|
+
return;
|
|
53
|
+
if (this.waiting > 0) {
|
|
54
|
+
this.waiting = Math.max(0, this.waiting - dt);
|
|
55
|
+
if (this.waiting > 0)
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (this.index >= this.route.steps.length) {
|
|
59
|
+
this.index = 0;
|
|
60
|
+
}
|
|
61
|
+
const step = this.route.steps[this.index];
|
|
62
|
+
const advanced = this.runStep(step);
|
|
63
|
+
if (advanced || this.route.skippable)
|
|
64
|
+
this.index++;
|
|
65
|
+
}
|
|
66
|
+
/** @returns whether the step actually moved/turned/waited, so the runner can decide to skip it */
|
|
67
|
+
runStep(step) {
|
|
68
|
+
if ('turn' in step) {
|
|
69
|
+
const direction = step.turn === 'random' ? this.pickDirection() : step.turn;
|
|
70
|
+
const { dx, dy } = DELTA[direction];
|
|
71
|
+
this.mover.turnTo(dx, dy);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if ('wait' in step) {
|
|
75
|
+
this.waiting = step.wait;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if ('jump' in step) {
|
|
79
|
+
return this.attempt(step.jump.dx, step.jump.dy, (dx, dy) => this.mover.jumpBy(dx, dy));
|
|
80
|
+
}
|
|
81
|
+
const { dx, dy } = this.resolveDirection(step);
|
|
82
|
+
return this.attempt(dx, dy, (dx, dy) => this.mover.moveBy(dx, dy));
|
|
83
|
+
}
|
|
84
|
+
resolveDirection(step) {
|
|
85
|
+
if (step.dir === 'random')
|
|
86
|
+
return DELTA[this.pickDirection()];
|
|
87
|
+
if (step.dir === 'toward' || step.dir === 'away') {
|
|
88
|
+
const sign = step.dir === 'toward' ? 1 : -1;
|
|
89
|
+
const ddx = step.x - this.mover.x;
|
|
90
|
+
const ddy = step.y - this.mover.y;
|
|
91
|
+
//the larger axis first, matching the direction a step would actually close (or open)
|
|
92
|
+
return Math.abs(ddx) >= Math.abs(ddy)
|
|
93
|
+
? { dx: sign * Math.sign(ddx) || 0, dy: 0 }
|
|
94
|
+
: { dx: 0, dy: sign * Math.sign(ddy) || 0 };
|
|
95
|
+
}
|
|
96
|
+
return DELTA[step.dir];
|
|
97
|
+
}
|
|
98
|
+
attempt(dx, dy, move) {
|
|
99
|
+
if (dx === 0 && dy === 0)
|
|
100
|
+
return true;
|
|
101
|
+
if (this.options.canMove && !this.options.canMove(dx, dy))
|
|
102
|
+
return false;
|
|
103
|
+
return move(dx, dy);
|
|
104
|
+
}
|
|
105
|
+
pickDirection() {
|
|
106
|
+
const random = this.options.random ?? Math.random;
|
|
107
|
+
return DIRECTIONS[Math.floor(random() * DIRECTIONS.length)];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL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C,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAEO,OAAO,CAAC,EAAU,EAAE,EAAU,EAAE,IAAyC;QAChF,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QACxE,OAAO,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACrB,CAAC;IAEO,aAAa;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QAClD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAE,CAAC;IAC9D,CAAC;CACD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Catalog, Direction } from '../i18n/index.ts';
|
|
2
|
+
import type { EventCommand } from './EventRunner.ts';
|
|
3
|
+
/**
|
|
4
|
+
* A terse, line-based text format for straight (non-branching) dialogue - the format a
|
|
5
|
+
* text-only RPG (`core` plus `rpg`, no renderer at all) can use for its own `EventCommand`
|
|
6
|
+
* scripts without depending on `two-d` for anything. `two-d/stage` has its own wrapper
|
|
7
|
+
* around the same parsing engine (`core.parseDialogueLines`) targeting `StageCommand`
|
|
8
|
+
* instead - declared separately for the same reason `EventChoice` is declared separately
|
|
9
|
+
* from `two-d/ui`'s `Choice`: a Pixi-based visual novel that never touches `rpg`'s map
|
|
10
|
+
* events should not have to pull the whole module in just to parse dialogue text, and a
|
|
11
|
+
* text-only RPG should not have to pull in Pixi either. The actual `@id`/`-` parsing logic
|
|
12
|
+
* lives once in `core.parseDialogueLines`, not copied between the two - only the final
|
|
13
|
+
* command shape (`speaker` here, `as` in `two-d/stage`) differs.
|
|
14
|
+
*
|
|
15
|
+
* Three kinds of line:
|
|
16
|
+
*
|
|
17
|
+
* - `@id text` names who is speaking and says `text`; `@id` alone (no text) just registers
|
|
18
|
+
* the speaker, without saying anything yet.
|
|
19
|
+
* - `- text` continues the two-speaker exchange the first two `@id` lines opened,
|
|
20
|
+
* alternating speaker on every line: the first `-` after the two openers goes to
|
|
21
|
+
* whichever of them did not speak last, and so on.
|
|
22
|
+
* - any other non-blank line narrates, with no speaker.
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
25
|
+
* @alice Hello.
|
|
26
|
+
* @bob Hi!
|
|
27
|
+
* - How are you?
|
|
28
|
+
* - Fine, and you?
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* The `-` shorthand is deliberately capped at two speakers: it exists for the two-character
|
|
32
|
+
* back-and-forth, not as a guess at which of three or more people talks next. A third
|
|
33
|
+
* distinct `@id` anywhere in the source is a parse error rather than a silent guess; a scene
|
|
34
|
+
* with more than two speakers writes `@id` on every line instead, same as it does today.
|
|
35
|
+
*
|
|
36
|
+
* Lines reach `EventCommand.say` as plain, untranslated text - a game's own translation step
|
|
37
|
+
* decides how that text reaches a player, the same seam MWL's own `_("...")`-marked strings
|
|
38
|
+
* use (the source text doubles as the catalog key). `extractDialogueCatalog` builds that
|
|
39
|
+
* catalog the same way MWL's `extractCatalog` does, for a game that wants a translator-ready
|
|
40
|
+
* file to start from.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { parseDialogueText, EventRunner, GameState } from '@datamoc/mw_games/rpg';
|
|
45
|
+
*
|
|
46
|
+
* declare const game: GameState;
|
|
47
|
+
*
|
|
48
|
+
* const runner = new EventRunner({
|
|
49
|
+
* game,
|
|
50
|
+
* present: async (request) => {
|
|
51
|
+
* console.log(request.speaker ? `${request.speaker}: ${request.text}` : request.text);
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* const commands = parseDialogueText(`
|
|
55
|
+
* @alice Hello.
|
|
56
|
+
* @bob Hi!
|
|
57
|
+
* - How are you?
|
|
58
|
+
* - Fine, and you?
|
|
59
|
+
* `);
|
|
60
|
+
* await runner.run(commands);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function parseDialogueText(source: string): EventCommand[];
|
|
64
|
+
/**
|
|
65
|
+
* Collects every `say`/`ask` line's text into an identity catalog - each key mapping to
|
|
66
|
+
* itself, the same shape MWL's own `extractCatalog` builds from `_("...")`-marked strings -
|
|
67
|
+
* so a translator has real entries to work from instead of a wall of untranslated dialogue.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { parseDialogueText, extractDialogueCatalog } from '@datamoc/mw_games/rpg';
|
|
72
|
+
*
|
|
73
|
+
* const commands = parseDialogueText('@alice Hello.\n');
|
|
74
|
+
* console.log(extractDialogueCatalog(commands).messages); // { 'Hello.': 'Hello.' }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function extractDialogueCatalog(commands: readonly EventCommand[], options?: {
|
|
78
|
+
locale?: string;
|
|
79
|
+
direction?: Direction;
|
|
80
|
+
}): Catalog;
|
|
81
|
+
//# sourceMappingURL=dialogue-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialogue-text.d.ts","sourceRoot":"","sources":["../../src/rpg/dialogue-text.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAIhE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAAO,GACtD,OAAO,CAOT"}
|