cubeforge 0.4.12 → 0.4.14
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/index.d.ts +118 -2
- package/dist/index.js +580 -237
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -506,6 +506,7 @@ var GameLoop = class {
|
|
|
506
506
|
constructor(onTick, options) {
|
|
507
507
|
this.onTick = onTick;
|
|
508
508
|
this.fixedDt = options?.fixedDt;
|
|
509
|
+
this.onRender = options?.onRender;
|
|
509
510
|
}
|
|
510
511
|
rafId = 0;
|
|
511
512
|
lastTime = 0;
|
|
@@ -513,6 +514,8 @@ var GameLoop = class {
|
|
|
513
514
|
paused = false;
|
|
514
515
|
hitPauseTimer = 0;
|
|
515
516
|
fixedDt;
|
|
517
|
+
onRender;
|
|
518
|
+
/** Freeze gameplay for `duration` seconds. Physics/scripts stop but rendering continues. */
|
|
516
519
|
hitPause(duration) {
|
|
517
520
|
this.hitPauseTimer = duration;
|
|
518
521
|
}
|
|
@@ -552,7 +555,8 @@ var GameLoop = class {
|
|
|
552
555
|
this.lastTime = time;
|
|
553
556
|
const dt = this.fixedDt ?? rawDt;
|
|
554
557
|
if (this.hitPauseTimer > 0) {
|
|
555
|
-
this.hitPauseTimer -=
|
|
558
|
+
this.hitPauseTimer -= rawDt;
|
|
559
|
+
this.onRender?.(0);
|
|
556
560
|
} else {
|
|
557
561
|
this.onTick(dt);
|
|
558
562
|
}
|
|
@@ -1222,74 +1226,159 @@ function tween(from, to, duration, ease = Ease.linear, onUpdate, onComplete, opt
|
|
|
1222
1226
|
}
|
|
1223
1227
|
|
|
1224
1228
|
// ../../packages/core/src/tweenTimeline.ts
|
|
1225
|
-
function createTimeline() {
|
|
1226
|
-
const
|
|
1229
|
+
function createTimeline(opts) {
|
|
1230
|
+
const segments = [];
|
|
1231
|
+
const labels = /* @__PURE__ */ new Map();
|
|
1232
|
+
let cursor = 0;
|
|
1233
|
+
let elapsed = 0;
|
|
1227
1234
|
let running = false;
|
|
1228
|
-
let
|
|
1229
|
-
|
|
1230
|
-
let
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
currentTween = null;
|
|
1236
|
-
}
|
|
1237
|
-
if (delayTimer !== null) {
|
|
1238
|
-
clearTimeout(delayTimer);
|
|
1239
|
-
delayTimer = null;
|
|
1240
|
-
}
|
|
1241
|
-
if (rafId !== null) {
|
|
1242
|
-
cancelAnimationFrame(rafId);
|
|
1243
|
-
rafId = null;
|
|
1235
|
+
let complete = false;
|
|
1236
|
+
const maxRepeats = opts?.repeat ?? (opts?.loop ? Infinity : 0);
|
|
1237
|
+
let repeatsDone = 0;
|
|
1238
|
+
function resolveStartTime(addOpts) {
|
|
1239
|
+
if (addOpts?.at) {
|
|
1240
|
+
const labelTime = labels.get(addOpts.at);
|
|
1241
|
+
return labelTime ?? cursor;
|
|
1244
1242
|
}
|
|
1243
|
+
return cursor;
|
|
1245
1244
|
}
|
|
1246
|
-
function
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
rafId = requestAnimationFrame(tick);
|
|
1245
|
+
function resetSegments() {
|
|
1246
|
+
for (const seg of segments) {
|
|
1247
|
+
seg.handle?.stop();
|
|
1248
|
+
seg.handle = void 0;
|
|
1249
|
+
seg.started = false;
|
|
1250
|
+
seg.complete = false;
|
|
1253
1251
|
}
|
|
1254
1252
|
}
|
|
1255
|
-
function
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
const entry = entries[index];
|
|
1261
|
-
const delay = entry.delay ?? 0;
|
|
1262
|
-
const startTween = () => {
|
|
1263
|
-
if (!running) return;
|
|
1264
|
-
currentTween = tween(entry.from, entry.to, entry.duration, entry.ease ?? Ease.linear, entry.onUpdate, () => {
|
|
1265
|
-
entry.onComplete?.();
|
|
1266
|
-
playEntry(index + 1);
|
|
1267
|
-
});
|
|
1268
|
-
lastTime = performance.now();
|
|
1269
|
-
rafId = requestAnimationFrame(tick);
|
|
1270
|
-
};
|
|
1271
|
-
if (delay > 0) {
|
|
1272
|
-
delayTimer = setTimeout(startTween, delay * 1e3);
|
|
1273
|
-
} else {
|
|
1274
|
-
startTween();
|
|
1253
|
+
function computeTotalDuration() {
|
|
1254
|
+
let max = 0;
|
|
1255
|
+
for (const seg of segments) {
|
|
1256
|
+
const end = seg.startTime + seg.delay + seg.entry.duration;
|
|
1257
|
+
if (end > max) max = end;
|
|
1275
1258
|
}
|
|
1259
|
+
return max;
|
|
1276
1260
|
}
|
|
1277
1261
|
const timeline = {
|
|
1278
|
-
add(entry) {
|
|
1279
|
-
|
|
1262
|
+
add(entry, addOpts) {
|
|
1263
|
+
const start = resolveStartTime(addOpts);
|
|
1264
|
+
const delay = addOpts?.delay ?? 0;
|
|
1265
|
+
segments.push({ startTime: start, delay, entry, started: false, complete: false });
|
|
1266
|
+
cursor = start + delay + entry.duration;
|
|
1280
1267
|
return timeline;
|
|
1281
1268
|
},
|
|
1269
|
+
addLabel(name) {
|
|
1270
|
+
labels.set(name, cursor);
|
|
1271
|
+
return timeline;
|
|
1272
|
+
},
|
|
1273
|
+
addParallel(entries, addOpts) {
|
|
1274
|
+
const start = resolveStartTime(addOpts);
|
|
1275
|
+
const delay = addOpts?.delay ?? 0;
|
|
1276
|
+
let maxEnd = cursor;
|
|
1277
|
+
for (const entry of entries) {
|
|
1278
|
+
segments.push({ startTime: start, delay, entry, started: false, complete: false });
|
|
1279
|
+
const end = start + delay + entry.duration;
|
|
1280
|
+
if (end > maxEnd) maxEnd = end;
|
|
1281
|
+
}
|
|
1282
|
+
cursor = maxEnd;
|
|
1283
|
+
return timeline;
|
|
1284
|
+
},
|
|
1285
|
+
update(dt) {
|
|
1286
|
+
if (!running || complete) return;
|
|
1287
|
+
elapsed += dt;
|
|
1288
|
+
let allDone = true;
|
|
1289
|
+
for (const seg of segments) {
|
|
1290
|
+
if (seg.complete) continue;
|
|
1291
|
+
const effectiveStart = seg.startTime + seg.delay;
|
|
1292
|
+
if (elapsed < effectiveStart) {
|
|
1293
|
+
allDone = false;
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (!seg.started) {
|
|
1297
|
+
seg.started = true;
|
|
1298
|
+
seg.handle = tween(
|
|
1299
|
+
seg.entry.from,
|
|
1300
|
+
seg.entry.to,
|
|
1301
|
+
seg.entry.duration,
|
|
1302
|
+
seg.entry.ease ?? Ease.linear,
|
|
1303
|
+
seg.entry.onUpdate,
|
|
1304
|
+
() => {
|
|
1305
|
+
seg.complete = true;
|
|
1306
|
+
seg.entry.onComplete?.();
|
|
1307
|
+
}
|
|
1308
|
+
);
|
|
1309
|
+
const overflow = elapsed - effectiveStart;
|
|
1310
|
+
if (overflow > 0) seg.handle.update(overflow);
|
|
1311
|
+
} else if (seg.handle) {
|
|
1312
|
+
seg.handle.update(dt);
|
|
1313
|
+
}
|
|
1314
|
+
if (!seg.complete) allDone = false;
|
|
1315
|
+
}
|
|
1316
|
+
if (allDone && segments.length > 0) {
|
|
1317
|
+
if (repeatsDone < maxRepeats) {
|
|
1318
|
+
repeatsDone++;
|
|
1319
|
+
elapsed = 0;
|
|
1320
|
+
resetSegments();
|
|
1321
|
+
} else {
|
|
1322
|
+
complete = true;
|
|
1323
|
+
running = false;
|
|
1324
|
+
opts?.onComplete?.();
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
},
|
|
1282
1328
|
start() {
|
|
1283
|
-
|
|
1329
|
+
elapsed = 0;
|
|
1284
1330
|
running = true;
|
|
1285
|
-
|
|
1331
|
+
complete = false;
|
|
1332
|
+
repeatsDone = 0;
|
|
1333
|
+
resetSegments();
|
|
1286
1334
|
},
|
|
1287
1335
|
stop() {
|
|
1288
1336
|
running = false;
|
|
1289
|
-
|
|
1337
|
+
complete = false;
|
|
1338
|
+
elapsed = 0;
|
|
1339
|
+
repeatsDone = 0;
|
|
1340
|
+
resetSegments();
|
|
1290
1341
|
},
|
|
1291
|
-
|
|
1342
|
+
seek(time) {
|
|
1343
|
+
elapsed = 0;
|
|
1344
|
+
resetSegments();
|
|
1345
|
+
elapsed = 0;
|
|
1346
|
+
const step = 1 / 60;
|
|
1347
|
+
while (elapsed < time) {
|
|
1348
|
+
const d = Math.min(step, time - elapsed);
|
|
1349
|
+
elapsed += d;
|
|
1350
|
+
for (const seg of segments) {
|
|
1351
|
+
if (seg.complete) continue;
|
|
1352
|
+
const effectiveStart = seg.startTime + seg.delay;
|
|
1353
|
+
if (elapsed < effectiveStart) continue;
|
|
1354
|
+
if (!seg.started) {
|
|
1355
|
+
seg.started = true;
|
|
1356
|
+
seg.handle = tween(
|
|
1357
|
+
seg.entry.from,
|
|
1358
|
+
seg.entry.to,
|
|
1359
|
+
seg.entry.duration,
|
|
1360
|
+
seg.entry.ease ?? Ease.linear,
|
|
1361
|
+
seg.entry.onUpdate,
|
|
1362
|
+
() => {
|
|
1363
|
+
seg.complete = true;
|
|
1364
|
+
}
|
|
1365
|
+
);
|
|
1366
|
+
const overflow = elapsed - effectiveStart;
|
|
1367
|
+
if (overflow > 0) seg.handle.update(overflow);
|
|
1368
|
+
} else if (seg.handle) {
|
|
1369
|
+
seg.handle.update(d);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
},
|
|
1374
|
+
get isRunning() {
|
|
1292
1375
|
return running;
|
|
1376
|
+
},
|
|
1377
|
+
get isComplete() {
|
|
1378
|
+
return complete;
|
|
1379
|
+
},
|
|
1380
|
+
get totalDuration() {
|
|
1381
|
+
return computeTotalDuration();
|
|
1293
1382
|
}
|
|
1294
1383
|
};
|
|
1295
1384
|
return timeline;
|
|
@@ -3389,18 +3478,34 @@ var RenderSystem = class {
|
|
|
3389
3478
|
animator._entered = true;
|
|
3390
3479
|
stateDef.onEnter?.();
|
|
3391
3480
|
}
|
|
3392
|
-
if (
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3481
|
+
if (animator._blendTimer != null && animator._blendTimer > 0) {
|
|
3482
|
+
animator._blendTimer -= dt;
|
|
3483
|
+
if (animator._blendTimer <= 0 && animator._blendToState) {
|
|
3484
|
+
stateDef.onExit?.();
|
|
3485
|
+
animator.currentState = animator._blendToState;
|
|
3486
|
+
animator._entered = false;
|
|
3487
|
+
animator._blendTimer = void 0;
|
|
3488
|
+
animator._blendToState = void 0;
|
|
3489
|
+
}
|
|
3490
|
+
} else {
|
|
3491
|
+
if (stateDef.transitions && stateDef.transitions.length > 0) {
|
|
3492
|
+
const sorted = [...stateDef.transitions].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
3493
|
+
for (const trans of sorted) {
|
|
3494
|
+
if (trans.exitTime != null && anim.frames.length > 0) {
|
|
3495
|
+
const progress = anim.currentIndex / anim.frames.length;
|
|
3496
|
+
if (progress < trans.exitTime) continue;
|
|
3497
|
+
}
|
|
3498
|
+
if (evaluateConditions(trans.when, animator.params)) {
|
|
3499
|
+
if (trans.blendDuration && trans.blendDuration > 0) {
|
|
3500
|
+
animator._blendTimer = trans.blendDuration;
|
|
3501
|
+
animator._blendToState = trans.to;
|
|
3502
|
+
} else {
|
|
3503
|
+
stateDef.onExit?.();
|
|
3504
|
+
animator.currentState = trans.to;
|
|
3505
|
+
animator._entered = false;
|
|
3506
|
+
}
|
|
3507
|
+
break;
|
|
3508
|
+
}
|
|
3404
3509
|
}
|
|
3405
3510
|
}
|
|
3406
3511
|
}
|
|
@@ -14557,7 +14662,11 @@ function Game({
|
|
|
14557
14662
|
handle.onFrame?.();
|
|
14558
14663
|
}
|
|
14559
14664
|
},
|
|
14560
|
-
|
|
14665
|
+
{
|
|
14666
|
+
...deterministic ? { fixedDt: 1 / 60 } : {},
|
|
14667
|
+
// During hit-pause, re-render the last frame so the screen isn't blank
|
|
14668
|
+
onRender: () => renderSystem.update(ecs, 0)
|
|
14669
|
+
}
|
|
14561
14670
|
);
|
|
14562
14671
|
const postProcessStack = createPostProcessStack();
|
|
14563
14672
|
const state = {
|
|
@@ -16057,7 +16166,10 @@ function Tilemap({
|
|
|
16057
16166
|
triggerLayer: triggerLayerName = "triggers",
|
|
16058
16167
|
onTileProperty,
|
|
16059
16168
|
navGrid,
|
|
16060
|
-
mergeColliders = true
|
|
16169
|
+
mergeColliders = true,
|
|
16170
|
+
solidTiles,
|
|
16171
|
+
autoColliders = false,
|
|
16172
|
+
tileColliderProps: _tileColliderProps
|
|
16061
16173
|
}) {
|
|
16062
16174
|
const engine = useContext20(EngineContext);
|
|
16063
16175
|
const [spawnedNodes, setSpawnedNodes] = useState6([]);
|
|
@@ -16118,7 +16230,7 @@ function Tilemap({
|
|
|
16118
16230
|
if (layerFilter && !layerFilter(layer)) continue;
|
|
16119
16231
|
if (!layer.visible) continue;
|
|
16120
16232
|
if (layer.type === "tilelayer" && layer.data) {
|
|
16121
|
-
const collision = isCollisionLayer(layer, collisionLayer);
|
|
16233
|
+
const collision = isCollisionLayer(layer, collisionLayer) || autoColliders && solidTiles && solidTiles.length > 0;
|
|
16122
16234
|
const trigger = !collision && isTriggerLayer(layer, triggerLayerName);
|
|
16123
16235
|
if (collision && navGrid) {
|
|
16124
16236
|
for (let row = 0; row < mapData.height; row++) {
|
|
@@ -16130,11 +16242,13 @@ function Tilemap({
|
|
|
16130
16242
|
}
|
|
16131
16243
|
if (collision || trigger) {
|
|
16132
16244
|
if (mergeColliders) {
|
|
16245
|
+
const solidSet = solidTiles ? new Set(solidTiles) : null;
|
|
16133
16246
|
const solidGrid = [];
|
|
16134
16247
|
for (let row = 0; row < mapData.height; row++) {
|
|
16135
16248
|
solidGrid[row] = [];
|
|
16136
16249
|
for (let col = 0; col < mapData.width; col++) {
|
|
16137
|
-
|
|
16250
|
+
const gid = layer.data[row * mapData.width + col];
|
|
16251
|
+
solidGrid[row][col] = gid !== 0 && (!solidSet || solidSet.has(gid));
|
|
16138
16252
|
}
|
|
16139
16253
|
}
|
|
16140
16254
|
const merged = mergeTileColliders(solidGrid, tilewidth, tileheight, 0, 0);
|
|
@@ -17764,6 +17878,200 @@ function useSceneManager(initialScene) {
|
|
|
17764
17878
|
};
|
|
17765
17879
|
}
|
|
17766
17880
|
|
|
17881
|
+
// src/hooks/useSceneTransition.ts
|
|
17882
|
+
import { useState as useState13, useCallback as useCallback7, useRef as useRef24, useEffect as useEffect60 } from "react";
|
|
17883
|
+
function useSceneTransition(initialScene, defaultTransition) {
|
|
17884
|
+
const [stack, setStack] = useState13([initialScene]);
|
|
17885
|
+
const [transState, setTransState] = useState13({
|
|
17886
|
+
phase: "idle",
|
|
17887
|
+
progress: 0,
|
|
17888
|
+
effect: null,
|
|
17889
|
+
pendingAction: null
|
|
17890
|
+
});
|
|
17891
|
+
const stackRef = useRef24(stack);
|
|
17892
|
+
stackRef.current = stack;
|
|
17893
|
+
const transRef = useRef24(transState);
|
|
17894
|
+
transRef.current = transState;
|
|
17895
|
+
useEffect60(() => {
|
|
17896
|
+
if (transState.phase === "idle") return;
|
|
17897
|
+
const effect = transState.effect;
|
|
17898
|
+
if (!effect || effect.type === "instant") return;
|
|
17899
|
+
const duration = (effect.duration ?? 0.4) / 2;
|
|
17900
|
+
let rafId;
|
|
17901
|
+
let start = performance.now();
|
|
17902
|
+
const animate = (now) => {
|
|
17903
|
+
const elapsed = (now - start) / 1e3;
|
|
17904
|
+
const t = Math.min(elapsed / duration, 1);
|
|
17905
|
+
if (transRef.current.phase === "out") {
|
|
17906
|
+
setTransState((prev) => ({ ...prev, progress: t }));
|
|
17907
|
+
if (t >= 1) {
|
|
17908
|
+
transRef.current.pendingAction?.();
|
|
17909
|
+
start = performance.now();
|
|
17910
|
+
setTransState((prev) => ({ ...prev, phase: "in", progress: 1, pendingAction: null }));
|
|
17911
|
+
}
|
|
17912
|
+
} else if (transRef.current.phase === "in") {
|
|
17913
|
+
setTransState((prev) => ({ ...prev, progress: 1 - t }));
|
|
17914
|
+
if (t >= 1) {
|
|
17915
|
+
setTransState({ phase: "idle", progress: 0, effect: null, pendingAction: null });
|
|
17916
|
+
return;
|
|
17917
|
+
}
|
|
17918
|
+
}
|
|
17919
|
+
rafId = requestAnimationFrame(animate);
|
|
17920
|
+
};
|
|
17921
|
+
rafId = requestAnimationFrame(animate);
|
|
17922
|
+
return () => cancelAnimationFrame(rafId);
|
|
17923
|
+
}, [transState.phase, transState.effect]);
|
|
17924
|
+
const startTransition = useCallback7(
|
|
17925
|
+
(effect, action) => {
|
|
17926
|
+
const eff = effect ?? defaultTransition ?? { type: "instant" };
|
|
17927
|
+
if (eff.type === "instant") {
|
|
17928
|
+
action();
|
|
17929
|
+
return;
|
|
17930
|
+
}
|
|
17931
|
+
setTransState({
|
|
17932
|
+
phase: "out",
|
|
17933
|
+
progress: 0,
|
|
17934
|
+
effect: eff,
|
|
17935
|
+
pendingAction: action
|
|
17936
|
+
});
|
|
17937
|
+
},
|
|
17938
|
+
[defaultTransition]
|
|
17939
|
+
);
|
|
17940
|
+
const push = useCallback7(
|
|
17941
|
+
(scene, transition) => {
|
|
17942
|
+
startTransition(transition, () => setStack((prev) => [...prev, scene]));
|
|
17943
|
+
},
|
|
17944
|
+
[startTransition]
|
|
17945
|
+
);
|
|
17946
|
+
const pop = useCallback7(
|
|
17947
|
+
(transition) => {
|
|
17948
|
+
const prev = stackRef.current;
|
|
17949
|
+
if (prev.length <= 1) return void 0;
|
|
17950
|
+
const popped = prev[prev.length - 1];
|
|
17951
|
+
startTransition(transition, () => setStack((p) => p.slice(0, -1)));
|
|
17952
|
+
return popped;
|
|
17953
|
+
},
|
|
17954
|
+
[startTransition]
|
|
17955
|
+
);
|
|
17956
|
+
const replace = useCallback7(
|
|
17957
|
+
(scene, transition) => {
|
|
17958
|
+
startTransition(transition, () => setStack((prev) => [...prev.slice(0, -1), scene]));
|
|
17959
|
+
},
|
|
17960
|
+
[startTransition]
|
|
17961
|
+
);
|
|
17962
|
+
const reset = useCallback7(
|
|
17963
|
+
(scene, transition) => {
|
|
17964
|
+
startTransition(transition, () => setStack([scene]));
|
|
17965
|
+
},
|
|
17966
|
+
[startTransition]
|
|
17967
|
+
);
|
|
17968
|
+
return {
|
|
17969
|
+
current: stack[stack.length - 1],
|
|
17970
|
+
stack,
|
|
17971
|
+
push,
|
|
17972
|
+
pop,
|
|
17973
|
+
replace,
|
|
17974
|
+
reset,
|
|
17975
|
+
progress: transState.progress,
|
|
17976
|
+
phase: transState.phase,
|
|
17977
|
+
activeTransition: transState.effect
|
|
17978
|
+
};
|
|
17979
|
+
}
|
|
17980
|
+
|
|
17981
|
+
// src/components/SceneTransitionOverlay.tsx
|
|
17982
|
+
import React9 from "react";
|
|
17983
|
+
function getOverlayStyle(effect, progress) {
|
|
17984
|
+
const color = effect.color ?? "#000";
|
|
17985
|
+
switch (effect.type) {
|
|
17986
|
+
case "fade":
|
|
17987
|
+
return {
|
|
17988
|
+
position: "absolute",
|
|
17989
|
+
inset: 0,
|
|
17990
|
+
backgroundColor: color,
|
|
17991
|
+
opacity: progress,
|
|
17992
|
+
pointerEvents: "none",
|
|
17993
|
+
zIndex: 9999
|
|
17994
|
+
};
|
|
17995
|
+
case "wipe": {
|
|
17996
|
+
const dir = effect.direction ?? "left";
|
|
17997
|
+
let clipPath;
|
|
17998
|
+
switch (dir) {
|
|
17999
|
+
case "left":
|
|
18000
|
+
clipPath = `inset(0 ${(1 - progress) * 100}% 0 0)`;
|
|
18001
|
+
break;
|
|
18002
|
+
case "right":
|
|
18003
|
+
clipPath = `inset(0 0 0 ${(1 - progress) * 100}%)`;
|
|
18004
|
+
break;
|
|
18005
|
+
case "up":
|
|
18006
|
+
clipPath = `inset(0 0 ${(1 - progress) * 100}% 0)`;
|
|
18007
|
+
break;
|
|
18008
|
+
case "down":
|
|
18009
|
+
clipPath = `inset(${(1 - progress) * 100}% 0 0 0)`;
|
|
18010
|
+
break;
|
|
18011
|
+
default:
|
|
18012
|
+
clipPath = `inset(0 ${(1 - progress) * 100}% 0 0)`;
|
|
18013
|
+
}
|
|
18014
|
+
return {
|
|
18015
|
+
position: "absolute",
|
|
18016
|
+
inset: 0,
|
|
18017
|
+
backgroundColor: color,
|
|
18018
|
+
clipPath,
|
|
18019
|
+
pointerEvents: "none",
|
|
18020
|
+
zIndex: 9999
|
|
18021
|
+
};
|
|
18022
|
+
}
|
|
18023
|
+
case "circle-close": {
|
|
18024
|
+
const radius = (1 - progress) * 72;
|
|
18025
|
+
return {
|
|
18026
|
+
position: "absolute",
|
|
18027
|
+
inset: 0,
|
|
18028
|
+
backgroundColor: color,
|
|
18029
|
+
clipPath: `circle(${radius}% at 50% 50%)`,
|
|
18030
|
+
pointerEvents: "none",
|
|
18031
|
+
zIndex: 9999
|
|
18032
|
+
};
|
|
18033
|
+
}
|
|
18034
|
+
default:
|
|
18035
|
+
return { display: "none" };
|
|
18036
|
+
}
|
|
18037
|
+
}
|
|
18038
|
+
function SceneTransitionOverlay({ controls }) {
|
|
18039
|
+
if (controls.phase === "idle" || !controls.activeTransition || controls.activeTransition.type === "instant") {
|
|
18040
|
+
return null;
|
|
18041
|
+
}
|
|
18042
|
+
if (controls.activeTransition.type === "circle-close") {
|
|
18043
|
+
const color = controls.activeTransition.color ?? "#000";
|
|
18044
|
+
const radius = (1 - controls.progress) * 72;
|
|
18045
|
+
return React9.createElement("div", {
|
|
18046
|
+
style: {
|
|
18047
|
+
position: "absolute",
|
|
18048
|
+
inset: 0,
|
|
18049
|
+
backgroundColor: color,
|
|
18050
|
+
WebkitMaskImage: `radial-gradient(circle ${radius}vmax at 50% 50%, transparent 100%, black 100%)`,
|
|
18051
|
+
maskImage: `radial-gradient(circle ${radius}vmax at 50% 50%, transparent 100%, black 100%)`,
|
|
18052
|
+
pointerEvents: "none",
|
|
18053
|
+
zIndex: 9999
|
|
18054
|
+
}
|
|
18055
|
+
});
|
|
18056
|
+
}
|
|
18057
|
+
return React9.createElement("div", {
|
|
18058
|
+
style: getOverlayStyle(controls.activeTransition, controls.progress)
|
|
18059
|
+
});
|
|
18060
|
+
}
|
|
18061
|
+
|
|
18062
|
+
// src/hooks/useHitstop.ts
|
|
18063
|
+
import { useContext as useContext51, useCallback as useCallback8 } from "react";
|
|
18064
|
+
function useHitstop() {
|
|
18065
|
+
const engine = useContext51(EngineContext);
|
|
18066
|
+
const freeze = useCallback8(
|
|
18067
|
+
(seconds) => {
|
|
18068
|
+
engine.loop.hitPause(seconds);
|
|
18069
|
+
},
|
|
18070
|
+
[engine]
|
|
18071
|
+
);
|
|
18072
|
+
return { freeze };
|
|
18073
|
+
}
|
|
18074
|
+
|
|
17767
18075
|
// src/hooks/useInputBuffer.ts
|
|
17768
18076
|
import { useMemo as useMemo9 } from "react";
|
|
17769
18077
|
function useInputBuffer(opts) {
|
|
@@ -17771,9 +18079,9 @@ function useInputBuffer(opts) {
|
|
|
17771
18079
|
}
|
|
17772
18080
|
|
|
17773
18081
|
// src/hooks/useComboDetector.ts
|
|
17774
|
-
import { useMemo as useMemo10, useRef as
|
|
18082
|
+
import { useMemo as useMemo10, useRef as useRef25 } from "react";
|
|
17775
18083
|
function useComboDetector(combos) {
|
|
17776
|
-
const lastComboRef =
|
|
18084
|
+
const lastComboRef = useRef25(null);
|
|
17777
18085
|
const result = useMemo10(() => {
|
|
17778
18086
|
const detector = new ComboDetector({ combos });
|
|
17779
18087
|
const api = {
|
|
@@ -17796,11 +18104,11 @@ function useComboDetector(combos) {
|
|
|
17796
18104
|
}
|
|
17797
18105
|
|
|
17798
18106
|
// src/hooks/useParent.ts
|
|
17799
|
-
import { useEffect as
|
|
18107
|
+
import { useEffect as useEffect61, useContext as useContext52 } from "react";
|
|
17800
18108
|
function useParent(childEntityId, parentEntityId) {
|
|
17801
|
-
const engine =
|
|
18109
|
+
const engine = useContext52(EngineContext);
|
|
17802
18110
|
if (!engine) throw new Error("useParent must be used inside <Game>");
|
|
17803
|
-
|
|
18111
|
+
useEffect61(() => {
|
|
17804
18112
|
setParent(engine.ecs, childEntityId, parentEntityId);
|
|
17805
18113
|
return () => {
|
|
17806
18114
|
removeParent(engine.ecs, childEntityId);
|
|
@@ -17809,7 +18117,7 @@ function useParent(childEntityId, parentEntityId) {
|
|
|
17809
18117
|
}
|
|
17810
18118
|
|
|
17811
18119
|
// src/hooks/useAccessibility.ts
|
|
17812
|
-
import { useCallback as
|
|
18120
|
+
import { useCallback as useCallback9, useSyncExternalStore } from "react";
|
|
17813
18121
|
var _version = 0;
|
|
17814
18122
|
var _listeners = /* @__PURE__ */ new Set();
|
|
17815
18123
|
function subscribe(cb) {
|
|
@@ -17821,12 +18129,12 @@ function getSnapshot() {
|
|
|
17821
18129
|
}
|
|
17822
18130
|
function useAccessibility() {
|
|
17823
18131
|
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
17824
|
-
const setOptions =
|
|
18132
|
+
const setOptions = useCallback9((opts) => {
|
|
17825
18133
|
setAccessibilityOptions(opts);
|
|
17826
18134
|
_version++;
|
|
17827
18135
|
for (const cb of _listeners) cb();
|
|
17828
18136
|
}, []);
|
|
17829
|
-
const announce =
|
|
18137
|
+
const announce = useCallback9((text, priority) => {
|
|
17830
18138
|
announceToScreenReader(text, priority);
|
|
17831
18139
|
}, []);
|
|
17832
18140
|
return {
|
|
@@ -17837,18 +18145,18 @@ function useAccessibility() {
|
|
|
17837
18145
|
}
|
|
17838
18146
|
|
|
17839
18147
|
// src/hooks/useHMR.ts
|
|
17840
|
-
import { useEffect as
|
|
18148
|
+
import { useEffect as useEffect62, useRef as useRef26, useMemo as useMemo11 } from "react";
|
|
17841
18149
|
var idCounter = 0;
|
|
17842
18150
|
function useHMR(hmrKey) {
|
|
17843
|
-
const idRef =
|
|
18151
|
+
const idRef = useRef26(null);
|
|
17844
18152
|
if (idRef.current === null) {
|
|
17845
18153
|
idRef.current = hmrKey ?? `__hmr_${idCounter++}`;
|
|
17846
18154
|
}
|
|
17847
18155
|
const key = idRef.current;
|
|
17848
18156
|
const isHotReload = hmrLoadState(key) !== void 0;
|
|
17849
|
-
const disposeRef =
|
|
17850
|
-
const acceptRef =
|
|
17851
|
-
|
|
18157
|
+
const disposeRef = useRef26(null);
|
|
18158
|
+
const acceptRef = useRef26(null);
|
|
18159
|
+
useEffect62(() => {
|
|
17852
18160
|
const hot = import.meta.hot;
|
|
17853
18161
|
if (!hot) return;
|
|
17854
18162
|
hot.dispose(() => {
|
|
@@ -17881,11 +18189,11 @@ function useHMR(hmrKey) {
|
|
|
17881
18189
|
}
|
|
17882
18190
|
|
|
17883
18191
|
// src/hooks/useSquashStretch.ts
|
|
17884
|
-
import { useCallback as
|
|
18192
|
+
import { useCallback as useCallback10, useContext as useContext53 } from "react";
|
|
17885
18193
|
function useSquashStretch() {
|
|
17886
|
-
const engine =
|
|
17887
|
-
const entityId =
|
|
17888
|
-
const trigger =
|
|
18194
|
+
const engine = useContext53(EngineContext);
|
|
18195
|
+
const entityId = useContext53(EntityContext);
|
|
18196
|
+
const trigger = useCallback10(
|
|
17889
18197
|
(scaleX, scaleY) => {
|
|
17890
18198
|
const ss = engine.ecs.getComponent(entityId, "SquashStretch");
|
|
17891
18199
|
if (!ss) return;
|
|
@@ -17898,10 +18206,10 @@ function useSquashStretch() {
|
|
|
17898
18206
|
}
|
|
17899
18207
|
|
|
17900
18208
|
// ../gameplay/src/hooks/useAnimationController.ts
|
|
17901
|
-
import { useState as
|
|
18209
|
+
import { useState as useState14, useCallback as useCallback11 } from "react";
|
|
17902
18210
|
function useAnimationController(states, initial) {
|
|
17903
|
-
const [stateName, setStateName] =
|
|
17904
|
-
const setState =
|
|
18211
|
+
const [stateName, setStateName] = useState14(initial);
|
|
18212
|
+
const setState = useCallback11((next) => {
|
|
17905
18213
|
setStateName((prev) => prev === next ? prev : next);
|
|
17906
18214
|
}, []);
|
|
17907
18215
|
const clip = states[stateName] ?? states[initial];
|
|
@@ -17923,39 +18231,39 @@ function useAnimationController(states, initial) {
|
|
|
17923
18231
|
}
|
|
17924
18232
|
|
|
17925
18233
|
// ../gameplay/src/hooks/useAISteering.ts
|
|
17926
|
-
import { useCallback as
|
|
18234
|
+
import { useCallback as useCallback12 } from "react";
|
|
17927
18235
|
function useAISteering() {
|
|
17928
|
-
const seek$ =
|
|
17929
|
-
const flee$ =
|
|
17930
|
-
const arrive$ =
|
|
18236
|
+
const seek$ = useCallback12((pos, target, speed) => seek(pos, target, speed), []);
|
|
18237
|
+
const flee$ = useCallback12((pos, threat, speed) => flee(pos, threat, speed), []);
|
|
18238
|
+
const arrive$ = useCallback12(
|
|
17931
18239
|
(pos, target, speed, slowRadius) => arrive(pos, target, speed, slowRadius),
|
|
17932
18240
|
[]
|
|
17933
18241
|
);
|
|
17934
|
-
const patrol$ =
|
|
18242
|
+
const patrol$ = useCallback12(
|
|
17935
18243
|
(pos, waypoints, speed, currentIdx, arriveThreshold) => patrol(pos, waypoints, speed, currentIdx, arriveThreshold),
|
|
17936
18244
|
[]
|
|
17937
18245
|
);
|
|
17938
|
-
const wander$ =
|
|
18246
|
+
const wander$ = useCallback12(
|
|
17939
18247
|
(pos, angle, speed, jitter) => wander(pos, angle, speed, jitter),
|
|
17940
18248
|
[]
|
|
17941
18249
|
);
|
|
17942
|
-
const pursuit$ =
|
|
18250
|
+
const pursuit$ = useCallback12(
|
|
17943
18251
|
(pos, targetPos, targetVel, speed, lookAhead) => pursuit(pos, targetPos, targetVel, speed, lookAhead),
|
|
17944
18252
|
[]
|
|
17945
18253
|
);
|
|
17946
|
-
const evade$ =
|
|
18254
|
+
const evade$ = useCallback12(
|
|
17947
18255
|
(pos, threatPos, threatVel, speed, lookAhead) => evade(pos, threatPos, threatVel, speed, lookAhead),
|
|
17948
18256
|
[]
|
|
17949
18257
|
);
|
|
17950
|
-
const separation$ =
|
|
18258
|
+
const separation$ = useCallback12(
|
|
17951
18259
|
(pos, neighbors, speed, radius) => separation(pos, neighbors, speed, radius),
|
|
17952
18260
|
[]
|
|
17953
18261
|
);
|
|
17954
|
-
const cohesion$ =
|
|
18262
|
+
const cohesion$ = useCallback12(
|
|
17955
18263
|
(pos, neighbors, speed) => cohesion(pos, neighbors, speed),
|
|
17956
18264
|
[]
|
|
17957
18265
|
);
|
|
17958
|
-
const alignment$ =
|
|
18266
|
+
const alignment$ = useCallback12(
|
|
17959
18267
|
(neighborVelocities, speed) => alignment(neighborVelocities, speed),
|
|
17960
18268
|
[]
|
|
17961
18269
|
);
|
|
@@ -17974,9 +18282,9 @@ function useAISteering() {
|
|
|
17974
18282
|
}
|
|
17975
18283
|
|
|
17976
18284
|
// ../gameplay/src/hooks/useDamageZone.ts
|
|
17977
|
-
import { useContext as
|
|
18285
|
+
import { useContext as useContext54 } from "react";
|
|
17978
18286
|
function useDamageZone(damage, opts = {}) {
|
|
17979
|
-
const engine =
|
|
18287
|
+
const engine = useContext54(EngineContext);
|
|
17980
18288
|
useTriggerEnter(
|
|
17981
18289
|
(other) => {
|
|
17982
18290
|
engine.events.emit(`damage:${other}`, { amount: damage });
|
|
@@ -17986,11 +18294,11 @@ function useDamageZone(damage, opts = {}) {
|
|
|
17986
18294
|
}
|
|
17987
18295
|
|
|
17988
18296
|
// ../gameplay/src/hooks/useDropThrough.ts
|
|
17989
|
-
import { useContext as
|
|
18297
|
+
import { useContext as useContext55, useCallback as useCallback13 } from "react";
|
|
17990
18298
|
function useDropThrough(frames = 8) {
|
|
17991
|
-
const engine =
|
|
17992
|
-
const entityId =
|
|
17993
|
-
const dropThrough =
|
|
18299
|
+
const engine = useContext55(EngineContext);
|
|
18300
|
+
const entityId = useContext55(EntityContext);
|
|
18301
|
+
const dropThrough = useCallback13(() => {
|
|
17994
18302
|
const rb = engine.ecs.getComponent(entityId, "RigidBody");
|
|
17995
18303
|
if (rb) rb.dropThrough = frames;
|
|
17996
18304
|
}, [engine.ecs, entityId, frames]);
|
|
@@ -17998,17 +18306,17 @@ function useDropThrough(frames = 8) {
|
|
|
17998
18306
|
}
|
|
17999
18307
|
|
|
18000
18308
|
// ../gameplay/src/hooks/useGameStateMachine.ts
|
|
18001
|
-
import { useState as
|
|
18309
|
+
import { useState as useState15, useRef as useRef27, useCallback as useCallback14, useEffect as useEffect63, useContext as useContext56 } from "react";
|
|
18002
18310
|
function useGameStateMachine(states, initial) {
|
|
18003
|
-
const engine =
|
|
18004
|
-
const [state, setState] =
|
|
18005
|
-
const stateRef =
|
|
18006
|
-
const statesRef =
|
|
18311
|
+
const engine = useContext56(EngineContext);
|
|
18312
|
+
const [state, setState] = useState15(initial);
|
|
18313
|
+
const stateRef = useRef27(initial);
|
|
18314
|
+
const statesRef = useRef27(states);
|
|
18007
18315
|
statesRef.current = states;
|
|
18008
|
-
|
|
18316
|
+
useEffect63(() => {
|
|
18009
18317
|
statesRef.current[initial]?.onEnter?.();
|
|
18010
18318
|
}, []);
|
|
18011
|
-
const transition =
|
|
18319
|
+
const transition = useCallback14((to) => {
|
|
18012
18320
|
const current = stateRef.current;
|
|
18013
18321
|
if (current === to) return;
|
|
18014
18322
|
statesRef.current[current]?.onExit?.();
|
|
@@ -18016,7 +18324,7 @@ function useGameStateMachine(states, initial) {
|
|
|
18016
18324
|
setState(to);
|
|
18017
18325
|
statesRef.current[to]?.onEnter?.();
|
|
18018
18326
|
}, []);
|
|
18019
|
-
|
|
18327
|
+
useEffect63(() => {
|
|
18020
18328
|
const eid = engine.ecs.createEntity();
|
|
18021
18329
|
engine.ecs.addComponent(
|
|
18022
18330
|
eid,
|
|
@@ -18032,27 +18340,27 @@ function useGameStateMachine(states, initial) {
|
|
|
18032
18340
|
}
|
|
18033
18341
|
|
|
18034
18342
|
// ../gameplay/src/hooks/useHealth.ts
|
|
18035
|
-
import { useRef as
|
|
18343
|
+
import { useRef as useRef28, useEffect as useEffect64, useContext as useContext57, useCallback as useCallback15 } from "react";
|
|
18036
18344
|
function useHealth(maxHp, opts = {}) {
|
|
18037
|
-
const engine =
|
|
18038
|
-
const entityId =
|
|
18039
|
-
const hpRef =
|
|
18040
|
-
const invincibleRef =
|
|
18345
|
+
const engine = useContext57(EngineContext);
|
|
18346
|
+
const entityId = useContext57(EntityContext);
|
|
18347
|
+
const hpRef = useRef28(maxHp);
|
|
18348
|
+
const invincibleRef = useRef28(false);
|
|
18041
18349
|
const iFrameDuration = opts.iFrames ?? 1;
|
|
18042
|
-
const onDeathRef =
|
|
18043
|
-
const onDamageRef =
|
|
18044
|
-
|
|
18350
|
+
const onDeathRef = useRef28(opts.onDeath);
|
|
18351
|
+
const onDamageRef = useRef28(opts.onDamage);
|
|
18352
|
+
useEffect64(() => {
|
|
18045
18353
|
onDeathRef.current = opts.onDeath;
|
|
18046
18354
|
});
|
|
18047
|
-
|
|
18355
|
+
useEffect64(() => {
|
|
18048
18356
|
onDamageRef.current = opts.onDamage;
|
|
18049
18357
|
});
|
|
18050
|
-
const timerRef =
|
|
18358
|
+
const timerRef = useRef28(
|
|
18051
18359
|
createTimer(iFrameDuration, () => {
|
|
18052
18360
|
invincibleRef.current = false;
|
|
18053
18361
|
})
|
|
18054
18362
|
);
|
|
18055
|
-
const takeDamage =
|
|
18363
|
+
const takeDamage = useCallback15(
|
|
18056
18364
|
(amount = 1) => {
|
|
18057
18365
|
if (invincibleRef.current || hpRef.current <= 0) return;
|
|
18058
18366
|
hpRef.current = Math.max(0, hpRef.current - amount);
|
|
@@ -18065,28 +18373,28 @@ function useHealth(maxHp, opts = {}) {
|
|
|
18065
18373
|
},
|
|
18066
18374
|
[iFrameDuration]
|
|
18067
18375
|
);
|
|
18068
|
-
const takeDamageRef =
|
|
18069
|
-
|
|
18376
|
+
const takeDamageRef = useRef28(takeDamage);
|
|
18377
|
+
useEffect64(() => {
|
|
18070
18378
|
takeDamageRef.current = takeDamage;
|
|
18071
18379
|
}, [takeDamage]);
|
|
18072
|
-
|
|
18380
|
+
useEffect64(() => {
|
|
18073
18381
|
return engine.events.on(`damage:${entityId}`, ({ amount }) => {
|
|
18074
18382
|
takeDamageRef.current(amount);
|
|
18075
18383
|
});
|
|
18076
18384
|
}, [engine.events, entityId]);
|
|
18077
|
-
const heal =
|
|
18385
|
+
const heal = useCallback15(
|
|
18078
18386
|
(amount) => {
|
|
18079
18387
|
hpRef.current = Math.min(maxHp, hpRef.current + amount);
|
|
18080
18388
|
},
|
|
18081
18389
|
[maxHp]
|
|
18082
18390
|
);
|
|
18083
|
-
const setHp =
|
|
18391
|
+
const setHp = useCallback15(
|
|
18084
18392
|
(hp) => {
|
|
18085
18393
|
hpRef.current = Math.min(maxHp, Math.max(0, hp));
|
|
18086
18394
|
},
|
|
18087
18395
|
[maxHp]
|
|
18088
18396
|
);
|
|
18089
|
-
const update =
|
|
18397
|
+
const update = useCallback15((dt) => {
|
|
18090
18398
|
timerRef.current.update(dt);
|
|
18091
18399
|
}, []);
|
|
18092
18400
|
return {
|
|
@@ -18110,11 +18418,11 @@ function useHealth(maxHp, opts = {}) {
|
|
|
18110
18418
|
}
|
|
18111
18419
|
|
|
18112
18420
|
// ../gameplay/src/hooks/useKinematicBody.ts
|
|
18113
|
-
import { useContext as
|
|
18421
|
+
import { useContext as useContext58, useCallback as useCallback16 } from "react";
|
|
18114
18422
|
function useKinematicBody() {
|
|
18115
|
-
const engine =
|
|
18116
|
-
const entityId =
|
|
18117
|
-
const moveAndCollide =
|
|
18423
|
+
const engine = useContext58(EngineContext);
|
|
18424
|
+
const entityId = useContext58(EntityContext);
|
|
18425
|
+
const moveAndCollide = useCallback16(
|
|
18118
18426
|
(dx, dy) => {
|
|
18119
18427
|
const transform = engine.ecs.getComponent(entityId, "Transform");
|
|
18120
18428
|
if (!transform) return { dx: 0, dy: 0 };
|
|
@@ -18150,7 +18458,7 @@ function useKinematicBody() {
|
|
|
18150
18458
|
},
|
|
18151
18459
|
[engine.ecs, entityId]
|
|
18152
18460
|
);
|
|
18153
|
-
const setVelocity =
|
|
18461
|
+
const setVelocity = useCallback16(
|
|
18154
18462
|
(vx, vy) => {
|
|
18155
18463
|
const rb = engine.ecs.getComponent(entityId, "RigidBody");
|
|
18156
18464
|
if (rb) {
|
|
@@ -18160,7 +18468,7 @@ function useKinematicBody() {
|
|
|
18160
18468
|
},
|
|
18161
18469
|
[engine.ecs, entityId]
|
|
18162
18470
|
);
|
|
18163
|
-
const setAngularVelocity =
|
|
18471
|
+
const setAngularVelocity = useCallback16(
|
|
18164
18472
|
(w) => {
|
|
18165
18473
|
const rb = engine.ecs.getComponent(entityId, "RigidBody");
|
|
18166
18474
|
if (rb) rb.angularVelocity = w;
|
|
@@ -18171,12 +18479,12 @@ function useKinematicBody() {
|
|
|
18171
18479
|
}
|
|
18172
18480
|
|
|
18173
18481
|
// ../gameplay/src/hooks/useLevelTransition.ts
|
|
18174
|
-
import { useState as
|
|
18482
|
+
import { useState as useState16, useRef as useRef29, useCallback as useCallback17 } from "react";
|
|
18175
18483
|
function useLevelTransition(initial) {
|
|
18176
|
-
const [currentLevel, setCurrentLevel] =
|
|
18177
|
-
const [isTransitioning, setIsTransitioning] =
|
|
18178
|
-
const overlayRef =
|
|
18179
|
-
const transitionTo =
|
|
18484
|
+
const [currentLevel, setCurrentLevel] = useState16(initial);
|
|
18485
|
+
const [isTransitioning, setIsTransitioning] = useState16(false);
|
|
18486
|
+
const overlayRef = useRef29(null);
|
|
18487
|
+
const transitionTo = useCallback17((level, opts = {}) => {
|
|
18180
18488
|
const { duration = 0.4, type = "fade" } = opts;
|
|
18181
18489
|
if (type === "instant") {
|
|
18182
18490
|
setCurrentLevel(level);
|
|
@@ -18213,13 +18521,13 @@ function useLevelTransition(initial) {
|
|
|
18213
18521
|
}
|
|
18214
18522
|
|
|
18215
18523
|
// ../gameplay/src/hooks/usePlatformerController.ts
|
|
18216
|
-
import { useContext as
|
|
18524
|
+
import { useContext as useContext59, useEffect as useEffect65 } from "react";
|
|
18217
18525
|
function normalizeKeys(val, defaults) {
|
|
18218
18526
|
if (!val) return defaults;
|
|
18219
18527
|
return Array.isArray(val) ? val : [val];
|
|
18220
18528
|
}
|
|
18221
18529
|
function usePlatformerController(entityId, opts = {}) {
|
|
18222
|
-
const engine =
|
|
18530
|
+
const engine = useContext59(EngineContext);
|
|
18223
18531
|
const {
|
|
18224
18532
|
speed = 200,
|
|
18225
18533
|
jumpForce = -500,
|
|
@@ -18227,6 +18535,9 @@ function usePlatformerController(entityId, opts = {}) {
|
|
|
18227
18535
|
coyoteTime = 0.08,
|
|
18228
18536
|
jumpBuffer = 0.08,
|
|
18229
18537
|
jumpCooldown = 0.18,
|
|
18538
|
+
acceleration = Infinity,
|
|
18539
|
+
groundFriction = 0.6,
|
|
18540
|
+
airFriction = 0.92,
|
|
18230
18541
|
gamepadIndex = 0,
|
|
18231
18542
|
gamepadDeadZone = 0.2,
|
|
18232
18543
|
bindings
|
|
@@ -18234,7 +18545,7 @@ function usePlatformerController(entityId, opts = {}) {
|
|
|
18234
18545
|
const leftKeys = normalizeKeys(bindings?.left, ["ArrowLeft", "KeyA", "a"]);
|
|
18235
18546
|
const rightKeys = normalizeKeys(bindings?.right, ["ArrowRight", "KeyD", "d"]);
|
|
18236
18547
|
const jumpKeys = normalizeKeys(bindings?.jump, ["Space", "ArrowUp", "KeyW", "w"]);
|
|
18237
|
-
|
|
18548
|
+
useEffect65(() => {
|
|
18238
18549
|
const state = {
|
|
18239
18550
|
coyoteTimer: 0,
|
|
18240
18551
|
jumpBuffer: 0,
|
|
@@ -18264,9 +18575,18 @@ function usePlatformerController(entityId, opts = {}) {
|
|
|
18264
18575
|
else if (!jumpKeys.some((k) => input.isDown(k)) && !gpJump) state.jumpBuffer = Math.max(0, state.jumpBuffer - dt);
|
|
18265
18576
|
const left = leftKeys.some((k) => input.isDown(k)) || gpLeft;
|
|
18266
18577
|
const right = rightKeys.some((k) => input.isDown(k)) || gpRight;
|
|
18267
|
-
if (left
|
|
18268
|
-
|
|
18269
|
-
|
|
18578
|
+
if (left || right) {
|
|
18579
|
+
const targetVx = left ? -speed : speed;
|
|
18580
|
+
if (acceleration === Infinity) {
|
|
18581
|
+
rb.vx = targetVx;
|
|
18582
|
+
} else {
|
|
18583
|
+
const diff = targetVx - rb.vx;
|
|
18584
|
+
const maxDelta = acceleration * dt;
|
|
18585
|
+
rb.vx += Math.abs(diff) <= maxDelta ? diff : Math.sign(diff) * maxDelta;
|
|
18586
|
+
}
|
|
18587
|
+
} else {
|
|
18588
|
+
rb.vx *= rb.onGround ? groundFriction : airFriction;
|
|
18589
|
+
}
|
|
18270
18590
|
const sprite = world.getComponent(id, "Sprite");
|
|
18271
18591
|
if (sprite) {
|
|
18272
18592
|
if (left) sprite.flipX = true;
|
|
@@ -18289,26 +18609,26 @@ function usePlatformerController(entityId, opts = {}) {
|
|
|
18289
18609
|
}
|
|
18290
18610
|
|
|
18291
18611
|
// ../gameplay/src/hooks/usePathfinding.ts
|
|
18292
|
-
import { useCallback as
|
|
18612
|
+
import { useCallback as useCallback18 } from "react";
|
|
18293
18613
|
function usePathfinding() {
|
|
18294
|
-
const createGrid$ =
|
|
18614
|
+
const createGrid$ = useCallback18(
|
|
18295
18615
|
(cols, rows, cellSize) => createNavGrid(cols, rows, cellSize),
|
|
18296
18616
|
[]
|
|
18297
18617
|
);
|
|
18298
|
-
const setWalkable$ =
|
|
18618
|
+
const setWalkable$ = useCallback18(
|
|
18299
18619
|
(grid, col, row, walkable) => setWalkable(grid, col, row, walkable),
|
|
18300
18620
|
[]
|
|
18301
18621
|
);
|
|
18302
|
-
const findPath$ =
|
|
18622
|
+
const findPath$ = useCallback18((grid, start, goal) => findPath(grid, start, goal), []);
|
|
18303
18623
|
return { createGrid: createGrid$, setWalkable: setWalkable$, findPath: findPath$ };
|
|
18304
18624
|
}
|
|
18305
18625
|
|
|
18306
18626
|
// ../gameplay/src/hooks/usePersistedBindings.ts
|
|
18307
|
-
import { useState as
|
|
18627
|
+
import { useState as useState17, useCallback as useCallback19, useMemo as useMemo12, useContext as useContext60 } from "react";
|
|
18308
18628
|
function usePersistedBindings(storageKey, defaults) {
|
|
18309
|
-
const engine =
|
|
18629
|
+
const engine = useContext60(EngineContext);
|
|
18310
18630
|
const input = engine.input;
|
|
18311
|
-
const [bindings, setBindings] =
|
|
18631
|
+
const [bindings, setBindings] = useState17(() => {
|
|
18312
18632
|
try {
|
|
18313
18633
|
const stored = localStorage.getItem(storageKey);
|
|
18314
18634
|
if (stored) return { ...defaults, ...JSON.parse(stored) };
|
|
@@ -18324,7 +18644,7 @@ function usePersistedBindings(storageKey, defaults) {
|
|
|
18324
18644
|
}
|
|
18325
18645
|
return out;
|
|
18326
18646
|
}, [bindings]);
|
|
18327
|
-
const rebind =
|
|
18647
|
+
const rebind = useCallback19(
|
|
18328
18648
|
(action, keys) => {
|
|
18329
18649
|
setBindings((prev) => {
|
|
18330
18650
|
const next = { ...prev, [action]: Array.isArray(keys) ? keys : [keys] };
|
|
@@ -18337,7 +18657,7 @@ function usePersistedBindings(storageKey, defaults) {
|
|
|
18337
18657
|
},
|
|
18338
18658
|
[storageKey]
|
|
18339
18659
|
);
|
|
18340
|
-
const reset =
|
|
18660
|
+
const reset = useCallback19(() => {
|
|
18341
18661
|
try {
|
|
18342
18662
|
localStorage.removeItem(storageKey);
|
|
18343
18663
|
} catch {
|
|
@@ -18358,21 +18678,21 @@ function usePersistedBindings(storageKey, defaults) {
|
|
|
18358
18678
|
}
|
|
18359
18679
|
|
|
18360
18680
|
// ../gameplay/src/hooks/useRestart.ts
|
|
18361
|
-
import { useState as
|
|
18681
|
+
import { useState as useState18, useCallback as useCallback20 } from "react";
|
|
18362
18682
|
function useRestart() {
|
|
18363
|
-
const [restartKey, setRestartKey] =
|
|
18364
|
-
const restart =
|
|
18683
|
+
const [restartKey, setRestartKey] = useState18(0);
|
|
18684
|
+
const restart = useCallback20(() => {
|
|
18365
18685
|
setRestartKey((k) => k + 1);
|
|
18366
18686
|
}, []);
|
|
18367
18687
|
return { restartKey, restart };
|
|
18368
18688
|
}
|
|
18369
18689
|
|
|
18370
18690
|
// ../gameplay/src/hooks/useSave.ts
|
|
18371
|
-
import { useCallback as
|
|
18691
|
+
import { useCallback as useCallback21, useRef as useRef30 } from "react";
|
|
18372
18692
|
function useSave(key, defaultValue, opts = {}) {
|
|
18373
18693
|
const version = opts.version ?? 1;
|
|
18374
|
-
const dataRef =
|
|
18375
|
-
const save =
|
|
18694
|
+
const dataRef = useRef30(defaultValue);
|
|
18695
|
+
const save = useCallback21(
|
|
18376
18696
|
(value) => {
|
|
18377
18697
|
dataRef.current = value;
|
|
18378
18698
|
const slot = { version, data: value };
|
|
@@ -18384,7 +18704,7 @@ function useSave(key, defaultValue, opts = {}) {
|
|
|
18384
18704
|
},
|
|
18385
18705
|
[key, version]
|
|
18386
18706
|
);
|
|
18387
|
-
const load =
|
|
18707
|
+
const load = useCallback21(() => {
|
|
18388
18708
|
try {
|
|
18389
18709
|
const raw = localStorage.getItem(key);
|
|
18390
18710
|
if (!raw) return defaultValue;
|
|
@@ -18404,11 +18724,11 @@ function useSave(key, defaultValue, opts = {}) {
|
|
|
18404
18724
|
return defaultValue;
|
|
18405
18725
|
}
|
|
18406
18726
|
}, [key, version]);
|
|
18407
|
-
const clear =
|
|
18727
|
+
const clear = useCallback21(() => {
|
|
18408
18728
|
localStorage.removeItem(key);
|
|
18409
18729
|
dataRef.current = defaultValue;
|
|
18410
18730
|
}, [key]);
|
|
18411
|
-
const exists =
|
|
18731
|
+
const exists = useCallback21(() => {
|
|
18412
18732
|
return localStorage.getItem(key) !== null;
|
|
18413
18733
|
}, [key]);
|
|
18414
18734
|
return {
|
|
@@ -18423,7 +18743,7 @@ function useSave(key, defaultValue, opts = {}) {
|
|
|
18423
18743
|
}
|
|
18424
18744
|
|
|
18425
18745
|
// ../gameplay/src/hooks/useIDBSave.ts
|
|
18426
|
-
import { useCallback as
|
|
18746
|
+
import { useCallback as useCallback22, useRef as useRef31 } from "react";
|
|
18427
18747
|
var DB_NAME = "cubeforge-saves";
|
|
18428
18748
|
var STORE_NAME = "saves";
|
|
18429
18749
|
function openDB() {
|
|
@@ -18441,12 +18761,12 @@ function openDB() {
|
|
|
18441
18761
|
}
|
|
18442
18762
|
function useIDBSave(key, defaultValue, opts = {}) {
|
|
18443
18763
|
const version = opts.version ?? 1;
|
|
18444
|
-
const dbRef =
|
|
18445
|
-
const getDB =
|
|
18764
|
+
const dbRef = useRef31(null);
|
|
18765
|
+
const getDB = useCallback22(() => {
|
|
18446
18766
|
if (!dbRef.current) dbRef.current = openDB();
|
|
18447
18767
|
return dbRef.current;
|
|
18448
18768
|
}, []);
|
|
18449
|
-
const save =
|
|
18769
|
+
const save = useCallback22(
|
|
18450
18770
|
async (value) => {
|
|
18451
18771
|
const db = await getDB();
|
|
18452
18772
|
const slot = { version, data: value };
|
|
@@ -18459,7 +18779,7 @@ function useIDBSave(key, defaultValue, opts = {}) {
|
|
|
18459
18779
|
},
|
|
18460
18780
|
[getDB, key, version]
|
|
18461
18781
|
);
|
|
18462
|
-
const load =
|
|
18782
|
+
const load = useCallback22(async () => {
|
|
18463
18783
|
const db = await getDB();
|
|
18464
18784
|
return new Promise((resolve, reject) => {
|
|
18465
18785
|
const tx = db.transaction(STORE_NAME, "readonly");
|
|
@@ -18485,7 +18805,7 @@ function useIDBSave(key, defaultValue, opts = {}) {
|
|
|
18485
18805
|
req.onerror = () => reject(req.error);
|
|
18486
18806
|
});
|
|
18487
18807
|
}, [getDB, key, version]);
|
|
18488
|
-
const clear =
|
|
18808
|
+
const clear = useCallback22(async () => {
|
|
18489
18809
|
const db = await getDB();
|
|
18490
18810
|
return new Promise((resolve, reject) => {
|
|
18491
18811
|
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
@@ -18494,7 +18814,7 @@ function useIDBSave(key, defaultValue, opts = {}) {
|
|
|
18494
18814
|
req.onerror = () => reject(req.error);
|
|
18495
18815
|
});
|
|
18496
18816
|
}, [getDB, key]);
|
|
18497
|
-
const exists =
|
|
18817
|
+
const exists = useCallback22(async () => {
|
|
18498
18818
|
const db = await getDB();
|
|
18499
18819
|
return new Promise((resolve, reject) => {
|
|
18500
18820
|
const tx = db.transaction(STORE_NAME, "readonly");
|
|
@@ -18507,12 +18827,17 @@ function useIDBSave(key, defaultValue, opts = {}) {
|
|
|
18507
18827
|
}
|
|
18508
18828
|
|
|
18509
18829
|
// ../gameplay/src/hooks/useTopDownMovement.ts
|
|
18510
|
-
import { useContext as
|
|
18830
|
+
import { useContext as useContext61, useEffect as useEffect66 } from "react";
|
|
18831
|
+
function moveToward(current, target, maxDelta) {
|
|
18832
|
+
const diff = target - current;
|
|
18833
|
+
if (Math.abs(diff) <= maxDelta) return target;
|
|
18834
|
+
return current + Math.sign(diff) * maxDelta;
|
|
18835
|
+
}
|
|
18511
18836
|
function useTopDownMovement(entityId, opts = {}) {
|
|
18512
|
-
const engine =
|
|
18513
|
-
const { speed = 200, normalizeDiagonal = true } = opts;
|
|
18514
|
-
|
|
18515
|
-
const updateFn = (id, world, input) => {
|
|
18837
|
+
const engine = useContext61(EngineContext);
|
|
18838
|
+
const { speed = 200, normalizeDiagonal = true, acceleration = Infinity, deceleration = acceleration } = opts;
|
|
18839
|
+
useEffect66(() => {
|
|
18840
|
+
const updateFn = (id, world, input, dt) => {
|
|
18516
18841
|
if (!world.hasEntity(id)) return;
|
|
18517
18842
|
const rb = world.getComponent(id, "RigidBody");
|
|
18518
18843
|
if (!rb) return;
|
|
@@ -18527,8 +18852,23 @@ function useTopDownMovement(entityId, opts = {}) {
|
|
|
18527
18852
|
dx /= len2;
|
|
18528
18853
|
dy /= len2;
|
|
18529
18854
|
}
|
|
18530
|
-
|
|
18531
|
-
|
|
18855
|
+
const targetVx = dx * speed;
|
|
18856
|
+
const targetVy = dy * speed;
|
|
18857
|
+
if (acceleration === Infinity && deceleration === Infinity) {
|
|
18858
|
+
rb.vx = targetVx;
|
|
18859
|
+
rb.vy = targetVy;
|
|
18860
|
+
} else {
|
|
18861
|
+
const hasInput = dx !== 0 || dy !== 0;
|
|
18862
|
+
const rate = hasInput ? acceleration : deceleration;
|
|
18863
|
+
if (rate === Infinity) {
|
|
18864
|
+
rb.vx = targetVx;
|
|
18865
|
+
rb.vy = targetVy;
|
|
18866
|
+
} else {
|
|
18867
|
+
const maxDelta = rate * dt;
|
|
18868
|
+
rb.vx = moveToward(rb.vx, targetVx, maxDelta);
|
|
18869
|
+
rb.vy = moveToward(rb.vy, targetVy, maxDelta);
|
|
18870
|
+
}
|
|
18871
|
+
}
|
|
18532
18872
|
};
|
|
18533
18873
|
engine.ecs.addComponent(entityId, createScript(updateFn));
|
|
18534
18874
|
return () => engine.ecs.removeComponent(entityId, "Script");
|
|
@@ -18536,18 +18876,18 @@ function useTopDownMovement(entityId, opts = {}) {
|
|
|
18536
18876
|
}
|
|
18537
18877
|
|
|
18538
18878
|
// ../gameplay/src/hooks/useDialogue.ts
|
|
18539
|
-
import { useState as
|
|
18879
|
+
import { useState as useState19, useCallback as useCallback23, useRef as useRef32 } from "react";
|
|
18540
18880
|
function useDialogue() {
|
|
18541
|
-
const [active, setActive] =
|
|
18542
|
-
const [currentId, setCurrentId] =
|
|
18543
|
-
const scriptRef =
|
|
18544
|
-
const start =
|
|
18881
|
+
const [active, setActive] = useState19(false);
|
|
18882
|
+
const [currentId, setCurrentId] = useState19(null);
|
|
18883
|
+
const scriptRef = useRef32(null);
|
|
18884
|
+
const start = useCallback23((script, startId) => {
|
|
18545
18885
|
scriptRef.current = script;
|
|
18546
18886
|
const id = startId ?? Object.keys(script)[0];
|
|
18547
18887
|
setCurrentId(id);
|
|
18548
18888
|
setActive(true);
|
|
18549
18889
|
}, []);
|
|
18550
|
-
const advance =
|
|
18890
|
+
const advance = useCallback23(
|
|
18551
18891
|
(choiceIndex) => {
|
|
18552
18892
|
if (!scriptRef.current || !currentId) return;
|
|
18553
18893
|
const line = scriptRef.current[currentId];
|
|
@@ -18577,7 +18917,7 @@ function useDialogue() {
|
|
|
18577
18917
|
},
|
|
18578
18918
|
[currentId]
|
|
18579
18919
|
);
|
|
18580
|
-
const close =
|
|
18920
|
+
const close = useCallback23(() => {
|
|
18581
18921
|
setActive(false);
|
|
18582
18922
|
setCurrentId(null);
|
|
18583
18923
|
scriptRef.current = null;
|
|
@@ -18695,17 +19035,17 @@ function DialogueBox({ dialogue, onAdvance, onClose, style = {} }) {
|
|
|
18695
19035
|
}
|
|
18696
19036
|
|
|
18697
19037
|
// ../gameplay/src/hooks/useCutscene.ts
|
|
18698
|
-
import { useState as
|
|
19038
|
+
import { useState as useState20, useCallback as useCallback24, useRef as useRef33, useEffect as useEffect67, useContext as useContext62 } from "react";
|
|
18699
19039
|
function useCutscene() {
|
|
18700
|
-
const engine =
|
|
18701
|
-
const [playing, setPlaying] =
|
|
18702
|
-
const [stepIndex, setStepIndex] =
|
|
18703
|
-
const stepsRef =
|
|
18704
|
-
const timerRef =
|
|
18705
|
-
const idxRef =
|
|
18706
|
-
const playingRef =
|
|
18707
|
-
const entityRef =
|
|
18708
|
-
const finish =
|
|
19040
|
+
const engine = useContext62(EngineContext);
|
|
19041
|
+
const [playing, setPlaying] = useState20(false);
|
|
19042
|
+
const [stepIndex, setStepIndex] = useState20(0);
|
|
19043
|
+
const stepsRef = useRef33([]);
|
|
19044
|
+
const timerRef = useRef33(0);
|
|
19045
|
+
const idxRef = useRef33(0);
|
|
19046
|
+
const playingRef = useRef33(false);
|
|
19047
|
+
const entityRef = useRef33(null);
|
|
19048
|
+
const finish = useCallback24(() => {
|
|
18709
19049
|
playingRef.current = false;
|
|
18710
19050
|
setPlaying(false);
|
|
18711
19051
|
setStepIndex(0);
|
|
@@ -18715,14 +19055,14 @@ function useCutscene() {
|
|
|
18715
19055
|
entityRef.current = null;
|
|
18716
19056
|
}
|
|
18717
19057
|
}, [engine.ecs]);
|
|
18718
|
-
const fireStep =
|
|
19058
|
+
const fireStep = useCallback24((step) => {
|
|
18719
19059
|
if (step.type === "call") step.fn();
|
|
18720
19060
|
if (step.type === "parallel")
|
|
18721
19061
|
step.steps.forEach((s2) => {
|
|
18722
19062
|
if (s2.type === "call") s2.fn();
|
|
18723
19063
|
});
|
|
18724
19064
|
}, []);
|
|
18725
|
-
const play =
|
|
19065
|
+
const play = useCallback24(
|
|
18726
19066
|
(steps) => {
|
|
18727
19067
|
stepsRef.current = steps;
|
|
18728
19068
|
idxRef.current = 0;
|
|
@@ -18779,7 +19119,7 @@ function useCutscene() {
|
|
|
18779
19119
|
},
|
|
18780
19120
|
[engine.ecs, finish, fireStep]
|
|
18781
19121
|
);
|
|
18782
|
-
const skip =
|
|
19122
|
+
const skip = useCallback24(() => {
|
|
18783
19123
|
for (let i = idxRef.current; i < stepsRef.current.length; i++) {
|
|
18784
19124
|
const step = stepsRef.current[i];
|
|
18785
19125
|
if (step.type === "call") step.fn();
|
|
@@ -18790,7 +19130,7 @@ function useCutscene() {
|
|
|
18790
19130
|
}
|
|
18791
19131
|
finish();
|
|
18792
19132
|
}, [finish]);
|
|
18793
|
-
|
|
19133
|
+
useEffect67(() => {
|
|
18794
19134
|
return () => {
|
|
18795
19135
|
if (entityRef.current !== null && engine.ecs.hasEntity(entityRef.current)) {
|
|
18796
19136
|
engine.ecs.destroyEntity(entityRef.current);
|
|
@@ -18801,7 +19141,7 @@ function useCutscene() {
|
|
|
18801
19141
|
}
|
|
18802
19142
|
|
|
18803
19143
|
// ../gameplay/src/hooks/useGameStore.ts
|
|
18804
|
-
import { useSyncExternalStore as useSyncExternalStore2, useCallback as
|
|
19144
|
+
import { useSyncExternalStore as useSyncExternalStore2, useCallback as useCallback25 } from "react";
|
|
18805
19145
|
function createStore(initialState) {
|
|
18806
19146
|
let state = { ...initialState };
|
|
18807
19147
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -18827,7 +19167,7 @@ function useGameStore(key, initialState) {
|
|
|
18827
19167
|
}
|
|
18828
19168
|
const store = stores.get(key);
|
|
18829
19169
|
const state = useSyncExternalStore2(store.subscribe, store.getState);
|
|
18830
|
-
const setState =
|
|
19170
|
+
const setState = useCallback25(
|
|
18831
19171
|
(partial) => {
|
|
18832
19172
|
store.setState(partial);
|
|
18833
19173
|
},
|
|
@@ -18837,21 +19177,21 @@ function useGameStore(key, initialState) {
|
|
|
18837
19177
|
}
|
|
18838
19178
|
|
|
18839
19179
|
// ../gameplay/src/hooks/useTween.ts
|
|
18840
|
-
import { useRef as
|
|
19180
|
+
import { useRef as useRef34, useCallback as useCallback26, useEffect as useEffect68 } from "react";
|
|
18841
19181
|
function useTween(opts) {
|
|
18842
|
-
const rafRef =
|
|
18843
|
-
const startTimeRef =
|
|
18844
|
-
const runningRef =
|
|
18845
|
-
const optsRef =
|
|
19182
|
+
const rafRef = useRef34(null);
|
|
19183
|
+
const startTimeRef = useRef34(0);
|
|
19184
|
+
const runningRef = useRef34(false);
|
|
19185
|
+
const optsRef = useRef34(opts);
|
|
18846
19186
|
optsRef.current = opts;
|
|
18847
|
-
const stop =
|
|
19187
|
+
const stop = useCallback26(() => {
|
|
18848
19188
|
if (rafRef.current !== null) {
|
|
18849
19189
|
cancelAnimationFrame(rafRef.current);
|
|
18850
19190
|
rafRef.current = null;
|
|
18851
19191
|
}
|
|
18852
19192
|
runningRef.current = false;
|
|
18853
19193
|
}, []);
|
|
18854
|
-
const start =
|
|
19194
|
+
const start = useCallback26(() => {
|
|
18855
19195
|
stop();
|
|
18856
19196
|
runningRef.current = true;
|
|
18857
19197
|
startTimeRef.current = performance.now();
|
|
@@ -18873,12 +19213,12 @@ function useTween(opts) {
|
|
|
18873
19213
|
};
|
|
18874
19214
|
rafRef.current = requestAnimationFrame(tick);
|
|
18875
19215
|
}, [stop]);
|
|
18876
|
-
|
|
19216
|
+
useEffect68(() => {
|
|
18877
19217
|
if (opts.autoStart) {
|
|
18878
19218
|
start();
|
|
18879
19219
|
}
|
|
18880
19220
|
}, []);
|
|
18881
|
-
|
|
19221
|
+
useEffect68(() => {
|
|
18882
19222
|
return () => {
|
|
18883
19223
|
if (rafRef.current !== null) {
|
|
18884
19224
|
cancelAnimationFrame(rafRef.current);
|
|
@@ -18897,15 +19237,15 @@ function useTween(opts) {
|
|
|
18897
19237
|
}
|
|
18898
19238
|
|
|
18899
19239
|
// ../gameplay/src/hooks/useObjectPool.ts
|
|
18900
|
-
import { useRef as
|
|
19240
|
+
import { useRef as useRef35, useMemo as useMemo13, useEffect as useEffect69 } from "react";
|
|
18901
19241
|
function useObjectPool(factory, reset, initialSize) {
|
|
18902
|
-
const poolRef =
|
|
18903
|
-
const activeRef =
|
|
18904
|
-
const factoryRef =
|
|
19242
|
+
const poolRef = useRef35([]);
|
|
19243
|
+
const activeRef = useRef35(0);
|
|
19244
|
+
const factoryRef = useRef35(factory);
|
|
18905
19245
|
factoryRef.current = factory;
|
|
18906
|
-
const resetRef =
|
|
19246
|
+
const resetRef = useRef35(reset);
|
|
18907
19247
|
resetRef.current = reset;
|
|
18908
|
-
|
|
19248
|
+
useEffect69(() => {
|
|
18909
19249
|
if (initialSize != null && initialSize > 0) {
|
|
18910
19250
|
const pool = poolRef.current;
|
|
18911
19251
|
for (let i = 0; i < initialSize; i++) {
|
|
@@ -18944,10 +19284,10 @@ function useObjectPool(factory, reset, initialSize) {
|
|
|
18944
19284
|
}
|
|
18945
19285
|
|
|
18946
19286
|
// ../gameplay/src/hooks/useForces.ts
|
|
18947
|
-
import { useContext as
|
|
19287
|
+
import { useContext as useContext63, useMemo as useMemo14 } from "react";
|
|
18948
19288
|
function useForces() {
|
|
18949
|
-
const engine =
|
|
18950
|
-
const entityId =
|
|
19289
|
+
const engine = useContext63(EngineContext);
|
|
19290
|
+
const entityId = useContext63(EntityContext);
|
|
18951
19291
|
return useMemo14(() => {
|
|
18952
19292
|
const getRb = () => engine.ecs.getComponent(entityId, "RigidBody");
|
|
18953
19293
|
const getTransform = () => engine.ecs.getComponent(entityId, "Transform");
|
|
@@ -19016,10 +19356,10 @@ function useForces() {
|
|
|
19016
19356
|
}
|
|
19017
19357
|
|
|
19018
19358
|
// ../gameplay/src/hooks/useCharacterController.ts
|
|
19019
|
-
import { useContext as
|
|
19359
|
+
import { useContext as useContext64, useMemo as useMemo15 } from "react";
|
|
19020
19360
|
function useCharacterController(config = {}) {
|
|
19021
|
-
const engine =
|
|
19022
|
-
const entityId =
|
|
19361
|
+
const engine = useContext64(EngineContext);
|
|
19362
|
+
const entityId = useContext64(EntityContext);
|
|
19023
19363
|
return useMemo15(() => {
|
|
19024
19364
|
const controller = new CharacterController(config);
|
|
19025
19365
|
return {
|
|
@@ -19069,7 +19409,7 @@ function definePrefab(name, defaults, render) {
|
|
|
19069
19409
|
}
|
|
19070
19410
|
|
|
19071
19411
|
// src/hooks/useNetworkSync.ts
|
|
19072
|
-
import { useEffect as
|
|
19412
|
+
import { useEffect as useEffect71, useRef as useRef37 } from "react";
|
|
19073
19413
|
|
|
19074
19414
|
// ../../packages/net/src/transport.ts
|
|
19075
19415
|
function isBinaryTransport(t) {
|
|
@@ -19414,17 +19754,17 @@ function syncEntity(config) {
|
|
|
19414
19754
|
}
|
|
19415
19755
|
|
|
19416
19756
|
// ../../packages/net/src/useNetworkInput.ts
|
|
19417
|
-
import { useState as
|
|
19757
|
+
import { useState as useState21, useEffect as useEffect70, useRef as useRef36 } from "react";
|
|
19418
19758
|
var INPUT_MSG_TYPE = "input:state";
|
|
19419
19759
|
function useNetworkInput(config) {
|
|
19420
19760
|
const { room, keys, input, tickRate = 20 } = config;
|
|
19421
19761
|
const intervalMs = 1e3 / tickRate;
|
|
19422
|
-
const [localInput, setLocalInput] =
|
|
19762
|
+
const [localInput, setLocalInput] = useState21(
|
|
19423
19763
|
() => Object.fromEntries(keys.map((k) => [k, false]))
|
|
19424
19764
|
);
|
|
19425
|
-
const [remoteInputs] =
|
|
19426
|
-
const localInputRef =
|
|
19427
|
-
|
|
19765
|
+
const [remoteInputs] = useState21(() => /* @__PURE__ */ new Map());
|
|
19766
|
+
const localInputRef = useRef36(localInput);
|
|
19767
|
+
useEffect70(() => {
|
|
19428
19768
|
let cleanupDom = null;
|
|
19429
19769
|
if (!input) {
|
|
19430
19770
|
let handleKeyDown2 = function(e) {
|
|
@@ -19638,9 +19978,9 @@ function lerpState(a, b, t) {
|
|
|
19638
19978
|
|
|
19639
19979
|
// src/hooks/useNetworkSync.ts
|
|
19640
19980
|
function useNetworkSync(entityId, components, room, world, owner, opts = {}) {
|
|
19641
|
-
const optsRef =
|
|
19981
|
+
const optsRef = useRef37(opts);
|
|
19642
19982
|
optsRef.current = opts;
|
|
19643
|
-
|
|
19983
|
+
useEffect71(() => {
|
|
19644
19984
|
const sync = syncEntity({
|
|
19645
19985
|
entityId,
|
|
19646
19986
|
components,
|
|
@@ -19655,18 +19995,18 @@ function useNetworkSync(entityId, components, room, world, owner, opts = {}) {
|
|
|
19655
19995
|
}
|
|
19656
19996
|
|
|
19657
19997
|
// src/hooks/useRemotePlayer.ts
|
|
19658
|
-
import { useEffect as
|
|
19998
|
+
import { useEffect as useEffect72, useRef as useRef38, useState as useState22 } from "react";
|
|
19659
19999
|
var PEER_JOIN_MSG = "peer:join";
|
|
19660
20000
|
var PEER_LEAVE_MSG = "peer:leave";
|
|
19661
20001
|
function useRemotePlayer(config) {
|
|
19662
20002
|
const { room, world, createEntity, destroyEntity } = config;
|
|
19663
|
-
const [players, setPlayers] =
|
|
19664
|
-
const playersRef =
|
|
19665
|
-
const createRef =
|
|
20003
|
+
const [players, setPlayers] = useState22(() => /* @__PURE__ */ new Map());
|
|
20004
|
+
const playersRef = useRef38(players);
|
|
20005
|
+
const createRef = useRef38(createEntity);
|
|
19666
20006
|
createRef.current = createEntity;
|
|
19667
|
-
const destroyRef =
|
|
20007
|
+
const destroyRef = useRef38(destroyEntity);
|
|
19668
20008
|
destroyRef.current = destroyEntity;
|
|
19669
|
-
|
|
20009
|
+
useEffect72(() => {
|
|
19670
20010
|
function spawnPeer(peerId) {
|
|
19671
20011
|
if (playersRef.current.has(peerId)) return;
|
|
19672
20012
|
const entityId = createRef.current(peerId);
|
|
@@ -19756,6 +20096,7 @@ export {
|
|
|
19756
20096
|
RenderSystem,
|
|
19757
20097
|
RigidBody,
|
|
19758
20098
|
Room,
|
|
20099
|
+
SceneTransitionOverlay,
|
|
19759
20100
|
ScreenFlash,
|
|
19760
20101
|
Script,
|
|
19761
20102
|
SegmentCollider,
|
|
@@ -19953,6 +20294,7 @@ export {
|
|
|
19953
20294
|
useGestures,
|
|
19954
20295
|
useHMR,
|
|
19955
20296
|
useHealth,
|
|
20297
|
+
useHitstop,
|
|
19956
20298
|
useIDBSave,
|
|
19957
20299
|
useInput,
|
|
19958
20300
|
useInputBuffer,
|
|
@@ -19980,6 +20322,7 @@ export {
|
|
|
19980
20322
|
useRestart,
|
|
19981
20323
|
useSave,
|
|
19982
20324
|
useSceneManager,
|
|
20325
|
+
useSceneTransition,
|
|
19983
20326
|
useSnapshot,
|
|
19984
20327
|
useSound,
|
|
19985
20328
|
useSpatialSound,
|