@adatechnology/game-interactables 0.7.0 → 0.9.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/README.md +10 -0
- package/dist/index.d.ts +87 -1
- package/dist/index.global.js +124 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +124 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -183,6 +183,8 @@ var locales = {
|
|
|
183
183
|
"prompt.read": "Read",
|
|
184
184
|
"prompt.breaker_on": "Switch on {circuit}",
|
|
185
185
|
"prompt.breaker_off": "Switch off {circuit}",
|
|
186
|
+
"prompt.main_on": "Switch on the main breaker",
|
|
187
|
+
"prompt.main_off": "Switch off the main breaker",
|
|
186
188
|
"prompt.open_valve": "Open valve",
|
|
187
189
|
"prompt.close_valve": "Close valve",
|
|
188
190
|
no_power: "No power",
|
|
@@ -234,6 +236,8 @@ var locales = {
|
|
|
234
236
|
"prompt.read": "Ler",
|
|
235
237
|
"prompt.breaker_on": "Ligar {circuit}",
|
|
236
238
|
"prompt.breaker_off": "Desligar {circuit}",
|
|
239
|
+
"prompt.main_on": "Ligar o disjuntor geral",
|
|
240
|
+
"prompt.main_off": "Desligar o disjuntor geral",
|
|
237
241
|
"prompt.open_valve": "Abrir registro",
|
|
238
242
|
"prompt.close_valve": "Fechar registro",
|
|
239
243
|
no_power: "Sem energia",
|
|
@@ -369,6 +373,7 @@ function createWorld(options = {}) {
|
|
|
369
373
|
let locale = options.locale ?? "en";
|
|
370
374
|
let table = resolveStrings(locale, options.strings);
|
|
371
375
|
let grid = options.grid ?? true;
|
|
376
|
+
let main = true;
|
|
372
377
|
let rain = options.rain ?? 0;
|
|
373
378
|
let wind = options.wind ? [options.wind[0], options.wind[1]] : [0, 0];
|
|
374
379
|
let defaultTank = null;
|
|
@@ -717,7 +722,7 @@ function createWorld(options = {}) {
|
|
|
717
722
|
}
|
|
718
723
|
function devicePowered(o, d) {
|
|
719
724
|
if (d.spec.electric === false) return true;
|
|
720
|
-
if (!grid) return false;
|
|
725
|
+
if (!grid || !main) return false;
|
|
721
726
|
if (d.spec.circuit) return breaker(d.spec.circuit);
|
|
722
727
|
if (d.spec.socket === void 0) return false;
|
|
723
728
|
const sid = plugs.get(gid(o, d.spec.id));
|
|
@@ -1185,6 +1190,11 @@ function createWorld(options = {}) {
|
|
|
1185
1190
|
def = on ? "prompt.breaker_off" : "prompt.breaker_on";
|
|
1186
1191
|
break;
|
|
1187
1192
|
}
|
|
1193
|
+
case "toggle_main": {
|
|
1194
|
+
state = main ? "on" : "off";
|
|
1195
|
+
def = main ? "prompt.main_off" : "prompt.main_on";
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1188
1198
|
case "toggle_fixture": {
|
|
1189
1199
|
const on = !!o.fixtures.get(a.fixture)?.on;
|
|
1190
1200
|
state = on ? "on" : "off";
|
|
@@ -1256,7 +1266,8 @@ function createWorld(options = {}) {
|
|
|
1256
1266
|
const p = c?.access ? o.parts.get(c.access) : void 0;
|
|
1257
1267
|
return p && gated(o, p) ? "requires_open" : null;
|
|
1258
1268
|
}
|
|
1259
|
-
case "toggle_breaker":
|
|
1269
|
+
case "toggle_breaker":
|
|
1270
|
+
case "toggle_main": {
|
|
1260
1271
|
const rocker = a.part ? o.parts.get(a.part) : void 0;
|
|
1261
1272
|
return rocker && gated(o, rocker) ? "requires_open" : null;
|
|
1262
1273
|
}
|
|
@@ -1464,6 +1475,14 @@ function createWorld(options = {}) {
|
|
|
1464
1475
|
world.power.setBreaker(a.circuit, on);
|
|
1465
1476
|
return true;
|
|
1466
1477
|
}
|
|
1478
|
+
case "toggle_main": {
|
|
1479
|
+
const rocker = a.part ? o.parts.get(a.part) : void 0;
|
|
1480
|
+
if (rocker && gated(o, rocker)) return false;
|
|
1481
|
+
const on = !main;
|
|
1482
|
+
if (a.part) setPartTarget(o, a.part, on ? 1 : 0);
|
|
1483
|
+
world.power.setMain(on);
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1467
1486
|
case "toggle_fixture":
|
|
1468
1487
|
return toggleFixture(o, a.fixture);
|
|
1469
1488
|
case "toggle_burner":
|
|
@@ -1731,6 +1750,7 @@ function createWorld(options = {}) {
|
|
|
1731
1750
|
version: 1,
|
|
1732
1751
|
objects,
|
|
1733
1752
|
grid,
|
|
1753
|
+
main,
|
|
1734
1754
|
breakers: Object.fromEntries(breakers),
|
|
1735
1755
|
seats: Object.fromEntries([...seats].map(([a, s]) => [a, { object: s.object, seat: s.seat }])),
|
|
1736
1756
|
defaultTank
|
|
@@ -1791,6 +1811,7 @@ function createWorld(options = {}) {
|
|
|
1791
1811
|
}
|
|
1792
1812
|
}
|
|
1793
1813
|
grid = state.grid;
|
|
1814
|
+
main = state.main ?? true;
|
|
1794
1815
|
breakers.clear();
|
|
1795
1816
|
for (const [k, v] of Object.entries(state.breakers)) breakers.set(k, v);
|
|
1796
1817
|
seats.clear();
|
|
@@ -1832,7 +1853,17 @@ function createWorld(options = {}) {
|
|
|
1832
1853
|
if (on === grid) return;
|
|
1833
1854
|
const before = powerSnapshot();
|
|
1834
1855
|
grid = on;
|
|
1835
|
-
emit({ type: "power", grid });
|
|
1856
|
+
emit({ type: "power", grid, main });
|
|
1857
|
+
emitPowerChanges(before);
|
|
1858
|
+
},
|
|
1859
|
+
get main() {
|
|
1860
|
+
return main;
|
|
1861
|
+
},
|
|
1862
|
+
setMain(on) {
|
|
1863
|
+
if (on === main) return;
|
|
1864
|
+
const before = powerSnapshot();
|
|
1865
|
+
main = on;
|
|
1866
|
+
emit({ type: "power", grid, main });
|
|
1836
1867
|
emitPowerChanges(before);
|
|
1837
1868
|
},
|
|
1838
1869
|
setBreaker(circuit, on) {
|
|
@@ -2285,6 +2316,92 @@ function attachLeaf(world, options, request) {
|
|
|
2285
2316
|
return createLeafDriver({ world, leaf, frame, ownsFrame, joint, onDispose: request.onDispose, drive: { isHinge, axis, pivot, centre, range, speed, base: rotation } });
|
|
2286
2317
|
}
|
|
2287
2318
|
|
|
2319
|
+
// src/span.ts
|
|
2320
|
+
var GRAVITY = 9.81;
|
|
2321
|
+
var SHAPE_STEPS = 60;
|
|
2322
|
+
var VERTICAL_SPAN = 1e-4;
|
|
2323
|
+
function polylineLength(points) {
|
|
2324
|
+
let length2 = 0;
|
|
2325
|
+
for (let i = 1; i < points.length; i++) length2 += Math.hypot(points[i][0] - points[i - 1][0], points[i][1] - points[i - 1][1], points[i][2] - points[i - 1][2]);
|
|
2326
|
+
return length2;
|
|
2327
|
+
}
|
|
2328
|
+
function shapeOf(ratio) {
|
|
2329
|
+
let low = 1e-9;
|
|
2330
|
+
let high = 1;
|
|
2331
|
+
while (Math.sinh(high) / high < ratio && high < 700) high *= 2;
|
|
2332
|
+
for (let i = 0; i < SHAPE_STEPS; i++) {
|
|
2333
|
+
const mid = (low + high) / 2;
|
|
2334
|
+
if (Math.sinh(mid) / mid < ratio) low = mid;
|
|
2335
|
+
else high = mid;
|
|
2336
|
+
}
|
|
2337
|
+
return (low + high) / 2;
|
|
2338
|
+
}
|
|
2339
|
+
function spanStrength(span) {
|
|
2340
|
+
return span.material.ultimateMPa * 1e6 * span.section;
|
|
2341
|
+
}
|
|
2342
|
+
function straight(params, count, weight, chord) {
|
|
2343
|
+
const { span, from, to } = params;
|
|
2344
|
+
const pull = span.material.elasticGPa * 1e9 * span.section * ((chord - span.length) / span.length);
|
|
2345
|
+
const rise = to[1] - from[1];
|
|
2346
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2347
|
+
const t = i / (count - 1);
|
|
2348
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + rise * t, from[2] + (to[2] - from[2]) * t];
|
|
2349
|
+
});
|
|
2350
|
+
return { points, pullFrom: pull + weight * (span.length - rise) / 2, pullTo: pull + weight * (span.length + rise) / 2 };
|
|
2351
|
+
}
|
|
2352
|
+
function loop(params, count, weight) {
|
|
2353
|
+
const { span, from, to } = params;
|
|
2354
|
+
const bottom = (from[1] + to[1] - span.length) / 2;
|
|
2355
|
+
const down = from[1] - bottom;
|
|
2356
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2357
|
+
const s = i / (count - 1) * span.length;
|
|
2358
|
+
return s <= down ? [from[0], from[1] - s, from[2]] : [to[0], bottom + (s - down), to[2]];
|
|
2359
|
+
});
|
|
2360
|
+
return { points, pullFrom: weight * down, pullTo: weight * (to[1] - bottom) };
|
|
2361
|
+
}
|
|
2362
|
+
function hanging(params, count, weight, across) {
|
|
2363
|
+
const { span, from, to } = params;
|
|
2364
|
+
const rise = to[1] - from[1];
|
|
2365
|
+
const c = across / (2 * shapeOf(Math.sqrt(span.length * span.length - rise * rise) / across));
|
|
2366
|
+
const x0 = across / 2 - c * Math.atanh(rise / span.length);
|
|
2367
|
+
const base = Math.cosh(-x0 / c);
|
|
2368
|
+
const points = Array.from({ length: count }, (_, i) => {
|
|
2369
|
+
const t = i / (count - 1);
|
|
2370
|
+
return [from[0] + (to[0] - from[0]) * t, from[1] + c * (Math.cosh((across * t - x0) / c) - base), from[2] + (to[2] - from[2]) * t];
|
|
2371
|
+
});
|
|
2372
|
+
return { points, pullFrom: weight * c * base, pullTo: weight * c * Math.cosh((across - x0) / c) };
|
|
2373
|
+
}
|
|
2374
|
+
function solveSpan(params) {
|
|
2375
|
+
const { span, from, to } = params;
|
|
2376
|
+
const count = Math.max(2, Math.floor(params.segments ?? 16));
|
|
2377
|
+
const weight = span.material.density * span.section * GRAVITY;
|
|
2378
|
+
const across = Math.hypot(to[0] - from[0], to[2] - from[2]);
|
|
2379
|
+
const chord = Math.hypot(across, to[1] - from[1]);
|
|
2380
|
+
const taut = chord >= span.length;
|
|
2381
|
+
const shape = taut ? straight(params, count, weight, chord) : across < VERTICAL_SPAN ? loop(params, count, weight) : hanging(params, count, weight, across);
|
|
2382
|
+
const ground = params.ground;
|
|
2383
|
+
if (ground) for (const p of shape.points) p[1] = Math.max(p[1], ground(p[0], p[2]) + (params.clearance ?? 0));
|
|
2384
|
+
const tension = Math.max(shape.pullFrom, shape.pullTo);
|
|
2385
|
+
const snaps = tension > spanStrength(span) ? shape.pullFrom >= shape.pullTo ? "from" : "to" : null;
|
|
2386
|
+
return { points: shape.points, tension, taut, snaps };
|
|
2387
|
+
}
|
|
2388
|
+
function hangTail(params) {
|
|
2389
|
+
const { anchor, length: length2 } = params;
|
|
2390
|
+
const count = Math.max(2, Math.floor(params.segments ?? 16));
|
|
2391
|
+
const clearance = params.clearance ?? 0;
|
|
2392
|
+
const floorAt = (x, z) => params.ground ? params.ground(x, z) + clearance : -Infinity;
|
|
2393
|
+
const drop = Math.max(0, Math.min(length2, anchor[1] - floorAt(anchor[0], anchor[2])));
|
|
2394
|
+
const toward = params.toward ?? [1, 0, 0];
|
|
2395
|
+
const flat = Math.hypot(toward[0], toward[2]) || 1;
|
|
2396
|
+
return Array.from({ length: count }, (_, i) => {
|
|
2397
|
+
const s = i / (count - 1) * length2;
|
|
2398
|
+
if (s <= drop) return [anchor[0], anchor[1] - s, anchor[2]];
|
|
2399
|
+
const x = anchor[0] + toward[0] / flat * (s - drop);
|
|
2400
|
+
const z = anchor[2] + toward[2] / flat * (s - drop);
|
|
2401
|
+
return [x, Math.max(anchor[1] - drop, floorAt(x, z)), z];
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2288
2405
|
// src/fits-volume.ts
|
|
2289
2406
|
function fitsInVolume(size, half) {
|
|
2290
2407
|
const thing = [...size].sort((a, b) => b - a);
|
|
@@ -2530,16 +2647,20 @@ export {
|
|
|
2530
2647
|
fitsSlot,
|
|
2531
2648
|
format,
|
|
2532
2649
|
generateLoot,
|
|
2650
|
+
hangTail,
|
|
2533
2651
|
hashString,
|
|
2534
2652
|
localToWorld,
|
|
2535
2653
|
locales,
|
|
2536
2654
|
mergeColliders,
|
|
2537
2655
|
pickLocale,
|
|
2656
|
+
polylineLength,
|
|
2538
2657
|
poseOf,
|
|
2539
2658
|
resolveStrings,
|
|
2540
2659
|
rng,
|
|
2541
2660
|
rotY,
|
|
2542
2661
|
rotateAxis,
|
|
2662
|
+
solveSpan,
|
|
2663
|
+
spanStrength,
|
|
2543
2664
|
worldToLocal
|
|
2544
2665
|
};
|
|
2545
2666
|
//# sourceMappingURL=index.js.map
|