@adatechnology/game-interactables 0.3.1 → 0.5.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/index.d.ts +7 -1
- package/dist/index.global.js +63 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +63 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -259,7 +259,10 @@ function dist3(a, b) {
|
|
|
259
259
|
// src/world.ts
|
|
260
260
|
var DEFAULT_ACTOR = "player";
|
|
261
261
|
var DEFAULT_RADIUS = 1.2;
|
|
262
|
+
var TAKE_PREFIX = "take.";
|
|
263
|
+
var TAKE_RADIUS = 0.6;
|
|
262
264
|
var AUTO_RANGE = 2;
|
|
265
|
+
var SOCKET_BEHIND = 0.05;
|
|
263
266
|
var SMOKE_TAIL = 20;
|
|
264
267
|
var FLUSH_SECONDS = 2;
|
|
265
268
|
var ACTOR_HEIGHT = 1.7;
|
|
@@ -578,7 +581,11 @@ function createWorld(options = {}) {
|
|
|
578
581
|
plugs.clear();
|
|
579
582
|
const sockets = [];
|
|
580
583
|
for (const o of objs.values()) {
|
|
581
|
-
for (const s of o.spec.sockets ?? [])
|
|
584
|
+
for (const s of o.spec.sockets ?? []) {
|
|
585
|
+
const pos = toWorld(o, s.pos);
|
|
586
|
+
const ahead = toWorld(o, [s.pos[0], s.pos[1], s.pos[2] + 1]);
|
|
587
|
+
sockets.push({ id: gid(o, s.id), local: s.id, pos, circuit: s.circuit, facing: [ahead[0] - pos[0], ahead[1] - pos[1], ahead[2] - pos[2]] });
|
|
588
|
+
}
|
|
582
589
|
}
|
|
583
590
|
const used = /* @__PURE__ */ new Set();
|
|
584
591
|
const autos = [];
|
|
@@ -604,6 +611,7 @@ function createWorld(options = {}) {
|
|
|
604
611
|
let bestD = AUTO_RANGE;
|
|
605
612
|
for (const s of sockets) {
|
|
606
613
|
if (used.has(s.id)) continue;
|
|
614
|
+
if ((from[0] - s.pos[0]) * s.facing[0] + (from[1] - s.pos[1]) * s.facing[1] + (from[2] - s.pos[2]) * s.facing[2] < -SOCKET_BEHIND) continue;
|
|
607
615
|
const dd = dist3(from, s.pos);
|
|
608
616
|
if (dd <= bestD) {
|
|
609
617
|
best = s;
|
|
@@ -1199,9 +1207,52 @@ function createWorld(options = {}) {
|
|
|
1199
1207
|
return { item, spec: i, o };
|
|
1200
1208
|
});
|
|
1201
1209
|
}
|
|
1210
|
+
function contentTakes(o) {
|
|
1211
|
+
if (options.takeContents === false) return [];
|
|
1212
|
+
const out = [];
|
|
1213
|
+
for (const c of o.spec.containers ?? []) {
|
|
1214
|
+
const list = o.contents.get(c.id);
|
|
1215
|
+
if (!list || !list.some((st) => st !== null) || !accessible(o.id, c.id)) continue;
|
|
1216
|
+
list.forEach((stack, slot) => {
|
|
1217
|
+
if (!stack || options.items?.[stack.type]?.pickable === false || stack.data?.pickable === false) return;
|
|
1218
|
+
const verb = t("prompt.take");
|
|
1219
|
+
const noun = table[`item.${stack.type}`] ?? humanize(stack.type);
|
|
1220
|
+
const item = {
|
|
1221
|
+
id: `${o.id}:${TAKE_PREFIX}${c.id}.${slot}`,
|
|
1222
|
+
object: o.id,
|
|
1223
|
+
kind: "take",
|
|
1224
|
+
pos: slotPosition(o.id, c.id, slot),
|
|
1225
|
+
radius: TAKE_RADIUS,
|
|
1226
|
+
label: `${verb} ${noun}`,
|
|
1227
|
+
verb,
|
|
1228
|
+
noun,
|
|
1229
|
+
hands: 1,
|
|
1230
|
+
itemType: stack.type,
|
|
1231
|
+
available: true,
|
|
1232
|
+
act: (actor) => takeAt(o.id, c.id, slot, actor ?? DEFAULT_ACTOR)
|
|
1233
|
+
};
|
|
1234
|
+
if (options.canInteract?.(item, DEFAULT_ACTOR) === false) {
|
|
1235
|
+
item.available = false;
|
|
1236
|
+
item.reason = "locked";
|
|
1237
|
+
}
|
|
1238
|
+
out.push(item);
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
return out;
|
|
1242
|
+
}
|
|
1243
|
+
function takeAt(objectId, containerId, slot, actor) {
|
|
1244
|
+
const o = objs.get(objectId);
|
|
1245
|
+
if (!o) return false;
|
|
1246
|
+
const probe = contentTakes(o).find((k) => k.id === `${objectId}:${TAKE_PREFIX}${containerId}.${slot}`);
|
|
1247
|
+
if (!probe || options.canInteract?.(probe, actor) === false) return false;
|
|
1248
|
+
return take(objectId, containerId, slot, actor) !== null;
|
|
1249
|
+
}
|
|
1202
1250
|
function interactables() {
|
|
1203
1251
|
const out = [];
|
|
1204
|
-
for (const o of objs.values())
|
|
1252
|
+
for (const o of objs.values()) {
|
|
1253
|
+
for (const e of interactablesOf(o)) out.push(e.item);
|
|
1254
|
+
out.push(...contentTakes(o));
|
|
1255
|
+
}
|
|
1205
1256
|
return out;
|
|
1206
1257
|
}
|
|
1207
1258
|
function target(eye, opts = {}) {
|
|
@@ -1211,11 +1262,11 @@ function createWorld(options = {}) {
|
|
|
1211
1262
|
let best = null;
|
|
1212
1263
|
let bestScore = Infinity;
|
|
1213
1264
|
for (const o of objs.values()) {
|
|
1214
|
-
for (const
|
|
1215
|
-
if (!
|
|
1216
|
-
if (opts.kinds && !opts.kinds.includes(
|
|
1217
|
-
if (opts.filter && !opts.filter(
|
|
1218
|
-
const v = [
|
|
1265
|
+
for (const item of [...interactablesOf(o).map((e) => e.item), ...contentTakes(o)]) {
|
|
1266
|
+
if (!item.available && !opts.includeUnavailable) continue;
|
|
1267
|
+
if (opts.kinds && !opts.kinds.includes(item.kind)) continue;
|
|
1268
|
+
if (opts.filter && !opts.filter(item)) continue;
|
|
1269
|
+
const v = [item.pos[0] - eye.x, item.pos[1] - eye.y, item.pos[2] - eye.z];
|
|
1219
1270
|
const d = Math.hypot(v[0], v[1], v[2]);
|
|
1220
1271
|
if (d > reach) continue;
|
|
1221
1272
|
const cos = d < 1e-6 ? 1 : clamp((v[0] * dir[0] + v[1] * dir[1] + v[2] * dir[2]) / d, -1, 1);
|
|
@@ -1224,7 +1275,7 @@ function createWorld(options = {}) {
|
|
|
1224
1275
|
const score = angle / cone * 0.6 + d / reach * 0.4;
|
|
1225
1276
|
if (score < bestScore) {
|
|
1226
1277
|
bestScore = score;
|
|
1227
|
-
best =
|
|
1278
|
+
best = item;
|
|
1228
1279
|
}
|
|
1229
1280
|
}
|
|
1230
1281
|
}
|
|
@@ -1235,6 +1286,10 @@ function createWorld(options = {}) {
|
|
|
1235
1286
|
for (const o of objs.values()) {
|
|
1236
1287
|
if (!interactableId.startsWith(o.id + ":")) continue;
|
|
1237
1288
|
const local = interactableId.slice(o.id.length + 1);
|
|
1289
|
+
if (local.startsWith(TAKE_PREFIX)) {
|
|
1290
|
+
const at = contentTakes(o).find((k) => k.id === interactableId);
|
|
1291
|
+
if (at) return at.act(actor);
|
|
1292
|
+
}
|
|
1238
1293
|
if (!o.interactions.some((i) => i.id === local)) continue;
|
|
1239
1294
|
found = interactablesOf(o).find((e) => e.spec.id === local) ?? null;
|
|
1240
1295
|
if (found) break;
|