-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathccw-approved-ext.js
314 lines (299 loc) · 8.32 KB
/
ccw-approved-ext.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import Cast from '../utils/cast.js'
// import cover from './assets/icon.svg'
// import icon from './assets/icon.svg'
class ArkosExtensions {
constructor(runtime) {
this.runtime = runtime
this._formatMessage = runtime.getFormatMessage({
'zh-cn': {
'ArkosExt.extensionName': 'Arkosの拓展',
'ArkosExt.stringEquality': '(区分大小写)[ONE]=[TWO]',
'ArkosExt.directionFromAtoB': '点x1:[X1]y1:[Y1]朝向点x2:[X2]y2:[Y2]的方向',
'ArkosExt.differenceBetweenDirections': '由方向1[a]到方向2[b]的角度差',
'ArkosExt.distance': '点x1:[X1]y1:[Y1]到点x2:[X2]y2:[Y2]的距离',
'ArkosExt.searchString': '在[str]中查找[substr]的位置(从位置[pos]开始找)',
'ArkosExt.insertString': '在[str]的第[pos]个字符前插入[substr]',
'ArkosExt.replaceString': '将[str]中的第[start]个到第[end]个字符,替换为[substr]',
},
en: {
'ArkosExt.extensionName': "Arkos' Extensions",
'ArkosExt.stringEquality': '(case sensitive)[ONE]=[TWO]',
'ArkosExt.directionFromAtoB': 'direction from x1:[X1]y1:[Y1]to x2:[X2]y2:[Y2]',
'ArkosExt.differenceBetweenDirections': 'direction[b] minus direction[a]',
'ArkosExt.distance': 'distance between x1:[X1]y1:[Y1]and x2:[X2]y2:[Y2]',
'ArkosExt.searchString': 'position of[substr]in[str],start from[pos]',
'ArkosExt.insertString': 'insert[substr]at[pos]of[str]',
'ArkosExt.replaceString': 'replace from[start]to[end]of[str],with[substr]',
},
})
}
formatMessage(id) {
return this._formatMessage({
id,
default: id,
description: id,
})
}
getInfo() {
return {
id: 'hcnTest', // 拓展id
name: this.formatMessage('ArkosExt.extensionName'), // 拓展名
color1: '#FF8383',
// menuIconURI: icon,
// blockIconURI: icon,
blocks: [
{
// 判断相等(区分大小写)
opcode: 'strictlyEquals',
blockType: 'Boolean',
text: this.formatMessage('ArkosExt.stringEquality'),
arguments: {
ONE: {
type: 'string',
defaultValue: 'A',
},
TWO: {
type: 'string',
defaultValue: 'a',
},
},
},
{
// 计算点A到点B的方向
opcode: 'getDirFromAToB',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.directionFromAtoB'),
arguments: {
X1: {
type: 'number',
defaultValue: 0,
},
Y1: {
type: 'number',
defaultValue: 0,
},
X2: {
type: 'number',
defaultValue: 0,
},
Y2: {
type: 'number',
defaultValue: 0,
},
},
},
{
// 计算角b-角a的角度差
opcode: 'differenceBetweenDirections',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.differenceBetweenDirections'),
arguments: {
a: {
type: 'number',
defaultValue: 0,
},
b: {
type: 'number',
defaultValue: 0,
},
},
},
{
// 两点距离
opcode: 'disFromAToB',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.distance'),
arguments: {
X1: {
type: 'number',
defaultValue: 0,
},
Y1: {
type: 'number',
defaultValue: 0,
},
X2: {
type: 'number',
defaultValue: 0,
},
Y2: {
type: 'number',
defaultValue: 0,
},
},
},
{
// 查找子字符串,从pos开始
opcode: 'indexof',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.searchString'),
arguments: {
str: {
type: 'string',
defaultValue: 'banana',
},
substr: {
type: 'string',
defaultValue: 'na',
},
pos: {
type: 'number',
defaultValue: 1,
},
},
},
{
// 在字符串中插入子字符串
opcode: 'insertStr',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.insertString'),
arguments: {
str: {
type: 'string',
defaultValue: 'ac',
},
substr: {
type: 'string',
defaultValue: 'b',
},
pos: {
type: 'number',
defaultValue: 2,
},
},
},
{
// 替换字符串中的从..到..的字符串
opcode: 'replaceStr',
blockType: 'reporter',
text: this.formatMessage('ArkosExt.replaceString'),
arguments: {
str: {
type: 'string',
defaultValue: 'ABCDEF',
},
substr: {
type: 'string',
defaultValue: 'XX',
},
start: {
type: 'number',
defaultValue: 3,
},
end: {
type: 'number',
defaultValue: 4,
},
},
},
{
//朝..方向旋转..角度
opcode: 'turnDegreesToDir',
blockType: 'command',
text: 'turn[degree]degrees toward direction[dir]',
arguments: {
degree: {
type: 'number',
defaultValue: 0,
},
dir: {
type: 'angle',
defaultValue: 0,
},
},
},
],
}
}
strictlyEquals(args) {
// Note strict equality: Inputs must match exactly: in type, case, etc.
return args.ONE === args.TWO
}
numGreaterThen(args) {
return args.ONE > args.TWO
}
getDirFromAToB(args) {
const { X1, X2, Y1, Y2 } = args
let a = (Math.atan((X2 - X1) / (Y2 - Y1)) / Math.PI) * 180.0
if (Y1 < Y2) return a
if (Y1 > Y2) {
a += 180
if (a > 180.0) a -= 360.0
return a
}
if (X2 > X1) return 90
if (X2 < X1) return -90
return NaN
}
differenceBetweenDirections(args) {
const { a, b } = args
let dif = (b - a) % 360
if (dif > 180) dif -= 360
return dif
}
disFromAToB(args) {
const { X1, X2, Y1, Y2 } = args
return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2))
}
indexof(args) {
const str = Cast.toString(args.str)
const substr = Cast.toString(args.substr)
const a = str.indexOf(substr, args.pos - 1)
if (a === -1) {
return ''
}
return a + 1
}
insertStr(args) {
const str = Cast.toString(args.str)
const substr = Cast.toString(args.substr)
let pos = args.pos - 1
if (pos < 0) {
pos = 0
}
return str.slice(0, pos) + substr + str.slice(pos)
}
replaceStr(args) {
const str = Cast.toString(args.str)
const substr = Cast.toString(args.substr)
let start = Cast.toNumber(args.start)
let end = Cast.toNumber(args.end)
if (start > end) {
const t = end
end = start
start = t
}
if (start < 1) start = 1
return str.slice(0, start - 1) + substr + str.slice(end)
}
turnDegreesToDir(args, util) {
//
// util.target.setDirection(util.target.direction + degrees);
console.log('---util-------------\n', util)
console.log('---args-------------\n', args)
console.log('---runtime-------------\n', this.runtime)
}
}
window.tempExt = {
Extension: ArkosExtensions,
info: {
name: 'hcn.extensionName',
description: 'hcn.description',
extensionId: 'hcnTest',
// iconURL: icon,
// insetIconURL: cover,
featured: true,
disabled: false,
collaborator: 'only for hcn test',
},
l10n: {
'zh-cn': {
'hcn.extensionName': 'hcn 的测试',
'hcn.description': 'hcn 的测试',
},
en: {
'hcn.extensionName': 'hcn test',
'hcn.description': 'hcn test',
},
},
}