@defold-typescript/transpiler 0.48.0 → 0.49.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/dist/hsm/debug.ts +36 -8
- package/dist/hsm/index.ts +1133 -204
- package/package.json +2 -2
package/dist/hsm/debug.ts
CHANGED
|
@@ -19,8 +19,15 @@ const SILENT: MachineInspector = {
|
|
|
19
19
|
|
|
20
20
|
const TEXT_OFFSET_Y = 40;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// A JavaScript object inherits members such as `__proto__` and `constructor`, and a caller's
|
|
23
|
+
// string can name one. This literal has no prototype, so every string is an own key. In Lua the
|
|
24
|
+
// nil field leaves a plain table.
|
|
25
|
+
function record<V>(): Record<string, V> {
|
|
26
|
+
return { __proto__: null } as unknown as Record<string, V>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const labelUses = record<number>();
|
|
30
|
+
const issuedLabels = record<boolean>();
|
|
24
31
|
|
|
25
32
|
function uniqueLabel(label: string): string {
|
|
26
33
|
let ordinal = labelUses[label] ?? 1;
|
|
@@ -96,9 +103,12 @@ function shownLeaves(leaves: readonly string[]): string {
|
|
|
96
103
|
|
|
97
104
|
/**
|
|
98
105
|
* Prints one line when it is called, then one line for each move `instance` makes, each starting
|
|
99
|
-
* with `hsm` and the label.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
106
|
+
* with `hsm` and the label. A move's line names the state whose rule made it and that rule's key.
|
|
107
|
+
* An event no active state takes prints an `unhandled` line with its `type` and the active
|
|
108
|
+
* leaves, once per type until the next move. Call it once after `start`. A label another
|
|
109
|
+
* `inspect` call already used gets an ordinal, such as `enemy#2`. In a release build it registers
|
|
110
|
+
* nothing and returns an inspector whose `draw` does nothing, so the calls can stay in shipped
|
|
111
|
+
* code.
|
|
102
112
|
*/
|
|
103
113
|
export function inspect<Ctx, E extends EventObject, P extends string>(
|
|
104
114
|
instance: MachineInstance<Ctx, E, P>,
|
|
@@ -110,10 +120,28 @@ export function inspect<Ctx, E extends EventObject, P extends string>(
|
|
|
110
120
|
const shownLabel = uniqueLabel(label);
|
|
111
121
|
const loggedLabel = escapeField(shownLabel);
|
|
112
122
|
let frame = 0;
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
let moves = 0;
|
|
124
|
+
const unhandledAt = record<number>();
|
|
125
|
+
instance.onMove((from, to, cause, event, source?: string, key?: number) => {
|
|
126
|
+
moves++;
|
|
127
|
+
let reason = escapeField(event === undefined ? cause : event.type);
|
|
128
|
+
if (source !== undefined) {
|
|
129
|
+
reason = `${reason}: ${escapeField(source)}`;
|
|
130
|
+
if (key !== undefined) {
|
|
131
|
+
reason = `${reason}, ${key}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
print(
|
|
135
|
+
`hsm ${loggedLabel} frame ${frame}: ${escapeField(from)} -> ${shown(to)} (${reason}) [${shownList(instance.leaves, escapeField)}]`,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
instance.onUnhandled((event) => {
|
|
139
|
+
if (unhandledAt[event.type] === moves) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
unhandledAt[event.type] = moves;
|
|
115
143
|
print(
|
|
116
|
-
`hsm ${loggedLabel} frame ${frame}:
|
|
144
|
+
`hsm ${loggedLabel} frame ${frame}: unhandled (${escapeField(event.type)}) [${shownList(instance.leaves, escapeField)}]`,
|
|
117
145
|
);
|
|
118
146
|
});
|
|
119
147
|
print(
|