@kubohiroya/turbowarp-aframe 0.12.0 → 0.12.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.
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/turbowarp-aframe.js +81 -26
- package/package.json +1 -1
- package/src/extension.ts +2 -8
- package/src/fixed-input-editors.ts +37 -8
- package/src/source-editors.ts +42 -9
package/README.ja.md
CHANGED
|
@@ -94,7 +94,7 @@ TurboWarp では `dist/turbowarp-aframe.js` を unsandboxed custom extension と
|
|
|
94
94
|
package として参照する場合は version を固定します。
|
|
95
95
|
|
|
96
96
|
```bash
|
|
97
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.12.
|
|
97
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.12.1
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
## ブロック概要
|
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ Load `dist/turbowarp-aframe.js` as an unsandboxed custom extension in TurboWarp.
|
|
|
94
94
|
For package-based reuse, pin the version:
|
|
95
95
|
|
|
96
96
|
```bash
|
|
97
|
-
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.12.
|
|
97
|
+
pnpm add --save-exact @kubohiroya/turbowarp-aframe@0.12.1
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
## Block reference
|
package/dist/turbowarp-aframe.js
CHANGED
|
@@ -9552,29 +9552,56 @@ var fixedInputEditors = [
|
|
|
9552
9552
|
bindings: [binding("setVrmExpression", "WEIGHT")]
|
|
9553
9553
|
}
|
|
9554
9554
|
];
|
|
9555
|
-
/**
|
|
9555
|
+
/**
|
|
9556
|
+
* Register only currently declared opcodes; release obsolete feature-flag scopes.
|
|
9557
|
+
*
|
|
9558
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
9559
|
+
* stays loaded for the next project: the same opcodes are registered again once that project has
|
|
9560
|
+
* loaded. Only `dispose()` is final.
|
|
9561
|
+
*/
|
|
9556
9562
|
function fixedInputRegistration(scratch) {
|
|
9557
9563
|
const host = typeof scratch === "object" && scratch !== null ? scratch : {};
|
|
9558
9564
|
let active;
|
|
9559
9565
|
let activeOpcodes = "";
|
|
9566
|
+
let lastOpcodes;
|
|
9560
9567
|
const removers = [];
|
|
9561
9568
|
let disposed = false;
|
|
9562
|
-
|
|
9563
|
-
|
|
9569
|
+
let released = false;
|
|
9570
|
+
let listening = false;
|
|
9571
|
+
const release = () => {
|
|
9564
9572
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
9565
9573
|
active = void 0;
|
|
9566
9574
|
activeOpcodes = "";
|
|
9567
9575
|
};
|
|
9576
|
+
const runtimeDisposed = () => {
|
|
9577
|
+
release();
|
|
9578
|
+
released = true;
|
|
9579
|
+
};
|
|
9580
|
+
const projectLoaded = () => {
|
|
9581
|
+
if (!released || lastOpcodes === void 0) return;
|
|
9582
|
+
released = false;
|
|
9583
|
+
try {
|
|
9584
|
+
registration.ensure(lastOpcodes);
|
|
9585
|
+
} catch {}
|
|
9586
|
+
};
|
|
9568
9587
|
const shutdown = () => {
|
|
9569
9588
|
disposed = true;
|
|
9570
|
-
|
|
9589
|
+
released = false;
|
|
9590
|
+
if (listening) {
|
|
9591
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9592
|
+
host.vm?.runtime?.off?.("PROJECT_LOADED", projectLoaded);
|
|
9593
|
+
listening = false;
|
|
9594
|
+
}
|
|
9595
|
+
release();
|
|
9571
9596
|
};
|
|
9572
|
-
|
|
9597
|
+
const registration = {
|
|
9573
9598
|
ensure(opcodes) {
|
|
9574
9599
|
const api = host.gui?.blockEditors;
|
|
9575
9600
|
const signature = [...new Set(opcodes)].sort().join("\0");
|
|
9576
9601
|
if (disposed || api === active && signature === activeOpcodes) return;
|
|
9577
|
-
|
|
9602
|
+
release();
|
|
9603
|
+
released = false;
|
|
9604
|
+
lastOpcodes = [...opcodes];
|
|
9578
9605
|
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function") return;
|
|
9579
9606
|
try {
|
|
9580
9607
|
for (const definition of fixedInputEditors) if (definition.opcodes.every((opcode) => opcodes.includes(opcode))) {
|
|
@@ -9584,14 +9611,19 @@ function fixedInputRegistration(scratch) {
|
|
|
9584
9611
|
}
|
|
9585
9612
|
active = api;
|
|
9586
9613
|
activeOpcodes = signature;
|
|
9587
|
-
|
|
9614
|
+
if (!listening) {
|
|
9615
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
9616
|
+
host.vm?.runtime?.on?.("PROJECT_LOADED", projectLoaded);
|
|
9617
|
+
listening = true;
|
|
9618
|
+
}
|
|
9588
9619
|
} catch (error) {
|
|
9589
|
-
|
|
9620
|
+
release();
|
|
9590
9621
|
throw error;
|
|
9591
9622
|
}
|
|
9592
9623
|
},
|
|
9593
9624
|
dispose: shutdown
|
|
9594
9625
|
};
|
|
9626
|
+
return registration;
|
|
9595
9627
|
}
|
|
9596
9628
|
function deepFreeze(value) {
|
|
9597
9629
|
if (value !== null && typeof value === "object") {
|
|
@@ -9936,23 +9968,51 @@ function createSourceEditorOptions(nowMs = Date.now) {
|
|
|
9936
9968
|
validationContext: context
|
|
9937
9969
|
}];
|
|
9938
9970
|
}
|
|
9939
|
-
/**
|
|
9971
|
+
/**
|
|
9972
|
+
* Optional capability: old GUIs continue executing blocks without editor registration.
|
|
9973
|
+
*
|
|
9974
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
9975
|
+
* stays loaded for the next project: the same editors are registered again once that project has
|
|
9976
|
+
* loaded. Only the returned remover is final.
|
|
9977
|
+
*/
|
|
9940
9978
|
function registerSourceEditors(scratch, nowMs = Date.now) {
|
|
9941
|
-
const
|
|
9979
|
+
const host = typeof scratch === "object" && scratch !== null ? scratch : {};
|
|
9980
|
+
const api = host.gui?.blockEditors;
|
|
9942
9981
|
if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== "function") return () => {};
|
|
9943
9982
|
const removers = [];
|
|
9944
|
-
|
|
9945
|
-
for (const
|
|
9946
|
-
}
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9983
|
+
const release = () => {
|
|
9984
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
9985
|
+
};
|
|
9986
|
+
const register = () => {
|
|
9987
|
+
try {
|
|
9988
|
+
for (const options of createSourceEditorOptions(nowMs)) removers.push(api.registerSourceEditor(options));
|
|
9989
|
+
return true;
|
|
9990
|
+
} catch {
|
|
9991
|
+
release();
|
|
9992
|
+
return false;
|
|
9993
|
+
}
|
|
9994
|
+
};
|
|
9995
|
+
if (!register()) return () => {};
|
|
9996
|
+
let released = false;
|
|
9997
|
+
const runtimeDisposed = () => {
|
|
9998
|
+
release();
|
|
9999
|
+
released = true;
|
|
10000
|
+
};
|
|
10001
|
+
const projectLoaded = () => {
|
|
10002
|
+
if (!released) return;
|
|
10003
|
+
released = false;
|
|
10004
|
+
register();
|
|
10005
|
+
};
|
|
10006
|
+
const runtime = host.vm?.runtime;
|
|
10007
|
+
runtime?.on?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
10008
|
+
runtime?.on?.("PROJECT_LOADED", projectLoaded);
|
|
9950
10009
|
let active = true;
|
|
9951
10010
|
return () => {
|
|
9952
|
-
if (active)
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
10011
|
+
if (!active) return;
|
|
10012
|
+
active = false;
|
|
10013
|
+
runtime?.off?.("RUNTIME_DISPOSED", runtimeDisposed);
|
|
10014
|
+
runtime?.off?.("PROJECT_LOADED", projectLoaded);
|
|
10015
|
+
release();
|
|
9956
10016
|
};
|
|
9957
10017
|
}
|
|
9958
10018
|
var block_definitions_default = {
|
|
@@ -16956,13 +17016,8 @@ var TurboWarpAFrameExtension = class {
|
|
|
16956
17016
|
this.lastEvent = null;
|
|
16957
17017
|
this.disposed = false;
|
|
16958
17018
|
this.vrms = new VrmAvatars(() => this.getThree());
|
|
16959
|
-
this.handleSourceEditorDispose = () => {
|
|
16960
|
-
this.removeSourceEditors();
|
|
16961
|
-
(Scratch.vm?.runtime)?.off?.("RUNTIME_DISPOSED", this.handleSourceEditorDispose);
|
|
16962
|
-
};
|
|
16963
17019
|
this.fixedEditors = fixedInputRegistration(Scratch);
|
|
16964
17020
|
this.removeSourceEditors = registerSourceEditors(Scratch);
|
|
16965
|
-
(Scratch.vm?.runtime)?.on?.("RUNTIME_DISPOSED", this.handleSourceEditorDispose);
|
|
16966
17021
|
this.resetGraph();
|
|
16967
17022
|
this.runtimeCapability = createRuntimeCapability({
|
|
16968
17023
|
createScene: (layer, mode) => this.createScene({
|
|
@@ -17370,7 +17425,7 @@ var TurboWarpAFrameExtension = class {
|
|
|
17370
17425
|
this.fixedEditors.dispose();
|
|
17371
17426
|
if (this.disposed) return;
|
|
17372
17427
|
this.disposed = true;
|
|
17373
|
-
this.
|
|
17428
|
+
this.removeSourceEditors();
|
|
17374
17429
|
for (const key of [...this.animationPlaybacks.keys()]) this.stopPlayback(key, true);
|
|
17375
17430
|
this.vrms.clear();
|
|
17376
17431
|
this.rootElement?.parentElement?.remove();
|
package/package.json
CHANGED
package/src/extension.ts
CHANGED
|
@@ -153,17 +153,11 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
153
153
|
private disposed = false;
|
|
154
154
|
private readonly vrms = new VrmAvatars(() => this.getThree() as unknown as VrmThreeApi | null);
|
|
155
155
|
|
|
156
|
+
/** Releases on RUNTIME_DISPOSED and registers again on the next PROJECT_LOADED by itself. */
|
|
156
157
|
private readonly removeSourceEditors: () => void;
|
|
157
|
-
private readonly handleSourceEditorDispose = (): void => {
|
|
158
|
-
this.removeSourceEditors();
|
|
159
|
-
const runtime = Scratch.vm?.runtime as {off?: (event: string, listener: () => void) => void} | undefined;
|
|
160
|
-
runtime?.off?.('RUNTIME_DISPOSED', this.handleSourceEditorDispose);
|
|
161
|
-
};
|
|
162
158
|
|
|
163
159
|
public constructor() {
|
|
164
160
|
this.removeSourceEditors = registerSourceEditors(Scratch);
|
|
165
|
-
const editorRuntime = Scratch.vm?.runtime as {on?: (event: string, listener: () => void) => void} | undefined;
|
|
166
|
-
editorRuntime?.on?.('RUNTIME_DISPOSED', this.handleSourceEditorDispose);
|
|
167
161
|
this.resetGraph();
|
|
168
162
|
this.runtimeCapability = createRuntimeCapability(
|
|
169
163
|
{
|
|
@@ -641,7 +635,7 @@ export class TurboWarpAFrameExtension implements TurboWarpExtension {
|
|
|
641
635
|
this.fixedEditors.dispose();
|
|
642
636
|
if (this.disposed) return;
|
|
643
637
|
this.disposed = true;
|
|
644
|
-
this.
|
|
638
|
+
this.removeSourceEditors();
|
|
645
639
|
for (const key of [...this.animationPlaybacks.keys()]) {
|
|
646
640
|
this.stopPlayback(key, true);
|
|
647
641
|
}
|
|
@@ -105,25 +105,49 @@ interface OptionalHost {
|
|
|
105
105
|
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Register only currently declared opcodes; release obsolete feature-flag scopes.
|
|
110
|
+
*
|
|
111
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
112
|
+
* stays loaded for the next project: the same opcodes are registered again once that project has
|
|
113
|
+
* loaded. Only `dispose()` is final.
|
|
114
|
+
*/
|
|
109
115
|
export function fixedInputRegistration(scratch: unknown) {
|
|
110
116
|
const host = (typeof scratch === 'object' && scratch !== null ? scratch : {}) as OptionalHost;
|
|
111
117
|
let active: unknown;
|
|
112
118
|
let activeOpcodes = '';
|
|
119
|
+
let lastOpcodes: readonly string[] | undefined;
|
|
113
120
|
const removers: (() => void)[] = [];
|
|
114
121
|
let disposed = false;
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
let released = false;
|
|
123
|
+
let listening = false;
|
|
124
|
+
const release = () => {
|
|
117
125
|
for (const remove of removers.splice(0).reverse()) remove();
|
|
118
126
|
active = undefined; activeOpcodes = '';
|
|
119
127
|
};
|
|
120
|
-
const
|
|
121
|
-
|
|
128
|
+
const runtimeDisposed = () => {release(); released = true;};
|
|
129
|
+
const projectLoaded = () => {
|
|
130
|
+
if (!released || lastOpcodes === undefined) return;
|
|
131
|
+
released = false;
|
|
132
|
+
// A failure leaves nothing registered; it must not break the project load.
|
|
133
|
+
try {registration.ensure(lastOpcodes);} catch {/* the next getInfo retries */}
|
|
134
|
+
};
|
|
135
|
+
const shutdown = () => {
|
|
136
|
+
disposed = true; released = false;
|
|
137
|
+
if (listening) {
|
|
138
|
+
host.vm?.runtime?.off?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
139
|
+
host.vm?.runtime?.off?.('PROJECT_LOADED', projectLoaded);
|
|
140
|
+
listening = false;
|
|
141
|
+
}
|
|
142
|
+
release();
|
|
143
|
+
};
|
|
144
|
+
const registration = {
|
|
122
145
|
ensure(opcodes: readonly string[]) {
|
|
123
146
|
const api = host.gui?.blockEditors;
|
|
124
147
|
const signature = [...new Set(opcodes)].sort().join('\0');
|
|
125
148
|
if (disposed || (api === active && signature === activeOpcodes)) return;
|
|
126
|
-
|
|
149
|
+
release();
|
|
150
|
+
released = false; lastOpcodes = [...opcodes];
|
|
127
151
|
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== 'function') return;
|
|
128
152
|
try {
|
|
129
153
|
for (const definition of fixedInputEditors) {
|
|
@@ -134,9 +158,14 @@ export function fixedInputRegistration(scratch: unknown) {
|
|
|
134
158
|
}
|
|
135
159
|
}
|
|
136
160
|
active = api; activeOpcodes = signature;
|
|
137
|
-
|
|
138
|
-
|
|
161
|
+
if (!listening) {
|
|
162
|
+
host.vm?.runtime?.on?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
163
|
+
host.vm?.runtime?.on?.('PROJECT_LOADED', projectLoaded);
|
|
164
|
+
listening = true;
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {release(); throw error;}
|
|
139
167
|
},
|
|
140
168
|
dispose: shutdown
|
|
141
169
|
};
|
|
170
|
+
return registration;
|
|
142
171
|
}
|
package/src/source-editors.ts
CHANGED
|
@@ -14,17 +14,50 @@ export function createSourceEditorOptions(nowMs: () => number = Date.now): reado
|
|
|
14
14
|
];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
interface OptionalSourceHost {
|
|
18
|
+
gui?: {blockEditors?: {apiVersion?: number; registerSourceEditor?: (options: SourceEditorOptions) => () => void}};
|
|
19
|
+
vm?: {runtime?: {on?: (event: string, listener: () => void) => void; off?: (event: string, listener: () => void) => void}};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Optional capability: old GUIs continue executing blocks without editor registration.
|
|
24
|
+
*
|
|
25
|
+
* Every project load disposes the runtime, which releases the registrations, but the extension
|
|
26
|
+
* stays loaded for the next project: the same editors are registered again once that project has
|
|
27
|
+
* loaded. Only the returned remover is final.
|
|
28
|
+
*/
|
|
18
29
|
export function registerSourceEditors(scratch: unknown, nowMs: () => number = Date.now): () => void {
|
|
19
|
-
const
|
|
30
|
+
const host = (typeof scratch === 'object' && scratch !== null ? scratch : {}) as OptionalSourceHost;
|
|
31
|
+
const api = host.gui?.blockEditors;
|
|
20
32
|
if (api?.apiVersion !== 1 || typeof api.registerSourceEditor !== 'function') return () => {};
|
|
21
33
|
const removers: (() => void)[] = [];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
const release = () => {for (const remove of removers.splice(0).reverse()) remove();};
|
|
35
|
+
const register = (): boolean => {
|
|
36
|
+
try {
|
|
37
|
+
for (const options of createSourceEditorOptions(nowMs)) removers.push(api.registerSourceEditor!(options));
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
release();
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (!register()) return () => {};
|
|
45
|
+
let released = false;
|
|
46
|
+
const runtimeDisposed = () => {release(); released = true;};
|
|
47
|
+
const projectLoaded = () => {
|
|
48
|
+
if (!released) return;
|
|
49
|
+
released = false;
|
|
50
|
+
register();
|
|
51
|
+
};
|
|
52
|
+
const runtime = host.vm?.runtime;
|
|
53
|
+
runtime?.on?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
54
|
+
runtime?.on?.('PROJECT_LOADED', projectLoaded);
|
|
28
55
|
let active = true;
|
|
29
|
-
return () => {
|
|
56
|
+
return () => {
|
|
57
|
+
if (!active) return;
|
|
58
|
+
active = false;
|
|
59
|
+
runtime?.off?.('RUNTIME_DISPOSED', runtimeDisposed);
|
|
60
|
+
runtime?.off?.('PROJECT_LOADED', projectLoaded);
|
|
61
|
+
release();
|
|
62
|
+
};
|
|
30
63
|
}
|