File size: 1,741 Bytes
30c32c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class YourExt {
    constructor(runtime, id) {
        //ext stuff
        this.runtime = runtime;
        this.menuIconURI = null;
        this.blockIconURI = null;
        this.colorScheme = ["#41e2d0", "#0DA57A"];
    }
    getInfo() {
        return {
            id: "gameutils",
            name: "GameUtils",
            blockIconURI: this.blockIconURI,
            menuIconURI: this.menuIconURI,
            color1: this.colorScheme[0],
            color2: this.colorScheme[1],
            blocks: [{
                "opcode": "LoadProject",
                "blockType": "command",
                "text": "Load Project from [url]",
                "arguments": {
                    "url": {
                        "type": "string",
                        "defaultValue": ""
                    }
                }
            }, ]
        }
    }
    async LoadProject(args, util) {
        try {
            const req = await fetch(args.ul)
            if (req.status == 200) {
                vm.loadProject(await req.blob())
            } else {
                console.error("Could not load project")
                }
            } catch (e) {
                console.error(e)
            }
        }
    }
    (function() {
        var extensionClass = YourExt;
        if (typeof window === "undefined" || !window.vm) {
            Scratch.extensions.register(new extensionClass());
        } else {
            var extensionInstance = new extensionClass(window.vm.extensionManager.runtime);
            var serviceName = window.vm.extensionManager._registerInternalExtension(extensionInstance);
            window.vm.extensionManager._loadedExtensions.set(extensionInstance.getInfo().id, serviceName);
        };
    })()