rcompiler 0.0.0-stage → 2.1.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/CHANGELOG.md +20 -0
- package/CONTRIBUTING.md +38 -0
- package/LICENSE +15 -0
- package/README.md +157 -2
- package/SECURITY.md +27 -0
- package/assets/placeholder.png +0 -0
- package/docs/ARCHITECTURE.md +74 -0
- package/docs/CLI.md +67 -0
- package/docs/COMPATIBILITY.md +29 -0
- package/docs/CONFIG.md +73 -0
- package/docs/DEBUGGING.md +46 -0
- package/docs/ROADMAP.md +12 -0
- package/docs/TESTING.md +55 -0
- package/exts/freya.js +430 -0
- package/exts/rcrcHelper.js +1396 -0
- package/exts/vartypeany.js +131 -0
- package/package.json +50 -4
- package/src/analysis.js +563 -0
- package/src/assets.js +335 -0
- package/src/cli.js +357 -0
- package/src/emit.js +353 -0
- package/src/mods.js +146 -0
- package/src/preludes.js +3451 -0
- package/src/rcompiler.js +2517 -0
- package/src/standard.js +1352 -0
- package/src/targets.js +129 -0
- package/src/web.js +1603 -0
|
@@ -0,0 +1,1396 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
if (!Scratch.extensions.unsandboxed)
|
|
3
|
+
throw new Error("编译器 需在非沙盒环境中运行以展示正常外观");
|
|
4
|
+
function require(url, callback, error) {
|
|
5
|
+
var script = document.createElement('script');
|
|
6
|
+
script.src = url;
|
|
7
|
+
script.async = true;
|
|
8
|
+
script.onload = callback;
|
|
9
|
+
script.onerror = error;
|
|
10
|
+
document.head.appendChild(script);
|
|
11
|
+
}
|
|
12
|
+
// 默认从项目站点加载浏览器版编译器;自托管可通过 localStorage 覆盖。
|
|
13
|
+
// 例:localStorage['rcompiler:compilerURL'] = './rcompiler.min.js'
|
|
14
|
+
const COMPILER_URL = (typeof localStorage !== 'undefined' && localStorage['rcompiler:compilerURL'])
|
|
15
|
+
|| 'https://rcompiler.0832.ink/rcompiler.min.js';
|
|
16
|
+
require(COMPILER_URL, async () => {
|
|
17
|
+
await regist(true);
|
|
18
|
+
}, async () => {
|
|
19
|
+
await regist(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const lang = localStorage["tw:language"] ? localStorage["tw:language"] : navigator.language;
|
|
23
|
+
const is中文 = lang == 'zh-cn' || lang == 'zh-CN';
|
|
24
|
+
const serverURL = 'https://trampoline.turbowarp.org/translate/';
|
|
25
|
+
const t = async (中文) => {
|
|
26
|
+
if (is中文)
|
|
27
|
+
return 中文;
|
|
28
|
+
else {
|
|
29
|
+
let urlBase = `${serverURL}translate?language=`;
|
|
30
|
+
urlBase += lang;
|
|
31
|
+
urlBase += '&text=';
|
|
32
|
+
urlBase += encodeURIComponent(中文);
|
|
33
|
+
return JSON.parse(await (await fetch(urlBase)).text()).result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class button {
|
|
38
|
+
constructor(runtime) {
|
|
39
|
+
this.runtime = runtime ?? Scratch?.vm?.runtime
|
|
40
|
+
const hijack = (fn) => {
|
|
41
|
+
const _orig = Function.prototype.apply
|
|
42
|
+
Function.prototype.apply = (thisArg) => thisArg
|
|
43
|
+
const result = fn()
|
|
44
|
+
Function.prototype.apply = _orig
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
47
|
+
const getScratch = (runtime) => {
|
|
48
|
+
function getEvent(e) {
|
|
49
|
+
return e instanceof Array ? e[e.length - 1] : e
|
|
50
|
+
}
|
|
51
|
+
const vm = hijack(
|
|
52
|
+
getEvent(runtime._events['QUESTION'])
|
|
53
|
+
).props.vm
|
|
54
|
+
return hijack(
|
|
55
|
+
getEvent(vm._events['EXTENSION_ADDED'])
|
|
56
|
+
)?.ScratchBlocks
|
|
57
|
+
}
|
|
58
|
+
if (!this.runtime) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
this.modifyScratchBlocks(getScratch(this.runtime))
|
|
62
|
+
}
|
|
63
|
+
createButtons(Blockly) {
|
|
64
|
+
// 按钮
|
|
65
|
+
class FieldButton extends Blockly.FieldImage {
|
|
66
|
+
constructor(src) {
|
|
67
|
+
super(src, 25, 25, undefined, false)
|
|
68
|
+
this.initialized = false
|
|
69
|
+
}
|
|
70
|
+
init() {
|
|
71
|
+
super.init()
|
|
72
|
+
if (!this.initialized) {
|
|
73
|
+
// 第一次初始化
|
|
74
|
+
Blockly.bindEventWithChecks_(
|
|
75
|
+
this.getSvgRoot(), 'mousedown', this, (e) => {
|
|
76
|
+
e.stopPropagation()
|
|
77
|
+
});
|
|
78
|
+
Blockly.bindEventWithChecks_(
|
|
79
|
+
this.getSvgRoot(), 'mouseup', this, this.handleClick.bind(this));
|
|
80
|
+
}
|
|
81
|
+
this.initialized = true
|
|
82
|
+
}
|
|
83
|
+
handleClick(e) {
|
|
84
|
+
if (!this.sourceBlock_ || !this.sourceBlock_.workspace) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (this.sourceBlock_.workspace.isDragging()) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (this.sourceBlock_.isInFlyout) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
this.onclick(e)
|
|
94
|
+
}
|
|
95
|
+
onclick(e) {
|
|
96
|
+
// 子类实现
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// + 按钮
|
|
100
|
+
class PlusButton extends FieldButton {
|
|
101
|
+
constructor() {
|
|
102
|
+
super(plusImage)
|
|
103
|
+
}
|
|
104
|
+
onclick() {
|
|
105
|
+
const block = this.sourceBlock_
|
|
106
|
+
// 增加积木数量改变
|
|
107
|
+
block.itemCount_ += 1
|
|
108
|
+
block.updateShape() // 更新
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// - 按钮
|
|
112
|
+
class MinusButton extends FieldButton {
|
|
113
|
+
constructor() {
|
|
114
|
+
super(minusImage)
|
|
115
|
+
}
|
|
116
|
+
onclick() {
|
|
117
|
+
// 获取这个 field 的积木
|
|
118
|
+
const block = this.sourceBlock_
|
|
119
|
+
// 增加积木数量改变
|
|
120
|
+
block.itemCount_ -= 1
|
|
121
|
+
if (block.itemCount_ < 0) {
|
|
122
|
+
// 不能有 -1 个参数
|
|
123
|
+
block.itemCount_ = 0
|
|
124
|
+
}
|
|
125
|
+
block.updateShape() // 更新
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
class EditButton extends FieldButton {
|
|
130
|
+
constructor() {
|
|
131
|
+
super(editImage)
|
|
132
|
+
}
|
|
133
|
+
onclick() {
|
|
134
|
+
// 获取这个 field 的积木
|
|
135
|
+
const block = this.sourceBlock_
|
|
136
|
+
block.toggleEdit()
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const editImage = 'data:image/svg+xml;base64,PHN2ZyB0PSIxNzEyNjMxNzcxNDkzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjI3MzkiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNNzQyLjQgODQ0LjggNzQyLjQgODQ0LjhjLTMyIDAtNjQtMTIuOC04OS42LTM4LjRsLTE2MC0xNjBjLTg5LjYgMjUuNi0xNzkuMiAwLTI0OS42LTY0QzE2Ni40IDUwNS42IDE0Ny4yIDM5Ni44IDE5MiAyOTQuNGM2LjQtMTIuOCAxMi44LTE5LjIgMjUuNi0xOS4yIDEyLjggMCAxOS4yIDAgMjUuNiA2LjRsMTE1LjIgMTE1LjIgNzAuNC03MC40TDMxMy42IDIxNy42QzMwNy4yIDIxMS4yIDMwMC44IDE5OC40IDMwMC44IDE5MmMwLTEyLjggNi40LTE5LjIgMTkuMi0yNS42IDk2LTQ0LjggMjExLjItMjUuNiAyODggNTEuMiA2NCA2NCA4OS42IDE2MCA2NCAyNDkuNkw4MzIgNjI3LjJjMjUuNiAyNS42IDM4LjQgNTcuNiAzOC40IDg5LjYgMCAzMi0xMi44IDY0LTM4LjQgODkuNkM4MDYuNCA4MzIgNzc0LjQgODQ0LjggNzQyLjQgODQ0Ljh6TTQ5OS4yIDU4Mi40YzYuNCAwIDE5LjIgNi40IDI1LjYgNi40bDE3Mi44IDE3Mi44YzEyLjggMTIuOCAyNS42IDE5LjIgNDQuOCAxOS4ybDAgMGMxOS4yIDAgMzItNi40IDQ0LjgtMTkuMiAxMi44LTEyLjggMTkuMi0yNS42IDE5LjItNDQuOCAwLTE5LjItNi40LTMyLTE5LjItNDQuOEw2MTQuNCA0OTkuMkM2MDEuNiA0OTIuOCA2MDEuNiA0NzMuNiA2MDggNDY3LjIgNjMzLjYgMzk2LjggNjE0LjQgMzIwIDU2My4yIDI2Mi40Yy00NC44LTQ0LjgtMTA4LjgtNjQtMTY2LjQtNTEuMmw4My4yIDgzLjJjMTkuMiAxOS4yIDE5LjIgNTEuMiAwIDcwLjRMMzkwLjQgNDU0LjRDMzcxLjIgNDczLjYgMzM5LjIgNDczLjYgMzIwIDQ1NC40TDIzNi44IDM3MS4yQzIyNCA0MjguOCAyNDMuMiA0OTIuOCAyODggNTM3LjZjNTEuMiA1MS4yIDEyOCA3MC40IDE5OC40IDQ0LjhDNDkyLjggNTgyLjQgNDk5LjIgNTgyLjQgNDk5LjIgNTgyLjR6IiBmaWxsPSIjZmZmZmZmIiBwLWlkPSIyNzQwIj48L3BhdGg+PC9zdmc+'
|
|
140
|
+
// 图片
|
|
141
|
+
const minusImage =
|
|
142
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAw' +
|
|
143
|
+
'MC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ij48cGF0aCBkPS' +
|
|
144
|
+
'JNMTggMTFoLTEyYy0xLjEwNCAwLTIgLjg5Ni0yIDJzLjg5NiAyIDIgMmgxMmMxLjEwNCAw' +
|
|
145
|
+
'IDItLjg5NiAyLTJzLS44OTYtMi0yLTJ6IiBmaWxsPSJ3aGl0ZSIgLz48L3N2Zz4K';
|
|
146
|
+
|
|
147
|
+
const plusImage =
|
|
148
|
+
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC' +
|
|
149
|
+
'9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0Ij48cGF0aCBkPSJNMT' +
|
|
150
|
+
'ggMTBoLTR2LTRjMC0xLjEwNC0uODk2LTItMi0ycy0yIC44OTYtMiAybC4wNzEgNGgtNC4wNz' +
|
|
151
|
+
'FjLTEuMTA0IDAtMiAuODk2LTIgMnMuODk2IDIgMiAybDQuMDcxLS4wNzEtLjA3MSA0LjA3MW' +
|
|
152
|
+
'MwIDEuMTA0Ljg5NiAyIDIgMnMyLS44OTYgMi0ydi00LjA3MWw0IC4wNzFjMS4xMDQgMCAyLS' +
|
|
153
|
+
'44OTYgMi0ycy0uODk2LTItMi0yeiIgZmlsbD0id2hpdGUiIC8+PC9zdmc+Cg==';
|
|
154
|
+
return {
|
|
155
|
+
PlusButton, MinusButton, EditButton
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
modifyScratchBlocks(Blockly) {
|
|
159
|
+
const runtime = this.runtime
|
|
160
|
+
this.workspace = Blockly.getMainWorkspace()
|
|
161
|
+
const ProcedureUtils = Blockly.ScratchBlocks.ProcedureUtils
|
|
162
|
+
|
|
163
|
+
const ExBlockly = {
|
|
164
|
+
attachTextShadow_: function (input, text) {
|
|
165
|
+
var blockType = 'text';
|
|
166
|
+
Blockly.Events.disable();
|
|
167
|
+
try {
|
|
168
|
+
var newBlock = this.workspace.newBlock(blockType);
|
|
169
|
+
newBlock.setFieldValue(text, 'TEXT');
|
|
170
|
+
newBlock.setShadow(true);
|
|
171
|
+
if (!this.isInsertionMarker()) {
|
|
172
|
+
newBlock.initSvg();
|
|
173
|
+
newBlock.render(false);
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
Blockly.Events.enable();
|
|
177
|
+
}
|
|
178
|
+
if (Blockly.Events.isEnabled()) {
|
|
179
|
+
Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
|
|
180
|
+
}
|
|
181
|
+
newBlock.outputConnection.connect(input.connection);
|
|
182
|
+
},
|
|
183
|
+
attachShadow_: function (input, text) {
|
|
184
|
+
var blockType = 'argument_reporter_string_number';
|
|
185
|
+
Blockly.Events.disable();
|
|
186
|
+
try {
|
|
187
|
+
var newBlock = this.workspace.newBlock(blockType);
|
|
188
|
+
newBlock.setFieldValue(text, 'VALUE');
|
|
189
|
+
newBlock.setShadow(true);
|
|
190
|
+
if (!this.isInsertionMarker()) {
|
|
191
|
+
newBlock.initSvg();
|
|
192
|
+
newBlock.render(false);
|
|
193
|
+
}
|
|
194
|
+
} finally {
|
|
195
|
+
Blockly.Events.enable();
|
|
196
|
+
}
|
|
197
|
+
if (Blockly.Events.isEnabled()) {
|
|
198
|
+
Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
|
|
199
|
+
}
|
|
200
|
+
newBlock.outputConnection.connect(input.connection);
|
|
201
|
+
},
|
|
202
|
+
updateShape: function () {
|
|
203
|
+
var wasRendered = this.rendered;
|
|
204
|
+
this.rendered = false;
|
|
205
|
+
|
|
206
|
+
// 更新参数
|
|
207
|
+
Blockly.Events.setGroup(true);
|
|
208
|
+
// 先记录现在的 mutation
|
|
209
|
+
var oldExtraState = Blockly.Xml.domToText(this.mutationToDom(this));
|
|
210
|
+
// 创建新的积木
|
|
211
|
+
for (var i = 0; i < this.itemCount_; i++) {
|
|
212
|
+
if (!this.getInput('ADD' + i)) {
|
|
213
|
+
const input = this.appendValueInput('ADD' + i)
|
|
214
|
+
//this.attachShadow_(input, 's')
|
|
215
|
+
this.moveInputBefore('ADD' + i, 'SUBSTACK')
|
|
216
|
+
if (this.argType == 'arg') {
|
|
217
|
+
this.attachShadow_(input, '参数' + i)
|
|
218
|
+
} else {
|
|
219
|
+
this.attachTextShadow_(input, '')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// const t = ProcedureUtils.createArgumentReporter_('s', '参数' + i)
|
|
223
|
+
// t.outputConnection.connect(input.connection);
|
|
224
|
+
//s = string, b = boolean, n = number
|
|
225
|
+
//这个attachShadow_是来自scratch 自定义函数 的积木
|
|
226
|
+
if (i > 0)
|
|
227
|
+
input.appendField(',')
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 将 + - 按钮移动到最右边
|
|
232
|
+
this.moveInputBefore('PLUSMINUS', null)
|
|
233
|
+
if (runtime._editingTarget) {
|
|
234
|
+
// 移除 input 并记录
|
|
235
|
+
const blocks = runtime._editingTarget.blocks
|
|
236
|
+
const targetBlock = blocks.getBlock(this.id)
|
|
237
|
+
const toDel = []
|
|
238
|
+
while (this.getInput('ADD' + i)) {
|
|
239
|
+
const input = targetBlock.inputs['ADD' + i]
|
|
240
|
+
if (input) {
|
|
241
|
+
if (input.block) {
|
|
242
|
+
const blockInInput = blocks.getBlock(input.block)
|
|
243
|
+
blocks.moveBlock({
|
|
244
|
+
id: blockInInput.id,
|
|
245
|
+
oldParent: this.id,
|
|
246
|
+
oldInput: 'ADD' + i,
|
|
247
|
+
newParent: undefined,
|
|
248
|
+
newInput: undefined,
|
|
249
|
+
//newCoordinate: e.newCoordinate
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (input.shadow && input.shadow == input.block) {
|
|
253
|
+
blocks.deleteBlock(input.shadow)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
toDel.push('ADD' + i)
|
|
257
|
+
//delete targetBlock.inputs['ADD' + i]
|
|
258
|
+
this.removeInput('ADD' + i);
|
|
259
|
+
i++;
|
|
260
|
+
}
|
|
261
|
+
setTimeout(() => {
|
|
262
|
+
toDel.forEach((i) => {
|
|
263
|
+
delete targetBlock.inputs[i]
|
|
264
|
+
})
|
|
265
|
+
}, 0);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 更新 oldItemCount,oldItemCount用于生成domMutation的
|
|
269
|
+
this.oldItemCount = this.itemCount_
|
|
270
|
+
// 新的 mutation
|
|
271
|
+
const newExtraState = Blockly.Xml.domToText(this.mutationToDom(this));
|
|
272
|
+
if (oldExtraState != newExtraState) {
|
|
273
|
+
// 判断是否一样,不一样就fire一个mutation更新事件
|
|
274
|
+
Blockly.Events.fire(
|
|
275
|
+
new Blockly.Events.BlockChange(
|
|
276
|
+
this, 'mutation', null,
|
|
277
|
+
oldExtraState, newExtraState, // 状态
|
|
278
|
+
),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
Blockly.Events.setGroup(false);
|
|
282
|
+
|
|
283
|
+
this.rendered = wasRendered;
|
|
284
|
+
if (wasRendered && !this.isInsertionMarker()) {
|
|
285
|
+
this.initSvg();
|
|
286
|
+
this.render();
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
mutationToDom: function () {
|
|
290
|
+
// 可以保存别的数据,会保存到sb3中,oldItemCount就是有多少个参数
|
|
291
|
+
const container = document.createElement('mutation');
|
|
292
|
+
container.setAttribute('items', `${this.oldItemCount}`);
|
|
293
|
+
return container;
|
|
294
|
+
},
|
|
295
|
+
domToMutation: function (xmlElement) {
|
|
296
|
+
// 读取 mutationToDom 保存的数据
|
|
297
|
+
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 0);
|
|
298
|
+
this.updateShape() // 读了之后更新
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const toggleEdit = function () {
|
|
303
|
+
const changeArgName = function (block, newName, oldName) {
|
|
304
|
+
if (block.type == "argument_reporter_string_number"
|
|
305
|
+
&& block.getFieldValue("VALUE") == oldName
|
|
306
|
+
) {
|
|
307
|
+
block.setFieldValue(newName, "VALUE")
|
|
308
|
+
}
|
|
309
|
+
for (var i = block.childBlocks_.length - 1; i >= 0; i--) {
|
|
310
|
+
changeArgName(block.childBlocks_[i], newName, oldName);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
this.editMode = !this.editMode
|
|
315
|
+
if (this.editMode) {
|
|
316
|
+
this.shadowChache = []
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
for (var i = 0; i < this.itemCount_; i++) {
|
|
320
|
+
const input = this.getInput('ADD' + i)
|
|
321
|
+
const connection = input.connection
|
|
322
|
+
const targetBlock = connection.targetBlock()
|
|
323
|
+
connection.disconnect()
|
|
324
|
+
|
|
325
|
+
if (this.editMode) {
|
|
326
|
+
const argName = targetBlock.getFieldValue('VALUE')
|
|
327
|
+
this.shadowChache.push(argName)
|
|
328
|
+
this.attachTextShadow_(input, argName)
|
|
329
|
+
} else {
|
|
330
|
+
const newName = targetBlock.getFieldValue('TEXT')
|
|
331
|
+
const oldName = this.shadowChache[i]
|
|
332
|
+
// TODO:从SUBSTACK开始,而不是this
|
|
333
|
+
const subBlock = this.getInput("SUBSTACK").connection.targetBlock()
|
|
334
|
+
subBlock && changeArgName(subBlock, newName, oldName)
|
|
335
|
+
this.attachShadow_(input, newName)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const blocks = runtime._editingTarget.blocks
|
|
339
|
+
blocks.deleteBlock(targetBlock)
|
|
340
|
+
targetBlock.dispose()
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const { PlusButton, MinusButton, EditButton } = this.createButtons(Blockly)
|
|
344
|
+
const handler = {
|
|
345
|
+
set: function (target, property, value, _receiver) {
|
|
346
|
+
if (property.slice(0, 4) == "rcompiler") {
|
|
347
|
+
const name = property.slice(5)
|
|
348
|
+
const orgInit = value.init
|
|
349
|
+
value.init = function () {
|
|
350
|
+
orgInit.call(this)
|
|
351
|
+
|
|
352
|
+
if (name == 'use' || name == 'user' || name == 'extuse' || name == 'extuser' || name == 'extuseb') {
|
|
353
|
+
this.plusButton = new PlusButton
|
|
354
|
+
this.minusButton = new MinusButton
|
|
355
|
+
this.itemCount_ = 0
|
|
356
|
+
this.oldItemCount = this.itemCount_
|
|
357
|
+
|
|
358
|
+
this.appendDummyInput("PLUSMINUS")
|
|
359
|
+
.appendField(this.plusButton)
|
|
360
|
+
.appendField(this.minusButton)
|
|
361
|
+
|
|
362
|
+
this.argType = 'text'
|
|
363
|
+
for (const key in ExBlockly) {
|
|
364
|
+
this[key] = ExBlockly[key]
|
|
365
|
+
}
|
|
366
|
+
//this.type = Blockly.OUTPUT_VALUE
|
|
367
|
+
}
|
|
368
|
+
else if (name == 'extdef') {
|
|
369
|
+
this.setOutputShape(Blockly.OUTPUT_SHAPE_SQUARE);
|
|
370
|
+
this.plusButton = new PlusButton
|
|
371
|
+
this.minusButton = new MinusButton
|
|
372
|
+
|
|
373
|
+
this.itemCount_ = 0
|
|
374
|
+
this.oldItemCount = this.itemCount_
|
|
375
|
+
this.editMode = false
|
|
376
|
+
this.toggleEdit = toggleEdit
|
|
377
|
+
this.argType = 'arg'
|
|
378
|
+
for (const key in ExBlockly) {
|
|
379
|
+
this[key] = ExBlockly[key]
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return Reflect.set(target, property, value)
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
this.call_reporter = this.call
|
|
388
|
+
Blockly.Blocks = new Proxy(Blockly.Blocks, handler)
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
let Toggles = {};
|
|
393
|
+
let Values = {};
|
|
394
|
+
let Tri = {}; // 三态设置:'default'(跟随TW/检测)| 'on' | 'off'
|
|
395
|
+
let Modes = {}; // 抗逆向:'normal' | 'obf' | 'debug'
|
|
396
|
+
let App = {}; // 打包配置(extensionStorage.rcompiler.project.App)
|
|
397
|
+
let setConfigs = () => { };
|
|
398
|
+
let RunAtCompile = false;
|
|
399
|
+
|
|
400
|
+
// 兼容不同宿主:优先 Scratch.vm;旧版全局 vm 作为后备
|
|
401
|
+
function rcVM() {
|
|
402
|
+
if (typeof Scratch !== 'undefined' && Scratch.vm) return Scratch.vm;
|
|
403
|
+
return (typeof window !== 'undefined' && window.vm) ? window.vm : null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function rcStorage() {
|
|
407
|
+
const V = rcVM();
|
|
408
|
+
return (V && V.runtime && V.runtime.extensionStorage) ? V.runtime.extensionStorage : null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// 打包配置默认值(与 src/analysis.js 的 APP_DEFAULTS 保持一致)
|
|
412
|
+
const RC_APP_DEFAULTS = {
|
|
413
|
+
Title: null,
|
|
414
|
+
Icon: null,
|
|
415
|
+
Resizable: false,
|
|
416
|
+
Fullscreen: false,
|
|
417
|
+
Decorations: true,
|
|
418
|
+
HideCursor: false,
|
|
419
|
+
Controls: false,
|
|
420
|
+
BtnFlag: false,
|
|
421
|
+
BtnPause: false,
|
|
422
|
+
BtnStop: false,
|
|
423
|
+
Autoplay: true,
|
|
424
|
+
ExitKey: 'none',
|
|
425
|
+
QuitOnStop: false,
|
|
426
|
+
CloneLimit: 300,
|
|
427
|
+
Bg: '#000000',
|
|
428
|
+
StageWidth: null,
|
|
429
|
+
StageHeight: null
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// 旧项目/旧扩展版本迁移:补齐缺失字段,不覆盖已有设置
|
|
433
|
+
function rcEnsureStorage() {
|
|
434
|
+
const st = rcStorage();
|
|
435
|
+
if (!st) return null;
|
|
436
|
+
if (!st.rcompiler || typeof st.rcompiler !== 'object') st.rcompiler = {};
|
|
437
|
+
const cfg = (st.rcompiler.config && typeof st.rcompiler.config === 'object') ? st.rcompiler.config : (st.rcompiler.config = {});
|
|
438
|
+
const proj = (st.rcompiler.project && typeof st.rcompiler.project === 'object') ? st.rcompiler.project : (st.rcompiler.project = {});
|
|
439
|
+
if (typeof cfg.RunAtCompile !== 'boolean') cfg.RunAtCompile = false;
|
|
440
|
+
if (typeof cfg.AllowThis !== 'boolean') cfg.AllowThis = true;
|
|
441
|
+
if (cfg.AntiReverse !== 'obf' && cfg.AntiReverse !== 'debug') cfg.AntiReverse = 'normal';
|
|
442
|
+
if (!proj.App || typeof proj.App !== 'object') proj.App = {};
|
|
443
|
+
for (const k in RC_APP_DEFAULTS) {
|
|
444
|
+
if (proj.App[k] === undefined) proj.App[k] = RC_APP_DEFAULTS[k];
|
|
445
|
+
}
|
|
446
|
+
if (proj.Stage == null) proj.Stage = 'default';
|
|
447
|
+
if (proj.FrameRate == null) proj.FrameRate = 'default';
|
|
448
|
+
if (proj.Interpolation == null) proj.Interpolation = 'default';
|
|
449
|
+
if (proj.numvars == null) proj.numvars = '';
|
|
450
|
+
if (proj.intvars == null) proj.intvars = '';
|
|
451
|
+
if (proj.strvars == null) proj.strvars = '';
|
|
452
|
+
if (proj.numlists == null) proj.numlists = '';
|
|
453
|
+
if (proj.strlists == null) proj.strlists = '';
|
|
454
|
+
if (proj.ignoreExt == null) proj.ignoreExt = '';
|
|
455
|
+
return { cfg, proj };
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function rcReadConfig() {
|
|
459
|
+
const store = rcEnsureStorage();
|
|
460
|
+
if (!store) return;
|
|
461
|
+
const { cfg, proj } = store;
|
|
462
|
+
Toggles.允许编译时执行代码 = !!cfg.RunAtCompile;
|
|
463
|
+
Toggles.允许扩展访问全局 = !!cfg.AllowThis;
|
|
464
|
+
Values.numvars = proj.numvars || '';
|
|
465
|
+
Values.intvars = proj.intvars || '';
|
|
466
|
+
Values.strvars = proj.strvars || '';
|
|
467
|
+
Values.numlists = proj.numlists || '';
|
|
468
|
+
Values.strlists = proj.strlists || '';
|
|
469
|
+
Values.ignoreExt = proj.ignoreExt || '';
|
|
470
|
+
Tri.Stage = proj.Stage || 'default';
|
|
471
|
+
Tri.FrameRate = proj.FrameRate || 'default';
|
|
472
|
+
Tri.Interpolation = proj.Interpolation || 'default';
|
|
473
|
+
Modes.抗逆向 = cfg.AntiReverse || 'normal';
|
|
474
|
+
App = proj.App;
|
|
475
|
+
RunAtCompile = Toggles.允许编译时执行代码;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
setConfigs = () => {
|
|
479
|
+
const V = rcVM();
|
|
480
|
+
if (!V) return;
|
|
481
|
+
rcReadConfig();
|
|
482
|
+
if (V.extensionManager && V.extensionManager.refreshBlocks) V.extensionManager.refreshBlocks();
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
function openModal(modal) {
|
|
486
|
+
const V = rcVM();
|
|
487
|
+
if (!V || !rcEnsureStorage()) return;
|
|
488
|
+
const readVar = (name, fallback) => {
|
|
489
|
+
try {
|
|
490
|
+
const el = document.documentElement;
|
|
491
|
+
let v = getComputedStyle(el).getPropertyValue(name).trim();
|
|
492
|
+
if (!v) v = getComputedStyle(document.body).getPropertyValue(name).trim();
|
|
493
|
+
return v || fallback;
|
|
494
|
+
} catch (error) {
|
|
495
|
+
return fallback;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const accent = readVar('--looks-secondary', V.is_rCodenow ? '#609834' : '#855CD6');
|
|
499
|
+
const accentDark = readVar('--looks-secondary-dark', accent);
|
|
500
|
+
const uiWhite = readVar('--ui-white', '#FFFFFF');
|
|
501
|
+
const textColor = readVar('--text-primary', '#575E75');
|
|
502
|
+
const textDim = readVar('--text-primary-transparent', 'rgba(87, 94, 117, 0.75)');
|
|
503
|
+
const hairline = readVar('--ui-black-transparent', 'rgba(0, 0, 0, 0.15)');
|
|
504
|
+
const radius = '0.5rem';
|
|
505
|
+
const font = '"Helvetica Neue", Helvetica, Arial, sans-serif';
|
|
506
|
+
|
|
507
|
+
const mk = (tag, css, txt) => {
|
|
508
|
+
const node = document.createElement(tag);
|
|
509
|
+
if (css) node.style.cssText = css;
|
|
510
|
+
if (txt != null) node.textContent = txt;
|
|
511
|
+
return node;
|
|
512
|
+
};
|
|
513
|
+
const buttonStyle = `height:32px;padding:0 .75rem;border:1px solid ${hairline};border-radius:${radius};background:${uiWhite};color:${textColor};font:inherit;font-size:.8rem;cursor:pointer;white-space:nowrap;`;
|
|
514
|
+
const mkButton = (txt, onclick) => {
|
|
515
|
+
const b = mk('button', buttonStyle, txt);
|
|
516
|
+
b.type = 'button';
|
|
517
|
+
b.addEventListener('mouseenter', () => { b.style.borderColor = accent; b.style.color = accent; });
|
|
518
|
+
b.addEventListener('mouseleave', () => { b.style.borderColor = hairline; b.style.color = textColor; });
|
|
519
|
+
b.addEventListener('click', onclick);
|
|
520
|
+
return b;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// 同一时刻只保留一个配置弹窗(重复点击按钮不会叠加)
|
|
524
|
+
document.querySelectorAll('[data-rcompiler-modal]').forEach((el) => el.remove());
|
|
525
|
+
|
|
526
|
+
let mask = mk('div', `position:fixed;inset:0;z-index:996;display:none;background:${readVar('--ui-modal-overlay', 'rgba(0, 0, 0, 0.35)')};`);
|
|
527
|
+
mask.setAttribute('data-rcompiler-modal', 'mask');
|
|
528
|
+
document.body.appendChild(mask);
|
|
529
|
+
|
|
530
|
+
let dialog = mk('div', `position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);z-index:997;display:none;flex-direction:column;width:min(560px, calc(100vw - 32px));max-height:calc(100vh - 64px);background:${uiWhite};color:${textColor};border:1px solid ${hairline};border-radius:${radius};box-shadow:0 6px 24px rgba(0, 0, 0, 0.18);overflow:hidden;font-family:${font};font-size:14px;outline:none;`);
|
|
531
|
+
dialog.tabIndex = -1;
|
|
532
|
+
dialog.setAttribute('data-rcompiler-modal', 'dialog');
|
|
533
|
+
dialog.setAttribute('role', 'dialog');
|
|
534
|
+
dialog.setAttribute('aria-modal', 'true');
|
|
535
|
+
dialog.setAttribute('aria-label', modal === 'CompilerConfig' ? '编译器配置' : '项目配置');
|
|
536
|
+
document.body.appendChild(dialog);
|
|
537
|
+
|
|
538
|
+
const header = mk('div', `display:flex;flex:0 0 auto;align-items:center;justify-content:space-between;gap:1rem;padding:.75rem 1rem;border-bottom:1px solid ${hairline};background:${uiWhite};`);
|
|
539
|
+
const title = mk('div', 'font-size:.95rem;font-weight:700;', modal === 'CompilerConfig' ? '编译器配置' : '项目配置');
|
|
540
|
+
const close = mk('button', `width:28px;height:28px;padding:0;border:none;border-radius:50%;background:transparent;color:${textColor};font:inherit;font-size:20px;line-height:1;cursor:pointer;`);
|
|
541
|
+
close.type = 'button';
|
|
542
|
+
close.textContent = '×';
|
|
543
|
+
close.setAttribute('aria-label', '关闭');
|
|
544
|
+
close.addEventListener('mouseenter', () => { close.style.background = hairline; });
|
|
545
|
+
close.addEventListener('mouseleave', () => { close.style.background = 'transparent'; });
|
|
546
|
+
close.addEventListener('click', () => hideWindow());
|
|
547
|
+
header.appendChild(title);
|
|
548
|
+
header.appendChild(close);
|
|
549
|
+
|
|
550
|
+
const body = mk('div', `flex:1 1 auto;min-height:0;padding:1rem;overflow-y:auto;`);
|
|
551
|
+
const footer = mk('div', `display:flex;flex:0 0 auto;align-items:center;justify-content:flex-end;gap:.5rem;padding:.75rem 1rem;border-top:1px solid ${hairline};`);
|
|
552
|
+
const footNote = mk('div', `margin-right:auto;color:${textDim};font-size:.75rem;`, modal === 'CompilerConfig' ? '设置随项目保存' : '打包项仅对启用舞台的项目生效');
|
|
553
|
+
const done = mk('button', `height:32px;padding:0 1rem;border:1px solid ${accent};border-radius:${radius};background:${accent};color:#FFFFFF;font:inherit;font-size:.85rem;cursor:pointer;`, '完成');
|
|
554
|
+
done.type = 'button';
|
|
555
|
+
done.addEventListener('mouseenter', () => { done.style.background = accentDark; done.style.borderColor = accentDark; });
|
|
556
|
+
done.addEventListener('mouseleave', () => { done.style.background = accent; done.style.borderColor = accent; });
|
|
557
|
+
done.addEventListener('click', () => hideWindow());
|
|
558
|
+
footer.appendChild(footNote);
|
|
559
|
+
footer.appendChild(done);
|
|
560
|
+
|
|
561
|
+
dialog.appendChild(header);
|
|
562
|
+
dialog.appendChild(body);
|
|
563
|
+
dialog.appendChild(footer);
|
|
564
|
+
|
|
565
|
+
const hideWindow = () => {
|
|
566
|
+
dialog.style.display = 'none';
|
|
567
|
+
mask.style.display = 'none';
|
|
568
|
+
dialog.remove();
|
|
569
|
+
mask.remove();
|
|
570
|
+
};
|
|
571
|
+
mask.addEventListener('click', (event) => {
|
|
572
|
+
if (event.target === mask) hideWindow();
|
|
573
|
+
});
|
|
574
|
+
dialog.addEventListener('keydown', (event) => {
|
|
575
|
+
if (event.key === 'Escape') hideWindow();
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
const section = (name, first) => {
|
|
579
|
+
const sec = mk('div', first ? 'margin:0;' : `margin-top:1.25rem;padding-top:1rem;border-top:1px solid ${hairline};`);
|
|
580
|
+
if (name) sec.appendChild(mk('div', 'margin-bottom:.55rem;font-size:.85rem;font-weight:700;', name));
|
|
581
|
+
body.appendChild(sec);
|
|
582
|
+
return sec;
|
|
583
|
+
};
|
|
584
|
+
const hint = (parent, txt, indent) => {
|
|
585
|
+
const h = mk('div', `margin:${indent ? '-.1rem 0 .5rem 130px' : '.25rem 0 .5rem'};color:${textDim};font-size:.75rem;line-height:1.45;`, txt);
|
|
586
|
+
parent.appendChild(h);
|
|
587
|
+
return h;
|
|
588
|
+
};
|
|
589
|
+
const row = (parent, labelText) => {
|
|
590
|
+
const r = mk('div', 'display:flex;align-items:center;gap:.75rem;min-height:36px;margin-bottom:.35rem;');
|
|
591
|
+
r.appendChild(mk('div', 'flex:0 0 130px;font-size:.85rem;font-weight:700;', labelText));
|
|
592
|
+
const ctl = mk('div', 'display:flex;flex:1 1 auto;align-items:center;gap:.5rem;min-width:0;');
|
|
593
|
+
r.appendChild(ctl);
|
|
594
|
+
parent.appendChild(r);
|
|
595
|
+
return ctl;
|
|
596
|
+
};
|
|
597
|
+
const switchControl = (value, onChange) => {
|
|
598
|
+
let on = !!value;
|
|
599
|
+
const sw = mk('button', `position:relative;flex:0 0 auto;width:42px;height:24px;padding:0;border:none;border-radius:12px;background:${on ? accent : '#C9CCD4'};cursor:pointer;transition:background .15s;`);
|
|
600
|
+
sw.type = 'button';
|
|
601
|
+
sw.setAttribute('aria-pressed', String(on));
|
|
602
|
+
const knob = mk('span', `position:absolute;top:3px;left:3px;width:18px;height:18px;border-radius:50%;background:#FFFFFF;box-shadow:0 1px 2px rgba(0, 0, 0, 0.25);transition:transform .15s;transform:translateX(${on ? 18 : 0}px);`);
|
|
603
|
+
sw.appendChild(knob);
|
|
604
|
+
sw.addEventListener('click', () => {
|
|
605
|
+
on = !on;
|
|
606
|
+
sw.style.background = on ? accent : '#C9CCD4';
|
|
607
|
+
knob.style.transform = `translateX(${on ? 18 : 0}px)`;
|
|
608
|
+
sw.setAttribute('aria-pressed', String(on));
|
|
609
|
+
onChange(on);
|
|
610
|
+
});
|
|
611
|
+
return sw;
|
|
612
|
+
};
|
|
613
|
+
const segment = (options, value, onChange) => {
|
|
614
|
+
let cur = value;
|
|
615
|
+
const wrap = mk('div', `display:inline-flex;flex:0 0 auto;border:1px solid ${hairline};border-radius:${radius};background:${uiWhite};overflow:hidden;`);
|
|
616
|
+
let paint = () => { };
|
|
617
|
+
const buttons = options.map(([val, label]) => {
|
|
618
|
+
const b = mk('button', 'padding:.35rem .7rem;border:none;background:transparent;font:inherit;font-size:.8rem;cursor:pointer;transition:background .15s,color .15s;white-space:nowrap;');
|
|
619
|
+
b.type = 'button';
|
|
620
|
+
b.textContent = label;
|
|
621
|
+
b.addEventListener('click', () => {
|
|
622
|
+
cur = val;
|
|
623
|
+
paint();
|
|
624
|
+
onChange(val);
|
|
625
|
+
});
|
|
626
|
+
wrap.appendChild(b);
|
|
627
|
+
return [val, b];
|
|
628
|
+
});
|
|
629
|
+
paint = () => {
|
|
630
|
+
for (const [val, b] of buttons) {
|
|
631
|
+
const on = val === cur;
|
|
632
|
+
b.style.background = on ? accent : 'transparent';
|
|
633
|
+
b.style.color = on ? '#FFFFFF' : textColor;
|
|
634
|
+
b.style.fontWeight = on ? '700' : '400';
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
paint();
|
|
638
|
+
return wrap;
|
|
639
|
+
};
|
|
640
|
+
const textInput = (value, placeholder, onChange, extraCss) => {
|
|
641
|
+
const input = mk('input', `flex:1 1 auto;min-width:0;height:32px;padding:0 .5rem;border:1px solid ${hairline};border-radius:${radius};background:${uiWhite};color:${textColor};font:inherit;font-size:.85rem;outline:none;${extraCss || ''}`);
|
|
642
|
+
input.type = 'text';
|
|
643
|
+
input.value = value == null ? '' : String(value);
|
|
644
|
+
input.placeholder = placeholder || '';
|
|
645
|
+
input.addEventListener('focus', () => { input.style.borderColor = accent; });
|
|
646
|
+
input.addEventListener('blur', () => { input.style.borderColor = hairline; onChange(input.value); });
|
|
647
|
+
input.addEventListener('keydown', (event) => { if (event.key === 'Enter') input.blur(); });
|
|
648
|
+
return input;
|
|
649
|
+
};
|
|
650
|
+
const numberInput = (value, onChange) => {
|
|
651
|
+
const input = mk('input', `width:110px;height:32px;padding:0 .5rem;border:1px solid ${hairline};border-radius:${radius};background:${uiWhite};color:${textColor};font:inherit;font-size:.85rem;outline:none;`);
|
|
652
|
+
input.type = 'number';
|
|
653
|
+
input.min = '1';
|
|
654
|
+
input.max = '9999';
|
|
655
|
+
input.value = String(value);
|
|
656
|
+
input.addEventListener('focus', () => { input.style.borderColor = accent; });
|
|
657
|
+
input.addEventListener('blur', () => {
|
|
658
|
+
input.style.borderColor = hairline;
|
|
659
|
+
const fixed = onChange(input.value);
|
|
660
|
+
if (fixed != null) input.value = String(fixed);
|
|
661
|
+
});
|
|
662
|
+
return input;
|
|
663
|
+
};
|
|
664
|
+
const normColor = (raw) => {
|
|
665
|
+
const m = String(raw || '').trim().match(/^#?([0-9a-fA-F]{6})$/);
|
|
666
|
+
return m ? ('#' + m[1].toLowerCase()) : null;
|
|
667
|
+
};
|
|
668
|
+
const appBool = (key, dflt) => {
|
|
669
|
+
const v = App[key];
|
|
670
|
+
if (v === 'on' || v === true) return true;
|
|
671
|
+
if (v === 'off' || v === false) return false;
|
|
672
|
+
return dflt;
|
|
673
|
+
};
|
|
674
|
+
const setApp = (key, value) => {
|
|
675
|
+
const store = rcEnsureStorage();
|
|
676
|
+
if (!store) return;
|
|
677
|
+
store.proj.App[key] = value;
|
|
678
|
+
App[key] = value;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
if (modal === 'CompilerConfig') {
|
|
682
|
+
const cfg = rcStorage().rcompiler.config;
|
|
683
|
+
const sec = section('安全', true);
|
|
684
|
+
const ctl1 = row(sec, '允许编译时执行代码');
|
|
685
|
+
ctl1.appendChild(switchControl(!!cfg.RunAtCompile, (on) => {
|
|
686
|
+
cfg.RunAtCompile = on;
|
|
687
|
+
Toggles.允许编译时执行代码 = on;
|
|
688
|
+
RunAtCompile = on;
|
|
689
|
+
}));
|
|
690
|
+
const ctl2 = row(sec, '允许扩展访问全局');
|
|
691
|
+
ctl2.appendChild(switchControl(!!cfg.AllowThis, (on) => {
|
|
692
|
+
cfg.AllowThis = on;
|
|
693
|
+
Toggles.允许扩展访问全局 = on;
|
|
694
|
+
}));
|
|
695
|
+
hint(sec, '开启后,项目中的扩展代码可在编译阶段执行,并能访问编译器内部全局对象。来源不可信的项目请保持关闭。');
|
|
696
|
+
|
|
697
|
+
const arc = section('抗逆向');
|
|
698
|
+
const arcDesc = {
|
|
699
|
+
normal: '保持现状:仅暴露资产名称与文本,无额外性能损失。',
|
|
700
|
+
obf: '加密资产与文本、去除符号并启用全量 LTO,建议发布时使用。',
|
|
701
|
+
debug: '保留角色名/变量名/块号,编译错误可定位到原项目积木。'
|
|
702
|
+
};
|
|
703
|
+
const arcHint = mk('div', `margin:.15rem 0 .5rem 130px;color:${textDim};font-size:.75rem;line-height:1.45;`, arcDesc[Modes.抗逆向] || arcDesc.normal);
|
|
704
|
+
const arcCtl = row(arc, '模式');
|
|
705
|
+
arcCtl.appendChild(segment([
|
|
706
|
+
['normal', '正常'],
|
|
707
|
+
['obf', '混淆'],
|
|
708
|
+
['debug', '调试']
|
|
709
|
+
], Modes.抗逆向 || 'normal', (v) => {
|
|
710
|
+
const store = rcEnsureStorage();
|
|
711
|
+
if (store) store.cfg.AntiReverse = v;
|
|
712
|
+
Modes.抗逆向 = v;
|
|
713
|
+
arcHint.textContent = arcDesc[v] || arcDesc.normal;
|
|
714
|
+
}));
|
|
715
|
+
arc.appendChild(arcHint);
|
|
716
|
+
hint(arc, '混淆模式下调试用环境变量(RCOMPILER_STAGE_DUMP)会被移除;调试模式会生成 main.rs.rcmap.json。', true);
|
|
717
|
+
} else if (modal === 'ProjectConfig') {
|
|
718
|
+
const proj = rcStorage().rcompiler.project;
|
|
719
|
+
const opt = section('优化', true);
|
|
720
|
+
const triRow = (label, key) => {
|
|
721
|
+
const ctl = row(opt, label);
|
|
722
|
+
ctl.appendChild(segment([
|
|
723
|
+
['default', '默认'],
|
|
724
|
+
['on', '开启'],
|
|
725
|
+
['off', '关闭']
|
|
726
|
+
], Tri[key] || 'default', (v) => {
|
|
727
|
+
proj[key] = v;
|
|
728
|
+
Tri[key] = v;
|
|
729
|
+
}));
|
|
730
|
+
};
|
|
731
|
+
triRow('舞台', 'Stage');
|
|
732
|
+
triRow('帧率设置', 'FrameRate');
|
|
733
|
+
triRow('视觉插值', 'Interpolation');
|
|
734
|
+
hint(opt, '默认:舞台与帧率跟随 TurboWarp 项目设置;视觉插值需舞台 + 帧门控 + 非 turbo。');
|
|
735
|
+
|
|
736
|
+
const types = section('手动类型');
|
|
737
|
+
const typeRow = (label, key, placeholder) => {
|
|
738
|
+
const ctl = row(types, label);
|
|
739
|
+
ctl.appendChild(textInput(Values[key], placeholder, (v) => {
|
|
740
|
+
proj[key] = v;
|
|
741
|
+
Values[key] = v;
|
|
742
|
+
}));
|
|
743
|
+
};
|
|
744
|
+
typeRow('数字变量', 'numvars', '变量名,逗号分隔');
|
|
745
|
+
typeRow('整数变量', 'intvars', '变量名,逗号分隔');
|
|
746
|
+
typeRow('字符串变量', 'strvars', '变量名,逗号分隔');
|
|
747
|
+
typeRow('数字列表', 'numlists', '列表名,逗号分隔');
|
|
748
|
+
typeRow('字符串列表', 'strlists', '列表名,逗号分隔');
|
|
749
|
+
hint(types, '声明后编译器会为变量/列表生成单类型字段,减少运行时的类型判断与锁。也可以直接用类型声明积木。');
|
|
750
|
+
|
|
751
|
+
const pack = section('打包');
|
|
752
|
+
const titleCtl = row(pack, '窗口标题');
|
|
753
|
+
titleCtl.appendChild(textInput(App.Title == null ? '' : App.Title, '留空则使用项目名', (v) => {
|
|
754
|
+
setApp('Title', v.trim() ? v.trim() : null);
|
|
755
|
+
}));
|
|
756
|
+
const iconCtl = row(pack, '应用图标');
|
|
757
|
+
const iconWrap = mk('div', 'display:flex;align-items:center;gap:.5rem;min-width:0;');
|
|
758
|
+
const preview = mk('div', `display:flex;flex:0 0 auto;align-items:center;justify-content:center;width:34px;height:34px;border:1px solid ${hairline};border-radius:${radius};background:repeating-conic-gradient(#F1F3F6 0% 25%, #FFFFFF 0% 50%) 50% / 8px 8px;overflow:hidden;`);
|
|
759
|
+
const previewImg = mk('img', 'display:none;max-width:100%;max-height:100%;image-rendering:auto;');
|
|
760
|
+
preview.appendChild(previewImg);
|
|
761
|
+
const showIcon = (src) => {
|
|
762
|
+
if (src) {
|
|
763
|
+
previewImg.src = src;
|
|
764
|
+
previewImg.style.display = 'block';
|
|
765
|
+
} else {
|
|
766
|
+
previewImg.removeAttribute('src');
|
|
767
|
+
previewImg.style.display = 'none';
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
showIcon(App.Icon);
|
|
771
|
+
const iconFile = mk('input', 'display:none;');
|
|
772
|
+
iconFile.type = 'file';
|
|
773
|
+
iconFile.accept = 'image/png,.png';
|
|
774
|
+
const chooseIcon = mkButton('选择 PNG', () => iconFile.click());
|
|
775
|
+
const iconError = mk('div', `margin:-.1rem 0 .5rem 130px;color:#C24A3E;font-size:.75rem;line-height:1.4;`);
|
|
776
|
+
const clearIcon = mkButton('清除', () => {
|
|
777
|
+
showIcon(null);
|
|
778
|
+
iconFile.value = '';
|
|
779
|
+
setApp('Icon', null);
|
|
780
|
+
iconError.textContent = '';
|
|
781
|
+
});
|
|
782
|
+
iconFile.addEventListener('change', () => {
|
|
783
|
+
const file = iconFile.files && iconFile.files[0];
|
|
784
|
+
if (!file) return;
|
|
785
|
+
const isPng = (file.type === 'image/png') || (!file.type && /\.png$/i.test(file.name));
|
|
786
|
+
if (!isPng) {
|
|
787
|
+
iconError.textContent = '仅支持 PNG 格式的图标。';
|
|
788
|
+
iconFile.value = '';
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const reader = new FileReader();
|
|
792
|
+
reader.onload = () => {
|
|
793
|
+
const data = String(reader.result || '');
|
|
794
|
+
if (!data.startsWith('data:image/png;base64,')) {
|
|
795
|
+
iconError.textContent = '图标读取失败,请重新选择 PNG。';
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
iconError.textContent = '';
|
|
799
|
+
showIcon(data);
|
|
800
|
+
setApp('Icon', data);
|
|
801
|
+
};
|
|
802
|
+
reader.onerror = () => { iconError.textContent = '图标读取失败。'; };
|
|
803
|
+
reader.readAsDataURL(file);
|
|
804
|
+
iconFile.value = '';
|
|
805
|
+
});
|
|
806
|
+
iconWrap.appendChild(preview);
|
|
807
|
+
iconWrap.appendChild(chooseIcon);
|
|
808
|
+
iconWrap.appendChild(clearIcon);
|
|
809
|
+
iconWrap.appendChild(iconFile);
|
|
810
|
+
iconCtl.appendChild(iconWrap);
|
|
811
|
+
pack.appendChild(iconError);
|
|
812
|
+
hint(pack, '仅 PNG。Windows 构建时同时写入 EXE 图标(超过 256×256 仅作运行时窗口图标)。', true);
|
|
813
|
+
|
|
814
|
+
const swRow = (label, key, dflt) => {
|
|
815
|
+
const ctl = row(pack, label);
|
|
816
|
+
ctl.appendChild(switchControl(appBool(key, dflt), (on) => setApp(key, on)));
|
|
817
|
+
};
|
|
818
|
+
swRow('窗口可缩放', 'Resizable', false);
|
|
819
|
+
swRow('全屏启动', 'Fullscreen', false);
|
|
820
|
+
swRow('显示窗口边框', 'Decorations', true);
|
|
821
|
+
swRow('隐藏鼠标指针', 'HideCursor', false);
|
|
822
|
+
// 顶栏三按钮独立开关(对照 TurboWarp 打包器;旧版 Controls=true 会全部展开为开)
|
|
823
|
+
swRow('顶栏·绿旗按钮', 'BtnFlag', false);
|
|
824
|
+
swRow('顶栏·暂停按钮', 'BtnPause', false);
|
|
825
|
+
swRow('顶栏·停止按钮', 'BtnStop', false);
|
|
826
|
+
swRow('自动启动', 'Autoplay', true);
|
|
827
|
+
swRow('停止后退出', 'QuitOnStop', false);
|
|
828
|
+
|
|
829
|
+
// 舞台长宽(留空 = 跟随 TurboWarp 项目设置 / 默认 480×360)
|
|
830
|
+
const sizeRow = (label, key) => {
|
|
831
|
+
const ctl = row(pack, label);
|
|
832
|
+
const input = mk('input', 'width:90px;height:32px;padding:0 .5rem;border:1px solid ' + hairline + ';border-radius:' + radius + ';background:' + uiWhite + ';color:' + textColor + ';font:inherit;font-size:.85rem;outline:none;');
|
|
833
|
+
input.type = 'number';
|
|
834
|
+
input.min = '20';
|
|
835
|
+
input.max = '1920';
|
|
836
|
+
input.placeholder = '跟随 TW';
|
|
837
|
+
input.value = App[key] == null ? '' : String(App[key]);
|
|
838
|
+
input.addEventListener('focus', () => { input.style.borderColor = accent; });
|
|
839
|
+
input.addEventListener('blur', () => {
|
|
840
|
+
input.style.borderColor = hairline;
|
|
841
|
+
const t = input.value.trim();
|
|
842
|
+
if (t === '') { setApp(key, null); return; }
|
|
843
|
+
const n = Math.round(Number(t));
|
|
844
|
+
if (!Number.isFinite(n)) { input.value = ''; setApp(key, null); return; }
|
|
845
|
+
const clamped = Math.max(20, Math.min(key === 'StageHeight' ? 1600 : 1920, n));
|
|
846
|
+
input.value = String(clamped);
|
|
847
|
+
setApp(key, clamped);
|
|
848
|
+
});
|
|
849
|
+
ctl.appendChild(input);
|
|
850
|
+
};
|
|
851
|
+
sizeRow('舞台宽', 'StageWidth');
|
|
852
|
+
sizeRow('舞台高', 'StageHeight');
|
|
853
|
+
hint(pack, '舞台长宽留空时跟随 TurboWarp 项目设置(宽高注释),默认 480×360。', true);
|
|
854
|
+
|
|
855
|
+
const exitCtl = row(pack, '退出快捷键');
|
|
856
|
+
exitCtl.appendChild(segment([
|
|
857
|
+
['none', '无'],
|
|
858
|
+
['escape', 'Esc'],
|
|
859
|
+
['ctrlq', 'Ctrl+Q']
|
|
860
|
+
], App.ExitKey || 'none', (v) => setApp('ExitKey', v)));
|
|
861
|
+
|
|
862
|
+
const cloneCtl = row(pack, '克隆上限');
|
|
863
|
+
cloneCtl.appendChild(numberInput(Number(App.CloneLimit) || 300, (v) => {
|
|
864
|
+
const n = Math.max(1, Math.min(9999, Math.round(Number(v) || 300)));
|
|
865
|
+
setApp('CloneLimit', n);
|
|
866
|
+
return n;
|
|
867
|
+
}));
|
|
868
|
+
cloneCtl.appendChild(mk('span', `color:${textDim};font-size:.75rem;`, '1 – 9999'));
|
|
869
|
+
|
|
870
|
+
const bgCtl = row(pack, '窗口背景色');
|
|
871
|
+
const picker = mk('input', `width:34px;height:32px;padding:0;border:1px solid ${hairline};border-radius:${radius};background:${uiWhite};cursor:pointer;`);
|
|
872
|
+
picker.type = 'color';
|
|
873
|
+
picker.value = normColor(App.Bg) || '#000000';
|
|
874
|
+
const hex = textInput(picker.value, '#000000', (v) => {
|
|
875
|
+
const c = normColor(v);
|
|
876
|
+
if (c) {
|
|
877
|
+
picker.value = c;
|
|
878
|
+
hex.value = c;
|
|
879
|
+
setApp('Bg', c);
|
|
880
|
+
} else {
|
|
881
|
+
hex.value = picker.value;
|
|
882
|
+
}
|
|
883
|
+
}, 'max-width:110px;flex:0 0 auto;');
|
|
884
|
+
picker.addEventListener('input', () => {
|
|
885
|
+
hex.value = picker.value;
|
|
886
|
+
setApp('Bg', picker.value);
|
|
887
|
+
});
|
|
888
|
+
bgCtl.appendChild(picker);
|
|
889
|
+
bgCtl.appendChild(hex);
|
|
890
|
+
hint(pack, '用于窗口比例与舞台不一致时的黑边填充。', true);
|
|
891
|
+
|
|
892
|
+
const dbg = section('调试');
|
|
893
|
+
const ignoreCtl = row(dbg, '自动忽略扩展');
|
|
894
|
+
ignoreCtl.appendChild(textInput(Values.ignoreExt, '扩展 id,逗号分隔', (v) => {
|
|
895
|
+
proj.ignoreExt = v;
|
|
896
|
+
Values.ignoreExt = v;
|
|
897
|
+
}));
|
|
898
|
+
hint(dbg, '名单中扩展的全部积木在编译时整体跳过:不加载扩展源码、不注册其依赖,其报告器取中性值(0/空/false)。标准积木类别不受影响。√ 不使用异步运行时 / 不循环克隆的角色 已由编译器自动侦测');
|
|
899
|
+
} else {
|
|
900
|
+
throw new Error('未知的配置面板:' + modal);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
dialog.style.display = 'flex';
|
|
904
|
+
mask.style.display = 'block';
|
|
905
|
+
dialog.focus();
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
async function regist(ifcompilerload) {
|
|
909
|
+
const V = rcVM();
|
|
910
|
+
if (!V) return;
|
|
911
|
+
new button(Scratch.vm.runtime);
|
|
912
|
+
const runtime = V.runtime;
|
|
913
|
+
const cbfsb = runtime._convertBlockForScratchBlocks.bind(runtime);
|
|
914
|
+
runtime._convertBlockForScratchBlocks = function (blockInfo, categoryInfo) {
|
|
915
|
+
const res = cbfsb(blockInfo, categoryInfo);
|
|
916
|
+
if (blockInfo.opcode == 'typechoose') {
|
|
917
|
+
res.json.args0[1] = {
|
|
918
|
+
"type": "field_input",
|
|
919
|
+
"name": "type",
|
|
920
|
+
"text": ""
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (blockInfo.全局) {
|
|
924
|
+
res.json.previousStatement = void 0;
|
|
925
|
+
res.json.nextStatement = void 0;
|
|
926
|
+
}
|
|
927
|
+
if (blockInfo.直接编译) {
|
|
928
|
+
res.json.args0 = [
|
|
929
|
+
{
|
|
930
|
+
"type": "field_input",
|
|
931
|
+
"name": "HEADER",
|
|
932
|
+
"text": ""
|
|
933
|
+
}
|
|
934
|
+
]
|
|
935
|
+
}
|
|
936
|
+
if (blockInfo.usefield) {
|
|
937
|
+
blockInfo.usefield.forEach(element => {
|
|
938
|
+
const name = res.json.args0[element].name;
|
|
939
|
+
res.json.args0[element] = {
|
|
940
|
+
"type": "field_input",
|
|
941
|
+
"name": name,
|
|
942
|
+
"text": blockInfo.arguments[name].defalutValue
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
if (blockInfo.opcode == 'fromcomment' || blockInfo.opcode == 'varset' || blockInfo.opcode == 'varcreate') {
|
|
947
|
+
res.json.args0[0] =
|
|
948
|
+
{
|
|
949
|
+
"type": "field_input",
|
|
950
|
+
"name": "HEADER",
|
|
951
|
+
"text": ""
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
return res;
|
|
955
|
+
}
|
|
956
|
+
let name = 'rcompiler';
|
|
957
|
+
let blocks = [
|
|
958
|
+
{
|
|
959
|
+
blockType: Scratch.BlockType.LABEL,
|
|
960
|
+
text: 'Wait a moment...'
|
|
961
|
+
},
|
|
962
|
+
{
|
|
963
|
+
blockType: Scratch.BlockType.LABEL,
|
|
964
|
+
text: 'Good stuff is coming...'
|
|
965
|
+
}
|
|
966
|
+
];
|
|
967
|
+
let menus = {};
|
|
968
|
+
class rcompilerHelper {
|
|
969
|
+
getInfo() {
|
|
970
|
+
return {
|
|
971
|
+
id: 'rcompiler',
|
|
972
|
+
name,
|
|
973
|
+
color1: '#192d50',
|
|
974
|
+
color2: '#294a84',
|
|
975
|
+
color3: '#294a84',
|
|
976
|
+
blocks,
|
|
977
|
+
menus
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
import() {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
fromcomment() {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
func() {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
use() {
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
user() {
|
|
993
|
+
return '';
|
|
994
|
+
}
|
|
995
|
+
funcargin() {
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
compile() {
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
compilerversion() {
|
|
1002
|
+
return new rcompiler().version();
|
|
1003
|
+
}
|
|
1004
|
+
outcompiler() {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
outcompilerr() {
|
|
1008
|
+
return '';
|
|
1009
|
+
}
|
|
1010
|
+
outcompilerb() {
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
setdepend() {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
setlibrary() {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
varcreate(args, util) {
|
|
1020
|
+
const thread = util.thread;
|
|
1021
|
+
if (!thread.variables) thread.variables = Object.create(null);
|
|
1022
|
+
const vars = thread.variables;
|
|
1023
|
+
vars[args.var] = '';
|
|
1024
|
+
}
|
|
1025
|
+
varset(args, util) {
|
|
1026
|
+
const thread = util.thread;
|
|
1027
|
+
if (!thread.variables) thread.variables = Object.create(null);
|
|
1028
|
+
const vars = thread.variables;
|
|
1029
|
+
vars[args.var] = args.thing;
|
|
1030
|
+
}
|
|
1031
|
+
varget(args, util) {
|
|
1032
|
+
const thread = util.thread;
|
|
1033
|
+
if (!thread.variables) thread.variables = Object.create(null);
|
|
1034
|
+
const vars = thread.variables;
|
|
1035
|
+
const varValue = vars[args.VAR];
|
|
1036
|
+
if (typeof varValue === "undefined") return "";
|
|
1037
|
+
return varValue;
|
|
1038
|
+
}
|
|
1039
|
+
setruntime() {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
setmain() {
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
setinuse() {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
cloneandwait() {
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
help() {
|
|
1052
|
+
window.open('https://git.0832.ink/LingbaSanar/rCompiler#readme');
|
|
1053
|
+
}
|
|
1054
|
+
compilenow() {
|
|
1055
|
+
return new rcompiler().compile(JSON.parse(V.toJSON())).out;
|
|
1056
|
+
}
|
|
1057
|
+
typeas() {
|
|
1058
|
+
return '';
|
|
1059
|
+
}
|
|
1060
|
+
typeis() {
|
|
1061
|
+
return '';
|
|
1062
|
+
}
|
|
1063
|
+
typechoose() {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
typeof() {
|
|
1067
|
+
return '';
|
|
1068
|
+
}
|
|
1069
|
+
openCompilerConfig() {
|
|
1070
|
+
setConfigs();
|
|
1071
|
+
openModal('CompilerConfig');
|
|
1072
|
+
}
|
|
1073
|
+
openProjectConfig() {
|
|
1074
|
+
setConfigs();
|
|
1075
|
+
openModal('ProjectConfig');
|
|
1076
|
+
}
|
|
1077
|
+
ignore() {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
extdef() {
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
extuse() {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
extuser() {
|
|
1087
|
+
return '';
|
|
1088
|
+
}
|
|
1089
|
+
extuseb() {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
flaguse() {
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
blocks = [
|
|
1097
|
+
{
|
|
1098
|
+
func: "help",
|
|
1099
|
+
blockType: Scratch.BlockType.BUTTON,
|
|
1100
|
+
text: await t('不知道怎么使用?')
|
|
1101
|
+
},
|
|
1102
|
+
'---',
|
|
1103
|
+
{
|
|
1104
|
+
func: "openCompilerConfig",
|
|
1105
|
+
blockType: Scratch.BlockType.BUTTON,
|
|
1106
|
+
text: await t('编译器配置')
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
func: "openProjectConfig",
|
|
1110
|
+
blockType: Scratch.BlockType.BUTTON,
|
|
1111
|
+
text: await t('项目配置')
|
|
1112
|
+
},
|
|
1113
|
+
'---',
|
|
1114
|
+
{
|
|
1115
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1116
|
+
text: await t('编译')
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
opcode: 'compile',
|
|
1120
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1121
|
+
text: await t('编译器指令 [to]'),
|
|
1122
|
+
直接编译: 1
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
opcode: 'outcompiler',
|
|
1126
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1127
|
+
text: await t('直接编译 [to]'),
|
|
1128
|
+
直接编译: 1
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
opcode: 'outcompilerr',
|
|
1132
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1133
|
+
text: await t('直接编译 [to]'),
|
|
1134
|
+
直接编译: 1
|
|
1135
|
+
},
|
|
1136
|
+
{
|
|
1137
|
+
opcode: 'outcompilerb',
|
|
1138
|
+
blockType: Scratch.BlockType.BOOLEAN,
|
|
1139
|
+
text: await t('直接编译 [to]'),
|
|
1140
|
+
直接编译: 1
|
|
1141
|
+
},
|
|
1142
|
+
'---',
|
|
1143
|
+
{
|
|
1144
|
+
opcode: 'setdepend',
|
|
1145
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1146
|
+
text: await t('设置文件头部引用 [depend]'),
|
|
1147
|
+
直接编译: 1,
|
|
1148
|
+
arguments: {
|
|
1149
|
+
depend: {
|
|
1150
|
+
type: Scratch.ArgumentType.STRING,
|
|
1151
|
+
defaultText: ''
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
opcode: 'setlibrary',
|
|
1157
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1158
|
+
text: await t('设置引用 [library]'),
|
|
1159
|
+
直接编译: 1,
|
|
1160
|
+
arguments: {
|
|
1161
|
+
library: {
|
|
1162
|
+
type: Scratch.ArgumentType.STRING,
|
|
1163
|
+
defaultText: ''
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
},
|
|
1167
|
+
'---',
|
|
1168
|
+
{
|
|
1169
|
+
opcode: 'compilerversion',
|
|
1170
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1171
|
+
text: await t('编译器版本'),
|
|
1172
|
+
disableMonitor: 1
|
|
1173
|
+
},
|
|
1174
|
+
'---',
|
|
1175
|
+
{
|
|
1176
|
+
opcode: 'ignore',
|
|
1177
|
+
blockType: Scratch.BlockType.CONDITIONAL,
|
|
1178
|
+
text: await t('不编译'),
|
|
1179
|
+
branchCount: 1
|
|
1180
|
+
},
|
|
1181
|
+
'---',
|
|
1182
|
+
{
|
|
1183
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1184
|
+
text: await t('区域变量')
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
opcode: 'varcreate',
|
|
1188
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1189
|
+
text: await t('创建变量 [var]'),
|
|
1190
|
+
arguments: {
|
|
1191
|
+
var: {
|
|
1192
|
+
type: Scratch.ArgumentType.STRING,
|
|
1193
|
+
defaultText: ''
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
{
|
|
1198
|
+
opcode: 'varset',
|
|
1199
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1200
|
+
text: await t('设置 [var] 为 [thing]'),
|
|
1201
|
+
arguments: {
|
|
1202
|
+
var: {
|
|
1203
|
+
type: Scratch.ArgumentType.STRING,
|
|
1204
|
+
defaultText: ''
|
|
1205
|
+
},
|
|
1206
|
+
thing: {
|
|
1207
|
+
type: Scratch.ArgumentType.STRING,
|
|
1208
|
+
defaultText: ''
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
opcode: 'varget',
|
|
1214
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1215
|
+
text: await t('变量 [var]'),
|
|
1216
|
+
直接编译: 1,
|
|
1217
|
+
arguments: {
|
|
1218
|
+
var: {
|
|
1219
|
+
type: Scratch.ArgumentType.STRING,
|
|
1220
|
+
defaultText: ''
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
},
|
|
1224
|
+
'---',
|
|
1225
|
+
{
|
|
1226
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1227
|
+
text: await t('作用域')
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
opcode: 'setruntime',
|
|
1231
|
+
blockType: Scratch.BlockType.CONDITIONAL,
|
|
1232
|
+
text: await t('全局'),
|
|
1233
|
+
branchCount: 1,
|
|
1234
|
+
全局: 1
|
|
1235
|
+
},
|
|
1236
|
+
{
|
|
1237
|
+
opcode: 'setmain',
|
|
1238
|
+
blockType: Scratch.BlockType.CONDITIONAL,
|
|
1239
|
+
text: await t('主函数内'),
|
|
1240
|
+
branchCount: 1,
|
|
1241
|
+
全局: 1
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
opcode: 'setinuse',
|
|
1245
|
+
blockType: Scratch.BlockType.CONDITIONAL,
|
|
1246
|
+
text: await t('编译空间'),
|
|
1247
|
+
branchCount: 1
|
|
1248
|
+
},
|
|
1249
|
+
'---',
|
|
1250
|
+
{
|
|
1251
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1252
|
+
text: await t('类型')
|
|
1253
|
+
},
|
|
1254
|
+
{
|
|
1255
|
+
opcode: 'typeas',
|
|
1256
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1257
|
+
text: await t('[thing] 作为 [type]'),
|
|
1258
|
+
arguments: {
|
|
1259
|
+
thing: {
|
|
1260
|
+
type: Scratch.ArgumentType.STRING,
|
|
1261
|
+
defaultText: ''
|
|
1262
|
+
},
|
|
1263
|
+
type: {
|
|
1264
|
+
type: Scratch.ArgumentType.STRING,
|
|
1265
|
+
menu: 'types'
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
opcode: 'typeis',
|
|
1271
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1272
|
+
text: await t('断言 [thing] 是 [type]'),
|
|
1273
|
+
arguments: {
|
|
1274
|
+
thing: {
|
|
1275
|
+
type: Scratch.ArgumentType.STRING,
|
|
1276
|
+
defaultText: ''
|
|
1277
|
+
},
|
|
1278
|
+
type: {
|
|
1279
|
+
type: Scratch.ArgumentType.STRING,
|
|
1280
|
+
menu: 'types'
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
'---',
|
|
1285
|
+
{
|
|
1286
|
+
opcode: 'typechoose',
|
|
1287
|
+
blockType: Scratch.BlockType.BOOLEAN,
|
|
1288
|
+
text: await t('[thing] 是 [type] ?'),
|
|
1289
|
+
arguments: {
|
|
1290
|
+
thing: {
|
|
1291
|
+
type: Scratch.ArgumentType.STRING,
|
|
1292
|
+
defaultText: ''
|
|
1293
|
+
},
|
|
1294
|
+
type: {
|
|
1295
|
+
type: Scratch.ArgumentType.STRING,
|
|
1296
|
+
defaultText: ''
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
},
|
|
1300
|
+
{
|
|
1301
|
+
opcode: 'typeof',
|
|
1302
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1303
|
+
text: await t('[thing] 的类型'),
|
|
1304
|
+
arguments: {
|
|
1305
|
+
thing: {
|
|
1306
|
+
type: Scratch.ArgumentType.STRING,
|
|
1307
|
+
defaultText: ''
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
},
|
|
1311
|
+
'---',
|
|
1312
|
+
{
|
|
1313
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1314
|
+
text: await t('更多')
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
opcode: 'cloneandwait',
|
|
1318
|
+
blockType: Scratch.BlockType.COMMAND,
|
|
1319
|
+
text: await t('克隆 [CLONE_OPTION] 并等待'),
|
|
1320
|
+
hideFromPalette: 1,
|
|
1321
|
+
arguments: {
|
|
1322
|
+
CLONE_OPTION: {
|
|
1323
|
+
type: Scratch.ArgumentType.STRING,
|
|
1324
|
+
defaultText: ''
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
},
|
|
1328
|
+
{
|
|
1329
|
+
blockType: Scratch.BlockType.XML,
|
|
1330
|
+
xml: `
|
|
1331
|
+
<block type="rcompiler_cloneandwait">
|
|
1332
|
+
<value name="CLONE_OPTION">
|
|
1333
|
+
<shadow type="control_create_clone_of_menu" />
|
|
1334
|
+
</value>
|
|
1335
|
+
</block>`,
|
|
1336
|
+
},
|
|
1337
|
+
'---',
|
|
1338
|
+
{
|
|
1339
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1340
|
+
text: await t('直接使用编译器')
|
|
1341
|
+
},
|
|
1342
|
+
ifcompilerload
|
|
1343
|
+
?
|
|
1344
|
+
{
|
|
1345
|
+
opcode: 'compilenow',
|
|
1346
|
+
blockType: Scratch.BlockType.REPORTER,
|
|
1347
|
+
text: await t('此Project的编译结果')
|
|
1348
|
+
}
|
|
1349
|
+
:
|
|
1350
|
+
{
|
|
1351
|
+
blockType: Scratch.BlockType.LABEL,
|
|
1352
|
+
text: await t('当前状态编译器不可用')
|
|
1353
|
+
},
|
|
1354
|
+
];
|
|
1355
|
+
name = await t('编译器');
|
|
1356
|
+
menus = {
|
|
1357
|
+
argtypes: {
|
|
1358
|
+
items: [
|
|
1359
|
+
{
|
|
1360
|
+
text: await t('数字或字符串'),
|
|
1361
|
+
value: '数字或字符串'
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
text: await t('布尔值'),
|
|
1365
|
+
value: '布尔值'
|
|
1366
|
+
}
|
|
1367
|
+
]
|
|
1368
|
+
},
|
|
1369
|
+
types: ['Num', 'Usize', 'i32', 'Str', 'Stri', 'Stu'],
|
|
1370
|
+
newblocktype: {
|
|
1371
|
+
items: [
|
|
1372
|
+
{
|
|
1373
|
+
text: await t('输入块'),
|
|
1374
|
+
value: '输入块'
|
|
1375
|
+
},
|
|
1376
|
+
{
|
|
1377
|
+
text: await t('流程块'),
|
|
1378
|
+
value: '流程块'
|
|
1379
|
+
}
|
|
1380
|
+
]
|
|
1381
|
+
},
|
|
1382
|
+
newblockstartornot: {
|
|
1383
|
+
items: [
|
|
1384
|
+
{
|
|
1385
|
+
text: await t('正常'),
|
|
1386
|
+
value: '正常'
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
text: await t('启动'),
|
|
1390
|
+
value: '启动'
|
|
1391
|
+
}
|
|
1392
|
+
]
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
Scratch.extensions.register(new rcompilerHelper());
|
|
1396
|
+
}
|