keystonemc 1.0.0 → 1.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/dist/core/event/eventManager.d.ts +33 -0
- package/dist/core/event/flow.d.ts +18 -0
- package/dist/core/event/priority.d.ts +8 -0
- package/dist/core/event/types.d.ts +6 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/keystone.d.ts +5 -0
- package/dist/core/math/axisAlignedBB.d.ts +114 -0
- package/dist/core/math/vector3.d.ts +225 -0
- package/dist/core/timer/timer.d.ts +94 -0
- package/dist/core/utils/debugger.d.ts +1 -0
- package/dist/index.js +988 -0
- package/dist/vite-plugin/index.d.ts +11 -0
- package/dist/vite-plugin/index.js +120 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,988 @@
|
|
|
1
|
+
import { world, system } from "@minecraft/server";
|
|
2
|
+
class Keystone {
|
|
3
|
+
constructor() {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
const keystone = new Keystone();
|
|
7
|
+
class Vector3 {
|
|
8
|
+
constructor(x, y, z) {
|
|
9
|
+
this.x = x;
|
|
10
|
+
this.y = y;
|
|
11
|
+
this.z = z;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* ゼロベクトルで生成
|
|
15
|
+
* @return {Vector3}
|
|
16
|
+
*/
|
|
17
|
+
static zero() {
|
|
18
|
+
return new Vector3(0, 0, 0);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* {x, y, z} オブジェクトから生成
|
|
22
|
+
* @param pos
|
|
23
|
+
* @returns {Vector3}
|
|
24
|
+
*/
|
|
25
|
+
static fromBDS(pos) {
|
|
26
|
+
return new Vector3(pos.x, pos.y, pos.z);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* x
|
|
30
|
+
* @returns {number}
|
|
31
|
+
*/
|
|
32
|
+
getX() {
|
|
33
|
+
return this.x;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* y
|
|
37
|
+
* @returns {number}
|
|
38
|
+
*/
|
|
39
|
+
getY() {
|
|
40
|
+
return this.y;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* z
|
|
44
|
+
* @returns {number}
|
|
45
|
+
*/
|
|
46
|
+
getZ() {
|
|
47
|
+
return this.z;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* x (整数値)
|
|
51
|
+
* @returns {number}
|
|
52
|
+
*/
|
|
53
|
+
getFloorX() {
|
|
54
|
+
return Math.floor(this.x);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* y (整数値)
|
|
58
|
+
* @returns {number}
|
|
59
|
+
*/
|
|
60
|
+
getFloorY() {
|
|
61
|
+
return Math.floor(this.y);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* z (整数値)
|
|
65
|
+
* @returns {number}
|
|
66
|
+
*/
|
|
67
|
+
getFloorZ() {
|
|
68
|
+
return Math.floor(this.z);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 加算
|
|
72
|
+
* @param x
|
|
73
|
+
* @param y
|
|
74
|
+
* @param z
|
|
75
|
+
* @return {Vector3}
|
|
76
|
+
*/
|
|
77
|
+
add(x, y, z) {
|
|
78
|
+
return new Vector3(
|
|
79
|
+
this.x + x,
|
|
80
|
+
this.y + y,
|
|
81
|
+
this.z + z
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* ベクトル単位での加算
|
|
86
|
+
* @param v
|
|
87
|
+
* @returns {Vector3}
|
|
88
|
+
*/
|
|
89
|
+
addVector(v) {
|
|
90
|
+
return this.add(v.x, v.y, v.z);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 減算
|
|
94
|
+
* @param x
|
|
95
|
+
* @param y
|
|
96
|
+
* @param z
|
|
97
|
+
* @return {Vector3}
|
|
98
|
+
*/
|
|
99
|
+
subtract(x, y, z) {
|
|
100
|
+
return this.add(-x, -y, -z);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* ベクトル単位での減算
|
|
104
|
+
* @param v
|
|
105
|
+
* @return {Vector3}
|
|
106
|
+
*/
|
|
107
|
+
subtractVector(v) {
|
|
108
|
+
return this.add(-v.x, -v.y, -v.z);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 乗算
|
|
112
|
+
* @param value
|
|
113
|
+
* @return {Vector3}
|
|
114
|
+
*/
|
|
115
|
+
multiply(value) {
|
|
116
|
+
return new Vector3(
|
|
117
|
+
this.x * value,
|
|
118
|
+
this.y * value,
|
|
119
|
+
this.z * value
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 除算
|
|
124
|
+
* @param value
|
|
125
|
+
* @return {Vector3}
|
|
126
|
+
*/
|
|
127
|
+
divide(value) {
|
|
128
|
+
return new Vector3(
|
|
129
|
+
this.x / value,
|
|
130
|
+
this.y / value,
|
|
131
|
+
this.z / value
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* ベクトルの内部数値小数点切り上げ
|
|
136
|
+
* @return {Vector3}
|
|
137
|
+
*/
|
|
138
|
+
ceil() {
|
|
139
|
+
return new Vector3(
|
|
140
|
+
Math.ceil(this.x),
|
|
141
|
+
Math.ceil(this.y),
|
|
142
|
+
Math.ceil(this.z)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* ベクトルの内部数値小数点切り捨て
|
|
147
|
+
* @return {Vector3}
|
|
148
|
+
*/
|
|
149
|
+
floor() {
|
|
150
|
+
return new Vector3(
|
|
151
|
+
Math.floor(this.x),
|
|
152
|
+
Math.floor(this.y),
|
|
153
|
+
Math.floor(this.z)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* ベクトルの内部数値小数点四捨五入
|
|
158
|
+
* @param precision
|
|
159
|
+
* @return {Vector3}
|
|
160
|
+
*/
|
|
161
|
+
round(precision = 0) {
|
|
162
|
+
const factor = Math.pow(10, precision);
|
|
163
|
+
return new Vector3(
|
|
164
|
+
Math.round(this.x * factor) / factor,
|
|
165
|
+
Math.round(this.y * factor) / factor,
|
|
166
|
+
Math.round(this.z * factor) / factor
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* ベクトルの内部数値の絶対値
|
|
171
|
+
* @return {Vector3}
|
|
172
|
+
*/
|
|
173
|
+
abs() {
|
|
174
|
+
return new Vector3(
|
|
175
|
+
Math.abs(this.x),
|
|
176
|
+
Math.abs(this.y),
|
|
177
|
+
Math.abs(this.z)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* 指定した2点間のユークリッド距離
|
|
182
|
+
* @param pos
|
|
183
|
+
* @return {number}
|
|
184
|
+
*/
|
|
185
|
+
distance(pos) {
|
|
186
|
+
return Math.sqrt(this.distanceSquared(pos));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 指定した2点間のユークリッド距離の2乗
|
|
190
|
+
* @param pos
|
|
191
|
+
* @return {number}
|
|
192
|
+
*/
|
|
193
|
+
distanceSquared(pos) {
|
|
194
|
+
const dx = this.x - pos.x;
|
|
195
|
+
const dy = this.y - pos.y;
|
|
196
|
+
const dz = this.z - pos.z;
|
|
197
|
+
return dx * dx + dy * dy + dz * dz;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 内積
|
|
201
|
+
* @param pos
|
|
202
|
+
* @return {number}
|
|
203
|
+
*/
|
|
204
|
+
dot(pos) {
|
|
205
|
+
return this.x * pos.x + this.y * pos.y + this.z * pos.z;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* 外積
|
|
209
|
+
* @param pos
|
|
210
|
+
* @return {Vector3}
|
|
211
|
+
*/
|
|
212
|
+
cross(pos) {
|
|
213
|
+
return new Vector3(
|
|
214
|
+
this.y * pos.z - this.z * pos.y,
|
|
215
|
+
this.z * pos.x - this.x * pos.z,
|
|
216
|
+
this.x * pos.y - this.y * pos.x
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* ベクトルの比較
|
|
221
|
+
* @param pos
|
|
222
|
+
* @return {boolean}
|
|
223
|
+
*/
|
|
224
|
+
equals(pos) {
|
|
225
|
+
return this.x === pos.x && this.y === pos.y && this.z === pos.z;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* ベクトルの長さ
|
|
229
|
+
* @return {number}
|
|
230
|
+
*/
|
|
231
|
+
length() {
|
|
232
|
+
return Math.sqrt(this.lengthSquared());
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* ベクトルの長さの2乗
|
|
236
|
+
* @return {number}
|
|
237
|
+
*/
|
|
238
|
+
lengthSquared() {
|
|
239
|
+
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* 正規化
|
|
243
|
+
* @return {Vector3}
|
|
244
|
+
*/
|
|
245
|
+
normalize() {
|
|
246
|
+
const len = this.length();
|
|
247
|
+
if (len > 0) {
|
|
248
|
+
return this.divide(len);
|
|
249
|
+
}
|
|
250
|
+
return new Vector3(0, 0, 0);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* オブジェクトの数値指定再生成
|
|
254
|
+
* @param x
|
|
255
|
+
* @param y
|
|
256
|
+
* @param z
|
|
257
|
+
* @return {Vector3}
|
|
258
|
+
*/
|
|
259
|
+
withComponents(x, y, z) {
|
|
260
|
+
return new Vector3(
|
|
261
|
+
x !== void 0 ? x : this.x,
|
|
262
|
+
y !== void 0 ? y : this.y,
|
|
263
|
+
z !== void 0 ? z : this.z
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* X座標をxValueにしたとき線分上に存在する点を返す
|
|
268
|
+
* @param end 終点
|
|
269
|
+
* @param xValue 途中点のX値
|
|
270
|
+
* @returns {Vector3|undefined}
|
|
271
|
+
*/
|
|
272
|
+
getIntermediateWithXValue(end, xValue) {
|
|
273
|
+
const dx = end.x - this.x;
|
|
274
|
+
if (dx === 0) return;
|
|
275
|
+
const t = (xValue - this.x) / dx;
|
|
276
|
+
if (t < 0 || t > 1) return;
|
|
277
|
+
return new Vector3(
|
|
278
|
+
this.x + dx * t,
|
|
279
|
+
this.y + (end.y - this.y) * t,
|
|
280
|
+
this.z + (end.z - this.z) * t
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Y座標をyValueにしたとき線分上に存在する点を返す
|
|
285
|
+
* @param end 終点
|
|
286
|
+
* @param yValue 途中点のY値
|
|
287
|
+
* @returns {Vector3|undefined}
|
|
288
|
+
*/
|
|
289
|
+
getIntermediateWithYValue(end, yValue) {
|
|
290
|
+
const dy = end.y - this.y;
|
|
291
|
+
if (dy === 0) return;
|
|
292
|
+
const t = (yValue - this.y) / dy;
|
|
293
|
+
if (t < 0 || t > 1) return;
|
|
294
|
+
return new Vector3(
|
|
295
|
+
this.x + (end.x - this.x) * t,
|
|
296
|
+
this.y + dy * t,
|
|
297
|
+
this.z + (end.z - this.z) * t
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Z座標をzValueにしたとき線分上に存在する点を返す
|
|
302
|
+
* @param end 終点
|
|
303
|
+
* @param zValue 途中点のZ値
|
|
304
|
+
* @returns {Vector3|undefined}
|
|
305
|
+
*/
|
|
306
|
+
getIntermediateWithZValue(end, zValue) {
|
|
307
|
+
const dz = end.z - this.z;
|
|
308
|
+
if (dz === 0) return;
|
|
309
|
+
const t = (zValue - this.z) / dz;
|
|
310
|
+
if (t < 0 || t > 1) return;
|
|
311
|
+
return new Vector3(
|
|
312
|
+
this.x + (end.x - this.x) * t,
|
|
313
|
+
this.y + (end.y - this.y) * t,
|
|
314
|
+
this.z + dz * t
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* BDS ScriptAPIで使える {x, y, z} 形式に変換
|
|
319
|
+
* @returns {_Vector3}
|
|
320
|
+
*/
|
|
321
|
+
toBDS() {
|
|
322
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* オブジェクトに変換
|
|
326
|
+
*/
|
|
327
|
+
toObject() {
|
|
328
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* toString
|
|
332
|
+
* @returns {string}
|
|
333
|
+
*/
|
|
334
|
+
toString() {
|
|
335
|
+
return `_Vector3(x=${this.x}, y=${this.y}, z=${this.z})`;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* 最大点
|
|
339
|
+
* @param vector
|
|
340
|
+
* @param vectors
|
|
341
|
+
* @returns {Vector3}
|
|
342
|
+
*/
|
|
343
|
+
static maxComponents(vector, ...vectors) {
|
|
344
|
+
let x = vector.x;
|
|
345
|
+
let y = vector.y;
|
|
346
|
+
let z = vector.z;
|
|
347
|
+
for (const pos of vectors) {
|
|
348
|
+
x = Math.max(x, pos.x);
|
|
349
|
+
y = Math.max(y, pos.y);
|
|
350
|
+
z = Math.max(z, pos.z);
|
|
351
|
+
}
|
|
352
|
+
return new Vector3(x, y, z);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* 最小点
|
|
356
|
+
* @param vector
|
|
357
|
+
* @param vectors
|
|
358
|
+
* @returns {Vector3}
|
|
359
|
+
*/
|
|
360
|
+
static minComponents(vector, ...vectors) {
|
|
361
|
+
let x = vector.x;
|
|
362
|
+
let y = vector.y;
|
|
363
|
+
let z = vector.z;
|
|
364
|
+
for (const pos of vectors) {
|
|
365
|
+
x = Math.min(x, pos.x);
|
|
366
|
+
y = Math.min(y, pos.y);
|
|
367
|
+
z = Math.min(z, pos.z);
|
|
368
|
+
}
|
|
369
|
+
return new Vector3(x, y, z);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* 合計
|
|
373
|
+
* @param vectors
|
|
374
|
+
* @returns {Vector3}
|
|
375
|
+
*/
|
|
376
|
+
static sum(...vectors) {
|
|
377
|
+
let x = 0, y = 0, z = 0;
|
|
378
|
+
for (const v of vectors) {
|
|
379
|
+
x += v.x;
|
|
380
|
+
y += v.y;
|
|
381
|
+
z += v.z;
|
|
382
|
+
}
|
|
383
|
+
return new Vector3(x, y, z);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
class AxisAlignedBB {
|
|
387
|
+
constructor(center, extent) {
|
|
388
|
+
this.center = center;
|
|
389
|
+
this.extent = extent;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 最小点最大点からオブジェクト化
|
|
393
|
+
* @param min
|
|
394
|
+
* @param max
|
|
395
|
+
* @returns {AxisAlignedBB}
|
|
396
|
+
*/
|
|
397
|
+
static fromMinMax(min, max) {
|
|
398
|
+
return new AxisAlignedBB(
|
|
399
|
+
{
|
|
400
|
+
x: (min.x + max.x) / 2,
|
|
401
|
+
y: (min.y + max.y) / 2,
|
|
402
|
+
z: (min.z + max.z) / 2
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
x: (max.x - min.x) / 2,
|
|
406
|
+
y: (max.y - min.y) / 2,
|
|
407
|
+
z: (max.z - min.z) / 2
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* 大きさ1のAABB生成
|
|
413
|
+
* @returns {AxisAlignedBB}
|
|
414
|
+
*/
|
|
415
|
+
static one() {
|
|
416
|
+
return AxisAlignedBB.fromMinMax(
|
|
417
|
+
{ x: 0, y: 0, z: 0 },
|
|
418
|
+
{ x: 1, y: 1, z: 1 }
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* {center, extent} オブジェクトから生成
|
|
423
|
+
* @param aabb
|
|
424
|
+
* @returns {AxisAlignedBB}
|
|
425
|
+
*/
|
|
426
|
+
static fromBDS(aabb) {
|
|
427
|
+
return new AxisAlignedBB(aabb.center, aabb.extent);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* 最小点
|
|
431
|
+
* @returns {Vector3}
|
|
432
|
+
*/
|
|
433
|
+
get min() {
|
|
434
|
+
return {
|
|
435
|
+
x: this.center.x - this.extent.x,
|
|
436
|
+
y: this.center.y - this.extent.y,
|
|
437
|
+
z: this.center.z - this.extent.z
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* 最大点
|
|
442
|
+
* @returns {Vector3}
|
|
443
|
+
*/
|
|
444
|
+
get max() {
|
|
445
|
+
return {
|
|
446
|
+
x: this.center.x + this.extent.x,
|
|
447
|
+
y: this.center.y + this.extent.y,
|
|
448
|
+
z: this.center.z + this.extent.z
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* オフセット
|
|
453
|
+
* @param dx
|
|
454
|
+
* @param dy
|
|
455
|
+
* @param dz
|
|
456
|
+
* @returns {AxisAlignedBB}
|
|
457
|
+
*/
|
|
458
|
+
offset(dx, dy, dz) {
|
|
459
|
+
return new AxisAlignedBB(
|
|
460
|
+
{ x: this.center.x + dx, y: this.center.y + dy, z: this.center.z + dz },
|
|
461
|
+
this.extent
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* 拡大
|
|
466
|
+
* @param dx
|
|
467
|
+
* @param dy
|
|
468
|
+
* @param dz
|
|
469
|
+
* @returns {AxisAlignedBB}
|
|
470
|
+
*/
|
|
471
|
+
expand(dx, dy, dz) {
|
|
472
|
+
return new AxisAlignedBB(
|
|
473
|
+
this.center,
|
|
474
|
+
{
|
|
475
|
+
x: this.extent.x + dx,
|
|
476
|
+
y: this.extent.y + dy,
|
|
477
|
+
z: this.extent.z + dz
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* 縮小
|
|
483
|
+
* @param dx
|
|
484
|
+
* @param dy
|
|
485
|
+
* @param dz
|
|
486
|
+
* @returns {AxisAlignedBB}
|
|
487
|
+
*/
|
|
488
|
+
contract(dx, dy, dz) {
|
|
489
|
+
return this.expand(-dx, -dy, -dz);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* 接触判定
|
|
493
|
+
* @param other
|
|
494
|
+
* @param epsilon
|
|
495
|
+
* @returns {boolean}
|
|
496
|
+
*/
|
|
497
|
+
intersects(other, epsilon = 1e-6) {
|
|
498
|
+
const aMin = this.min;
|
|
499
|
+
const aMax = this.max;
|
|
500
|
+
const bMin = other.min;
|
|
501
|
+
const bMax = other.max;
|
|
502
|
+
return bMax.x - aMin.x > epsilon && aMax.x - bMin.x > epsilon && bMax.y - aMin.y > epsilon && aMax.y - bMin.y > epsilon && bMax.z - aMin.z > epsilon && aMax.z - bMin.z > epsilon;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* 対象座標が内包されているか
|
|
506
|
+
* @param v
|
|
507
|
+
* @returns {boolean}
|
|
508
|
+
*/
|
|
509
|
+
contains(v) {
|
|
510
|
+
const min = this.min;
|
|
511
|
+
const max = this.max;
|
|
512
|
+
return v.x > min.x && v.x < max.x && v.y > min.y && v.y < max.y && v.z > min.z && v.z < max.z;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Xの長さ
|
|
516
|
+
* @returns {number}
|
|
517
|
+
*/
|
|
518
|
+
getXLength() {
|
|
519
|
+
return this.extent.x * 2;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Yの長さ
|
|
523
|
+
* @returns {number}
|
|
524
|
+
*/
|
|
525
|
+
getYLength() {
|
|
526
|
+
return this.extent.y * 2;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Zの長さ
|
|
530
|
+
* @returns {number}
|
|
531
|
+
*/
|
|
532
|
+
getZLength() {
|
|
533
|
+
return this.extent.z * 2;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* 体積
|
|
537
|
+
* @returns {number}
|
|
538
|
+
*/
|
|
539
|
+
getVolume() {
|
|
540
|
+
return this.getXLength() * this.getYLength() * this.getZLength();
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* キューブ判定
|
|
544
|
+
* @param epsilon
|
|
545
|
+
* @returns {boolean}
|
|
546
|
+
*/
|
|
547
|
+
isCube(epsilon = 1e-6) {
|
|
548
|
+
const x = this.getXLength();
|
|
549
|
+
const y = this.getYLength();
|
|
550
|
+
const z = this.getZLength();
|
|
551
|
+
return Math.abs(x - y) < epsilon && Math.abs(y - z) < epsilon;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* BDS ScriptAPIで使える {center, extent} 形式に変換
|
|
555
|
+
* @returns {AABB}
|
|
556
|
+
*/
|
|
557
|
+
toBDS() {
|
|
558
|
+
return { center: this.center, extent: this.extent };
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* オブジェクトに変換
|
|
562
|
+
*/
|
|
563
|
+
toObject() {
|
|
564
|
+
return { center: this.center, extent: this.extent };
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* toString
|
|
568
|
+
* @returns {string}
|
|
569
|
+
*/
|
|
570
|
+
toString() {
|
|
571
|
+
return `AxisAlignedBB{center=(${this.center.x}, ${this.center.y}, ${this.center.z}), extent=(${this.center.x}, ${this.center.y}, ${this.center.z})}`;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
var Priority = /* @__PURE__ */ ((Priority2) => {
|
|
575
|
+
Priority2[Priority2["LOWEST"] = 5] = "LOWEST";
|
|
576
|
+
Priority2[Priority2["LOW"] = 4] = "LOW";
|
|
577
|
+
Priority2[Priority2["NORMAL"] = 3] = "NORMAL";
|
|
578
|
+
Priority2[Priority2["HIGH"] = 2] = "HIGH";
|
|
579
|
+
Priority2[Priority2["HIGHEST"] = 1] = "HIGHEST";
|
|
580
|
+
Priority2[Priority2["MONITOR"] = 0] = "MONITOR";
|
|
581
|
+
return Priority2;
|
|
582
|
+
})(Priority || {});
|
|
583
|
+
const _EventManager = class _EventManager {
|
|
584
|
+
/** init: world.beforeEvents / world.afterEvents を全自動で subscribe して dispatch に流す */
|
|
585
|
+
static initialize() {
|
|
586
|
+
for (const name in world.afterEvents) {
|
|
587
|
+
world.afterEvents[name].subscribe((ev) => {
|
|
588
|
+
_EventManager.dispatchAfter(name, ev);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
for (const name in world.beforeEvents) {
|
|
592
|
+
world.beforeEvents[name].subscribe((ev) => {
|
|
593
|
+
_EventManager.dispatchBefore(name, ev);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
// ---------- register ----------
|
|
598
|
+
static registerAfter(eventName, listener) {
|
|
599
|
+
if (!this.afterListeners[eventName]) {
|
|
600
|
+
this.afterListeners[eventName] = [];
|
|
601
|
+
}
|
|
602
|
+
const arr = this.afterListeners[eventName];
|
|
603
|
+
arr.push(listener);
|
|
604
|
+
arr.sort((a, b) => (b.priority ?? Priority.NORMAL) - (a.priority ?? Priority.NORMAL));
|
|
605
|
+
}
|
|
606
|
+
static registerBefore(eventName, listener) {
|
|
607
|
+
if (!this.beforeListeners[eventName]) {
|
|
608
|
+
this.beforeListeners[eventName] = [];
|
|
609
|
+
}
|
|
610
|
+
const arr = this.beforeListeners[eventName];
|
|
611
|
+
arr.push(listener);
|
|
612
|
+
arr.sort((a, b) => (b.priority ?? Priority.NORMAL) - (a.priority ?? Priority.NORMAL));
|
|
613
|
+
}
|
|
614
|
+
// ---------- dispatch ----------
|
|
615
|
+
static dispatchAfter(eventName, event) {
|
|
616
|
+
const arr = this.afterListeners[eventName];
|
|
617
|
+
if (!arr) return;
|
|
618
|
+
for (const listener of arr) {
|
|
619
|
+
try {
|
|
620
|
+
listener.handler(event);
|
|
621
|
+
} catch (e) {
|
|
622
|
+
console.error(`[EventManager] after:${String(eventName)} handler threw:`, e);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
static dispatchBefore(eventName, event) {
|
|
627
|
+
const arr = this.beforeListeners[eventName];
|
|
628
|
+
if (!arr) return;
|
|
629
|
+
for (const listener of arr) {
|
|
630
|
+
try {
|
|
631
|
+
listener.handler(event);
|
|
632
|
+
} catch (e) {
|
|
633
|
+
console.error(`[EventManager] before:${String(eventName)} handler threw:`, e);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
// ---------- utility ----------
|
|
638
|
+
/** 登録済みリスナーを全部クリア(Plugin 単位で実装するなら拡張する) */
|
|
639
|
+
static clearAll() {
|
|
640
|
+
this.afterListeners = {};
|
|
641
|
+
this.beforeListeners = {};
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
_EventManager.afterListeners = {};
|
|
645
|
+
_EventManager.beforeListeners = {};
|
|
646
|
+
let EventManager = _EventManager;
|
|
647
|
+
const COLOR = {
|
|
648
|
+
reset: "\x1B[0m",
|
|
649
|
+
bold: "\x1B[1m",
|
|
650
|
+
dim: "\x1B[2m",
|
|
651
|
+
red: "\x1B[31m",
|
|
652
|
+
green: "\x1B[32m",
|
|
653
|
+
yellow: "\x1B[33m",
|
|
654
|
+
blue: "\x1B[34m",
|
|
655
|
+
magenta: "\x1B[35m",
|
|
656
|
+
cyan: "\x1B[36m",
|
|
657
|
+
white: "\x1B[37m",
|
|
658
|
+
gray: "\x1B[90m"
|
|
659
|
+
};
|
|
660
|
+
const _VLQDecoder = class _VLQDecoder {
|
|
661
|
+
static decode(str) {
|
|
662
|
+
const result = [];
|
|
663
|
+
let shift = 0;
|
|
664
|
+
let value = 0;
|
|
665
|
+
for (let i = 0; i < str.length; i++) {
|
|
666
|
+
const digit = this.BASE64_CHARS.indexOf(str[i]);
|
|
667
|
+
if (digit === -1) continue;
|
|
668
|
+
const continuation = (digit & 32) !== 0;
|
|
669
|
+
value += (digit & 31) << shift;
|
|
670
|
+
if (continuation) {
|
|
671
|
+
shift += 5;
|
|
672
|
+
} else {
|
|
673
|
+
const negative = (value & 1) !== 0;
|
|
674
|
+
value >>>= 1;
|
|
675
|
+
result.push(negative ? -value : value);
|
|
676
|
+
value = 0;
|
|
677
|
+
shift = 0;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return result;
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
_VLQDecoder.BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
684
|
+
let VLQDecoder = _VLQDecoder;
|
|
685
|
+
class SourceMapDebugger {
|
|
686
|
+
constructor() {
|
|
687
|
+
this.decodedMappings = [];
|
|
688
|
+
this.initialized = false;
|
|
689
|
+
this.initialize();
|
|
690
|
+
}
|
|
691
|
+
initialize() {
|
|
692
|
+
if (typeof globalThis.__SOURCE_MAP__ !== "undefined") {
|
|
693
|
+
this.sourceMap = globalThis.__SOURCE_MAP__;
|
|
694
|
+
this.decodeMappings();
|
|
695
|
+
this.initialized = true;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
decodeMappings() {
|
|
699
|
+
if (!this.sourceMap?.mappings) return;
|
|
700
|
+
const lines = this.sourceMap.mappings.split(";");
|
|
701
|
+
let generatedLine = 1;
|
|
702
|
+
let prevOriginalLine = 0;
|
|
703
|
+
let prevOriginalColumn = 0;
|
|
704
|
+
let prevSource = 0;
|
|
705
|
+
let prevName = 0;
|
|
706
|
+
for (const line of lines) {
|
|
707
|
+
if (!line) {
|
|
708
|
+
generatedLine++;
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
const segments = line.split(",");
|
|
712
|
+
let generatedColumn = 0;
|
|
713
|
+
for (const segment of segments) {
|
|
714
|
+
if (!segment) continue;
|
|
715
|
+
const decoded = VLQDecoder.decode(segment);
|
|
716
|
+
if (decoded.length < 1) continue;
|
|
717
|
+
generatedColumn += decoded[0];
|
|
718
|
+
const mapping = {
|
|
719
|
+
generatedLine,
|
|
720
|
+
generatedColumn,
|
|
721
|
+
originalLine: 0,
|
|
722
|
+
originalColumn: 0,
|
|
723
|
+
sourceIndex: 0
|
|
724
|
+
};
|
|
725
|
+
if (decoded.length > 1) {
|
|
726
|
+
prevSource += decoded[1];
|
|
727
|
+
mapping.sourceIndex = prevSource;
|
|
728
|
+
if (decoded.length > 2) {
|
|
729
|
+
prevOriginalLine += decoded[2];
|
|
730
|
+
mapping.originalLine = prevOriginalLine;
|
|
731
|
+
if (decoded.length > 3) {
|
|
732
|
+
prevOriginalColumn += decoded[3];
|
|
733
|
+
mapping.originalColumn = prevOriginalColumn;
|
|
734
|
+
if (decoded.length > 4) {
|
|
735
|
+
prevName += decoded[4];
|
|
736
|
+
mapping.name = this.sourceMap.names?.[prevName];
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
this.decodedMappings.push(mapping);
|
|
742
|
+
}
|
|
743
|
+
generatedLine++;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
getOriginalPosition(line, column) {
|
|
747
|
+
if (!this.initialized || this.decodedMappings.length === 0) return null;
|
|
748
|
+
let best = null;
|
|
749
|
+
let bestDistance = Infinity;
|
|
750
|
+
for (const m of this.decodedMappings) {
|
|
751
|
+
if (m.generatedLine === line) {
|
|
752
|
+
const distance = column !== void 0 ? Math.abs(m.generatedColumn - column) : 0;
|
|
753
|
+
if (distance < bestDistance) {
|
|
754
|
+
bestDistance = distance;
|
|
755
|
+
best = m;
|
|
756
|
+
}
|
|
757
|
+
} else if (m.generatedLine < line) {
|
|
758
|
+
if (!best || m.generatedLine > best.generatedLine) best = m;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (best && this.sourceMap.sources?.[best.sourceIndex]) {
|
|
762
|
+
return {
|
|
763
|
+
source: this.sourceMap.sources[best.sourceIndex],
|
|
764
|
+
line: best.originalLine,
|
|
765
|
+
column: best.originalColumn,
|
|
766
|
+
content: this.sourceMap.sourcesContent?.[best.sourceIndex],
|
|
767
|
+
name: best.name
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
debug(...args) {
|
|
773
|
+
try {
|
|
774
|
+
const err = new Error();
|
|
775
|
+
const stack = err.stack || "";
|
|
776
|
+
const stackLines = stack.split("\n");
|
|
777
|
+
const output = [];
|
|
778
|
+
output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
|
|
779
|
+
output.push(`${COLOR.bold}${COLOR.cyan}📍 DEBUG${COLOR.reset}`);
|
|
780
|
+
let position = null;
|
|
781
|
+
for (let i = 2; i < Math.min(stackLines.length, 8); i++) {
|
|
782
|
+
const line = stackLines[i];
|
|
783
|
+
console.log(JSON.stringify(line));
|
|
784
|
+
const match = /(?:\()?(?:[A-Za-z0-9._/-]+):(\d+)(?::(\d+))?\)?$/.exec(line);
|
|
785
|
+
if (match) {
|
|
786
|
+
const lineNum = parseInt(match[1]);
|
|
787
|
+
const colNum = match[2] ? parseInt(match[2]) : void 0;
|
|
788
|
+
position = this.getOriginalPosition(lineNum, colNum);
|
|
789
|
+
if (position) break;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (position) {
|
|
793
|
+
const file = position.source.replace(/^.*\//, "");
|
|
794
|
+
output.push(`${COLOR.blue}📄 ${file}:${position.line}:${position.column}${COLOR.reset}`);
|
|
795
|
+
if (position.name) output.push(`${COLOR.cyan}🏷 ${position.name}${COLOR.reset}`);
|
|
796
|
+
if (position.content) {
|
|
797
|
+
const lines = position.content.split("\n");
|
|
798
|
+
const target = position.line - 1;
|
|
799
|
+
const range = 2;
|
|
800
|
+
output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
|
|
801
|
+
for (let i = Math.max(0, target - range); i <= Math.min(lines.length - 1, target + range); i++) {
|
|
802
|
+
const num = `${(i + 1).toString().padStart(3, " ")}`;
|
|
803
|
+
const content = lines[i];
|
|
804
|
+
if (i === target) {
|
|
805
|
+
output.push(`${COLOR.red}${COLOR.bold}→ ${num}: ${COLOR.white}${content}${COLOR.reset}`);
|
|
806
|
+
} else {
|
|
807
|
+
output.push(`${COLOR.gray} ${num}: ${content}${COLOR.reset}`);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
} else {
|
|
812
|
+
output.push(`${COLOR.gray}📍 Location: (source map not available)${COLOR.reset}`);
|
|
813
|
+
}
|
|
814
|
+
output.push(`${COLOR.gray}─────────────────────${COLOR.reset}`);
|
|
815
|
+
output.push(`${COLOR.bold}${COLOR.white}💾 Values:${COLOR.reset}`);
|
|
816
|
+
args.forEach((arg, i) => {
|
|
817
|
+
let val;
|
|
818
|
+
if (arg === void 0) val = "undefined";
|
|
819
|
+
else if (arg === null) val = "null";
|
|
820
|
+
else if (typeof arg === "object") {
|
|
821
|
+
try {
|
|
822
|
+
val = JSON.stringify(arg, null, 2);
|
|
823
|
+
} catch {
|
|
824
|
+
val = "[Circular or Complex Object]";
|
|
825
|
+
}
|
|
826
|
+
} else if (typeof arg === "function") {
|
|
827
|
+
val = `[Function: ${arg.name || "anonymous"}]`;
|
|
828
|
+
} else {
|
|
829
|
+
val = String(arg);
|
|
830
|
+
}
|
|
831
|
+
output.push(`${COLOR.green}[${i}]:${COLOR.reset} ${val}`);
|
|
832
|
+
});
|
|
833
|
+
output.push(`${COLOR.yellow}━━━━━━━━━━━━━━━━━━━━━━${COLOR.reset}`);
|
|
834
|
+
console.log(output.join("\n"));
|
|
835
|
+
} catch (err) {
|
|
836
|
+
console.log(`${COLOR.red}[DEBUG ERROR]${COLOR.reset}`, err);
|
|
837
|
+
console.log(args);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
const debuggerInstance = new SourceMapDebugger();
|
|
842
|
+
function debug(...args) {
|
|
843
|
+
debuggerInstance.debug(...args);
|
|
844
|
+
}
|
|
845
|
+
const _TimerScheduler = class _TimerScheduler {
|
|
846
|
+
/** スケジューラにタスクを登録 */
|
|
847
|
+
static addTask(task) {
|
|
848
|
+
this.tasks.add(task);
|
|
849
|
+
this.ensureStarted();
|
|
850
|
+
}
|
|
851
|
+
/** タスクを削除 */
|
|
852
|
+
static removeTask(task) {
|
|
853
|
+
this.tasks.delete(task);
|
|
854
|
+
}
|
|
855
|
+
/** Interval を開始(1 本だけ) */
|
|
856
|
+
static ensureStarted() {
|
|
857
|
+
if (this.started) return;
|
|
858
|
+
this.started = true;
|
|
859
|
+
system.runInterval(() => {
|
|
860
|
+
this.tick++;
|
|
861
|
+
for (const task of this.tasks) {
|
|
862
|
+
try {
|
|
863
|
+
task();
|
|
864
|
+
} catch (e) {
|
|
865
|
+
console.error("[TimerScheduler] Task error:", e);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}, 1);
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
_TimerScheduler.tasks = /* @__PURE__ */ new Set();
|
|
872
|
+
_TimerScheduler.tick = 0;
|
|
873
|
+
_TimerScheduler.started = false;
|
|
874
|
+
let TimerScheduler = _TimerScheduler;
|
|
875
|
+
class Timer {
|
|
876
|
+
constructor(onRun, onCancel) {
|
|
877
|
+
this.currentTick = 0;
|
|
878
|
+
this.stopped = false;
|
|
879
|
+
this.canceled = false;
|
|
880
|
+
this.forceCanceled = false;
|
|
881
|
+
this.onRun = onRun;
|
|
882
|
+
this.onCancel = onCancel;
|
|
883
|
+
}
|
|
884
|
+
/** 一時停止 */
|
|
885
|
+
stop() {
|
|
886
|
+
this.stopped = true;
|
|
887
|
+
}
|
|
888
|
+
/** 再開 */
|
|
889
|
+
resume() {
|
|
890
|
+
this.stopped = false;
|
|
891
|
+
}
|
|
892
|
+
/** 停止しているか */
|
|
893
|
+
isStopped() {
|
|
894
|
+
return this.stopped;
|
|
895
|
+
}
|
|
896
|
+
/** キャンセル要求 */
|
|
897
|
+
cancel(force = false) {
|
|
898
|
+
if (force) this.forceCanceled = true;
|
|
899
|
+
this.canceled = true;
|
|
900
|
+
}
|
|
901
|
+
/** タイマー内部キャンセル */
|
|
902
|
+
internalCancel(force = false) {
|
|
903
|
+
if (!this.task) return 2;
|
|
904
|
+
TimerScheduler.removeTask(this.task);
|
|
905
|
+
this.onCancel?.();
|
|
906
|
+
return force ? 1 : 0;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
class RepeatingTimer extends Timer {
|
|
910
|
+
constructor(onRun, opts = {}, onCancel) {
|
|
911
|
+
super(onRun, onCancel);
|
|
912
|
+
this.period = opts.period ?? 1;
|
|
913
|
+
this.endless = opts.endless ?? true;
|
|
914
|
+
this.silenceOnStop = opts.silenceOnStop ?? true;
|
|
915
|
+
this.maxElapsedTicks = opts.maxElapsedTicks;
|
|
916
|
+
this.onFinal = opts.onFinal;
|
|
917
|
+
}
|
|
918
|
+
/** タイマー開始 */
|
|
919
|
+
start() {
|
|
920
|
+
this.task = () => {
|
|
921
|
+
if (this.forceCanceled) return this.internalCancel(true);
|
|
922
|
+
if (this.canceled) return this.internalCancel();
|
|
923
|
+
if (!this.endless && this.maxElapsedTicks !== void 0 && this.currentTick >= this.maxElapsedTicks) {
|
|
924
|
+
this.onFinal?.();
|
|
925
|
+
return this.internalCancel();
|
|
926
|
+
}
|
|
927
|
+
if (this.currentTick % this.period === 0) {
|
|
928
|
+
if (!this.stopped || this.stopped && !this.silenceOnStop)
|
|
929
|
+
this.onRun?.(this.currentTick);
|
|
930
|
+
}
|
|
931
|
+
if (!this.stopped) this.currentTick++;
|
|
932
|
+
};
|
|
933
|
+
TimerScheduler.addTask(this.task);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
class DelayedTimer extends Timer {
|
|
937
|
+
constructor(onRun, opts = {}, onCancel) {
|
|
938
|
+
super(onRun, onCancel);
|
|
939
|
+
this.delay = opts.delay ?? 1;
|
|
940
|
+
}
|
|
941
|
+
start() {
|
|
942
|
+
this.task = () => {
|
|
943
|
+
if (this.forceCanceled) return this.internalCancel(true);
|
|
944
|
+
if (this.canceled) return this.internalCancel();
|
|
945
|
+
if (this.currentTick >= this.delay) {
|
|
946
|
+
this.onRun?.(this.currentTick);
|
|
947
|
+
return this.internalCancel();
|
|
948
|
+
}
|
|
949
|
+
this.currentTick++;
|
|
950
|
+
};
|
|
951
|
+
TimerScheduler.addTask(this.task);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
function repeating(opts) {
|
|
955
|
+
const options = {
|
|
956
|
+
period: opts.every,
|
|
957
|
+
endless: opts.endless,
|
|
958
|
+
silenceOnStop: opts.silenceWhenStopped,
|
|
959
|
+
maxElapsedTicks: opts.max,
|
|
960
|
+
onFinal: opts.final
|
|
961
|
+
};
|
|
962
|
+
const t = new RepeatingTimer(opts.run, options, opts.cancel);
|
|
963
|
+
t.start();
|
|
964
|
+
return t;
|
|
965
|
+
}
|
|
966
|
+
function delayed(ticks, run, cancel) {
|
|
967
|
+
const t = new DelayedTimer(() => run(), { delay: ticks }, cancel);
|
|
968
|
+
t.start();
|
|
969
|
+
return t;
|
|
970
|
+
}
|
|
971
|
+
function sleep(tick) {
|
|
972
|
+
return new Promise((resolve) => {
|
|
973
|
+
new DelayedTimer(() => resolve(), { delay: tick }).start();
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
export {
|
|
977
|
+
AxisAlignedBB,
|
|
978
|
+
DelayedTimer,
|
|
979
|
+
EventManager,
|
|
980
|
+
Priority,
|
|
981
|
+
RepeatingTimer,
|
|
982
|
+
Vector3,
|
|
983
|
+
debug,
|
|
984
|
+
delayed,
|
|
985
|
+
keystone,
|
|
986
|
+
repeating,
|
|
987
|
+
sleep
|
|
988
|
+
};
|