-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModLoader.js
197 lines (175 loc) · 7.24 KB
/
ModLoader.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(function(Scratch) {
let tempURL = '';
let modmenuOpen = true;
let buttonStyle = 'margin: 4px;color: white;background: #5e5e5e;border-width: 4px;border-radius: 5px;border-color: transparent;';
// Add div
var ModMenuDiv = document.createElement("div");
ModMenuDiv.className = "ModMenu";
ModMenuDiv.hidden = false;
ModMenuDiv.style = 'padding: 5px;display: inline-table; transform: translate(0px, 0px); width: 0px; height: 0px;'
document.querySelector('div[class^="sc-layers"]').appendChild(ModMenuDiv);
// Add extension loader button
var LoadExtensionButton = document.createElement("button");
LoadExtensionButton.hidden = false;
LoadExtensionButton.textContent = 'Load external extension';
LoadExtensionButton.addEventListener('click', loadExtension);
LoadExtensionButton.style = buttonStyle;
ModMenuDiv.appendChild(LoadExtensionButton);
// Add sprite loader button
var LoadSpriteButton = document.createElement("button");
LoadSpriteButton.hidden = false;
LoadSpriteButton.textContent = 'Load external sprite';
LoadSpriteButton.addEventListener('click', loadSprite);
LoadSpriteButton.style = buttonStyle;
ModMenuDiv.appendChild(LoadSpriteButton);
// Add project download button
var DownloadProjectButton = document.createElement("button");
DownloadProjectButton.hidden = false;
DownloadProjectButton.textContent = 'Download project file';
DownloadProjectButton.addEventListener('click', downloadProject);
DownloadProjectButton.style = buttonStyle;
ModMenuDiv.appendChild(DownloadProjectButton);
// Add framerate button
var SetFpsButton = document.createElement("button");
SetFpsButton.hidden = false;
SetFpsButton.textContent = 'Frame rate\n('+vm.runtime.frameLoop.framerate+')';
SetFpsButton.addEventListener('click', setFrameRate);
SetFpsButton.style = buttonStyle;
ModMenuDiv.appendChild(SetFpsButton);
// Add interpolation button
var SetInterpolationButton = document.createElement("button");
SetInterpolationButton.hidden = false;
SetInterpolationButton.textContent = 'Interpolation\n('+vm.runtime.interpolationEnabled+')';
SetInterpolationButton.addEventListener('click', setInterpolation);
SetInterpolationButton.style = buttonStyle;
ModMenuDiv.appendChild(SetInterpolationButton);
// Add HQ pen button
var SetHQPenButton = document.createElement("button");
SetHQPenButton.hidden = false;
SetHQPenButton.textContent = 'High quality pen\n('+vm.runtime.renderer.useHighQualityRender+')';
SetHQPenButton.addEventListener('click', setHQPen);
SetHQPenButton.style = buttonStyle;
ModMenuDiv.appendChild(SetHQPenButton);
// Add turbo button
var SetTurboModeButton = document.createElement("button");
SetTurboModeButton.hidden = false;
SetTurboModeButton.textContent = 'Turbo Mode\n('+vm.runtime.turboMode+')';
SetTurboModeButton.addEventListener('click', setTurboMode);
SetTurboModeButton.style = buttonStyle;
ModMenuDiv.appendChild(SetTurboModeButton);
// Add exit loader button
var ExitModButton = document.createElement("button");
ExitModButton.hidden = false;
ExitModButton.textContent = 'Hide mod menu';
ExitModButton.style = buttonStyle;
ExitModButton.addEventListener('click', exitMod);
ModMenuDiv.appendChild(ExitModButton);
function setTurboMode(){
if(vm.runtime.turboMode == true){
vm.runtime.turboMode = false;
}
else {
vm.runtime.turboMode = true;
}
SetTurboModeButton.textContent = 'Turbo Mode\n('+vm.runtime.turboMode+')';
}
function setHQPen(){
if(vm.runtime.renderer.useHighQualityRender == true){
vm.runtime.renderer.setUseHighQualityRender(false);
}
else {
vm.runtime.renderer.setUseHighQualityRender(true);
}
SetHQPenButton.textContent = 'High quality pen\n('+vm.runtime.renderer.useHighQualityRender+')';
}
function setInterpolation(){
if(vm.runtime.interpolationEnabled == true){
vm.runtime.setInterpolation(false);
}
else {
vm.runtime.setInterpolation(true);
}
SetInterpolationButton.textContent = 'Interpolation\n('+vm.runtime.interpolationEnabled+')';
}
function setFrameRate(){
tempURL = prompt("Enter frame rate (FPS)");
if (tempURL !== null){
vm.runtime.setFramerate(Number(tempURL));
SetFpsButton.textContent = 'Frame rate\n('+vm.runtime.frameLoop.framerate+')';
}
}
function loadExtension(){
tempURL = prompt("Enter extension URL");
vm.extensionManager.loadExtensionURL(tempURL);
}
function loadSprite() {
tempURL = prompt("Enter sprite URL");
fetch(tempURL)
.then(r => r.arrayBuffer())
.then(buffer => vm.addSprite(buffer))
.then(() => {
console.log("Done");
vm.greenFlag();
})
.catch((error) => {
console.log("Error", error);
});
}
function exitMod() {
if (modmenuOpen == true){
LoadSpriteButton.style.visibility = 'hidden';
LoadExtensionButton.style.visibility = 'hidden';
DownloadProjectButton.style.visibility = 'hidden';
SetFpsButton.style.visibility = 'hidden';
SetInterpolationButton.style.visibility = 'hidden';
SetHQPenButton.style.visibility = 'hidden';
SetTurboModeButton.style.visibility = 'hidden';
ExitModButton.textContent = ''
ExitModButton.style = buttonStyle+'height: 25px;width: 25px;';
modmenuOpen = false;
}
else {
LoadSpriteButton.style.visibility = 'visible';
LoadExtensionButton.style.visibility = 'visible';
DownloadProjectButton.style.visibility = 'visible';
SetFpsButton.style.visibility = 'visible';
SetInterpolationButton.style.visibility = 'visible';
SetHQPenButton.style.visibility = 'visible';
SetTurboModeButton.style.visibility = 'visible';
ExitModButton.textContent = 'Hide mod menu';
ExitModButton.style = buttonStyle;
modmenuOpen = true;
}
}
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
async function downloadProject() {
if (vm.runtime.isPackaged == true) {
alert("Warning: This project has 'Remove raw asset data after loading to save RAM' enabled, assets that have already been loaded won't save properly. If that happens, consider using https://turbowarp.github.io/unpackager/.")
}
let blob = await vm.saveProjectSb3()
let reader = new FileReader()
reader.readAsDataURL(blob)
reader.onload = function(){
dataUrl = reader.result;
downloadURI(dataUrl, document.title + '.sb3');
}
}
class ModLoader {
getInfo() {
return {
id: 'ModLoader',
name: "You can't see this lol",
blocks: []
};
}
}
Scratch.extensions.register(new ModLoader());
})(Scratch);