Skip to content

Commit fbbeffe

Browse files
v9.9.13: optimize types
1 parent 95cb4da commit fbbeffe

8 files changed

Lines changed: 9603 additions & 9665 deletions

File tree

lib/index.cjs

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

lib/index.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

Lines changed: 9570 additions & 9618 deletions
Large diffs are not rendered by default.

lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@open-ccw/scratch-vm",
3-
"version": "9.9.12",
3+
"version": "9.9.13",
44
"description": "Virtual Machine for Scratch 3.0 merged tw-vm",
55
"author": "Massachusetts Institute of Technology",
66
"license": "LGPL-3.0-only",

src/blocks/gandi_async_asset.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import BlockType from "../extension-support/block-type";
22
import ArgumentType from "../extension-support/argument-type";
33
import Cast from "../util/cast";
44
import Runtime from "../engine/runtime";
5+
import type RenderedTarget from "../sprites/rendered-target";
56

67
class GandiAsyncAssetManager {
78
runtime: Runtime;
@@ -17,8 +18,8 @@ class GandiAsyncAssetManager {
1718
this.runtime.on("PROJECT_RUN_STOP", this.autoClearAsyncCostume.bind(this));
1819

1920
const config =
20-
(runtime.ccwAPI as any)?.getOnlineExtensionsConfig &&
21-
(runtime.ccwAPI as any)?.getOnlineExtensionsConfig();
21+
runtime.ccwAPI?.getOnlineExtensionsConfig &&
22+
runtime.ccwAPI?.getOnlineExtensionsConfig();
2223
const extConfig = config && config[this.NS];
2324
this.apis = extConfig?.api;
2425

@@ -146,11 +147,11 @@ class GandiAsyncAssetManager {
146147

147148
clearAsyncCostume() {
148149
this.runtime.targets.forEach((target) => {
149-
const sprite = target.sprite as any;
150+
const sprite = target.sprite;
150151
sprite.costumes = sprite.costumes.filter(
151152
(costume: any) => !costume.isRuntimeAsyncLoad,
152153
);
153-
(target as any).setCostume(0);
154+
(target as RenderedTarget).setCostume(0);
154155
});
155156
}
156157

src/engine/runtime.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ import Scratch3SensingBlocks from "../blocks/scratch3_sensing";
5050
import Scratch3DataBlocks from "../blocks/scratch3_data";
5151
import Scratch3ProcedureBlocks from "../blocks/scratch3_procedures";
5252
import Target from "./target";
53-
import VirtualMachine from "../virtual-machine";
5453
import type { CCWApi } from "../ccwApi";
54+
import type ExtensionManager from "../extension-support/extension-manager";
5555

5656
// Virtual I/O devices.
5757

@@ -546,9 +546,11 @@ class Runtime extends EventEmitter {
546546
hatsConcurrency: number;
547547
};
548548
compilerOptions: { enabled: boolean; warpTimer: boolean };
549-
ccwAPI: CCWApi;
549+
ccwAPI: Partial<CCWApi>;
550550
waitingLoadAssetCallbackQueue: Function[];
551551
debug: boolean;
552+
extensionManager?: ExtensionManager;
553+
isLoadProjectAssetsNonBlocking?: boolean;
552554
_lastStepTime: number;
553555
interpolationEnabled: boolean;
554556
_defaultStoredSettings: {
@@ -764,20 +766,7 @@ class Runtime extends EventEmitter {
764766
/** ccw: add ccwAPI init value {}
765767
*
766768
*/
767-
this.ccwAPI = {
768-
getOpenVM() {
769-
debugger
770-
return {}
771-
},
772-
getOnlineExtensionsConfig(){
773-
debugger
774-
return
775-
},
776-
async getExtensionURLById(id) {
777-
debugger
778-
return id
779-
},
780-
};
769+
this.ccwAPI = {};
781770

782771
this.waitingLoadAssetCallbackQueue = [];
783772

src/virtual-machine.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class VirtualMachine extends EventEmitter {
8686
asyncLoadingProjectAssetsSupported: boolean;
8787
_dragTarget: RenderedTarget | null;
8888
_assetsLoadProgress: Progress | null;
89-
extensionManager: any;
89+
extensionManager: ExtensionManager;
9090
securityManager: any;
9191
exports: {
9292
Sprite: typeof Sprite;
@@ -399,7 +399,7 @@ class VirtualMachine extends EventEmitter {
399399
this.extensionManager = new ExtensionManager(this);
400400
this.securityManager = this.extensionManager.securityManager;
401401
// extensionManager is attached dynamically (not declared on Runtime).
402-
(this.runtime as any).extensionManager = this.extensionManager;
402+
this.runtime.extensionManager = this.extensionManager;
403403

404404
// Load core extensions
405405
for (const id of CORE_EXTENSIONS) {
@@ -677,7 +677,7 @@ class VirtualMachine extends EventEmitter {
677677
// Support non-blocking loading of project assets.
678678
if (this.asyncLoadingProjectAssetsSupported) {
679679
this.runtime.asyncLoadingProjectAssets = true;
680-
(this.runtime as any).isLoadProjectAssetsNonBlocking = true;
680+
this.runtime.isLoadProjectAssetsNonBlocking = true;
681681
}
682682
const _projectProcessingUniqueId = (this._projectProcessingUniqueId =
683683
Math.random());
@@ -696,7 +696,7 @@ class VirtualMachine extends EventEmitter {
696696
}
697697

698698
const validationPromise = new Promise((resolve, reject) => {
699-
const {default: validate} = ScratchParser;
699+
const { default: validate } = ScratchParser;
700700
// The second argument of false below indicates to the validator that the
701701
// input should be parsed/validated as an entire project (and not a single sprite)
702702
validate(input, false, (error: any, res: unknown) => {
@@ -769,7 +769,7 @@ class VirtualMachine extends EventEmitter {
769769
})
770770
.then(() => this.runtime.handleProjectLoaded())
771771
.then(() => {
772-
(this.runtime as any).isLoadProjectAssetsNonBlocking = false;
772+
this.runtime.isLoadProjectAssetsNonBlocking = false;
773773
this.runtime.fireWaitingLoadCallbackQueue();
774774
})
775775
.catch((error) => {
@@ -1239,7 +1239,7 @@ class VirtualMachine extends EventEmitter {
12391239
* @type {[{id: string; url?: string}]}
12401240
*/
12411241
const extInfo: Array<{ id: string; url?: string }> = [];
1242-
extensions.extensionIDs.forEach((extensionID: string | number) => {
1242+
extensions.extensionIDs.forEach((extensionID: string) => {
12431243
// 跳过已加载
12441244
if (this.extensionManager.isExtensionLoaded(extensionID)) return;
12451245
// 跳过 builtin
@@ -1886,11 +1886,7 @@ class VirtualMachine extends EventEmitter {
18861886
x: 0,
18871887
y: 0,
18881888
};
1889-
(target.blocks as any).createBlock(
1890-
shadowBlock,
1891-
"default",
1892-
undefined,
1893-
);
1889+
target.blocks.createBlock(shadowBlock, "default");
18941890
this.runtime.emitTargetBlocksChanged(
18951891
targetId,
18961892
["add", [shadowBlock]],
@@ -2487,7 +2483,7 @@ class VirtualMachine extends EventEmitter {
24872483
newName: string,
24882484
sendNameChangedEvent: boolean = true,
24892485
) {
2490-
const target = this.runtime.getTargetById(targetId) as any;
2486+
const target = this.runtime.getTargetById(targetId) as RenderedTarget;
24912487
if (target) {
24922488
if (!target.isSprite()) {
24932489
throw new Error("Cannot rename non-sprite targets.");
@@ -2837,7 +2833,7 @@ class VirtualMachine extends EventEmitter {
28372833
// Create an array promises for extensions to load
28382834
const extensionPromises = Array.from(extensionIDs, (id) =>
28392835
// Only support builtin extension for now, so not using extensionURLs to load
2840-
this.extensionManager.loadExtensionURL(id),
2836+
this.extensionManager.loadExtensionURL(id as string),
28412837
);
28422838

28432839
return Promise.all(extensionPromises).then(() => {
@@ -3133,7 +3129,7 @@ class VirtualMachine extends EventEmitter {
31333129
continue;
31343130
}
31353131
globalProcedures = globalProcedures.concat(
3136-
(target as any).blocks.getGlobalProceduresXML(),
3132+
target.blocks.getGlobalProceduresXML(),
31373133
);
31383134
}
31393135
return globalProcedures;

0 commit comments

Comments
 (0)