@adatechnology/game-interactables 0.3.0 → 0.4.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 +5 -1
- package/dist/index.global.js +62 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +62 -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,51 @@ 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
|
+
available: true,
|
|
1231
|
+
act: (actor) => takeAt(o.id, c.id, slot, actor ?? DEFAULT_ACTOR)
|
|
1232
|
+
};
|
|
1233
|
+
if (options.canInteract?.(item, DEFAULT_ACTOR) === false) {
|
|
1234
|
+
item.available = false;
|
|
1235
|
+
item.reason = "locked";
|
|
1236
|
+
}
|
|
1237
|
+
out.push(item);
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
return out;
|
|
1241
|
+
}
|
|
1242
|
+
function takeAt(objectId, containerId, slot, actor) {
|
|
1243
|
+
const o = objs.get(objectId);
|
|
1244
|
+
if (!o) return false;
|
|
1245
|
+
const probe = contentTakes(o).find((k) => k.id === `${objectId}:${TAKE_PREFIX}${containerId}.${slot}`);
|
|
1246
|
+
if (!probe || options.canInteract?.(probe, actor) === false) return false;
|
|
1247
|
+
return take(objectId, containerId, slot, actor) !== null;
|
|
1248
|
+
}
|
|
1202
1249
|
function interactables() {
|
|
1203
1250
|
const out = [];
|
|
1204
|
-
for (const o of objs.values())
|
|
1251
|
+
for (const o of objs.values()) {
|
|
1252
|
+
for (const e of interactablesOf(o)) out.push(e.item);
|
|
1253
|
+
out.push(...contentTakes(o));
|
|
1254
|
+
}
|
|
1205
1255
|
return out;
|
|
1206
1256
|
}
|
|
1207
1257
|
function target(eye, opts = {}) {
|
|
@@ -1211,11 +1261,11 @@ function createWorld(options = {}) {
|
|
|
1211
1261
|
let best = null;
|
|
1212
1262
|
let bestScore = Infinity;
|
|
1213
1263
|
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 = [
|
|
1264
|
+
for (const item of [...interactablesOf(o).map((e) => e.item), ...contentTakes(o)]) {
|
|
1265
|
+
if (!item.available && !opts.includeUnavailable) continue;
|
|
1266
|
+
if (opts.kinds && !opts.kinds.includes(item.kind)) continue;
|
|
1267
|
+
if (opts.filter && !opts.filter(item)) continue;
|
|
1268
|
+
const v = [item.pos[0] - eye.x, item.pos[1] - eye.y, item.pos[2] - eye.z];
|
|
1219
1269
|
const d = Math.hypot(v[0], v[1], v[2]);
|
|
1220
1270
|
if (d > reach) continue;
|
|
1221
1271
|
const cos = d < 1e-6 ? 1 : clamp((v[0] * dir[0] + v[1] * dir[1] + v[2] * dir[2]) / d, -1, 1);
|
|
@@ -1224,7 +1274,7 @@ function createWorld(options = {}) {
|
|
|
1224
1274
|
const score = angle / cone * 0.6 + d / reach * 0.4;
|
|
1225
1275
|
if (score < bestScore) {
|
|
1226
1276
|
bestScore = score;
|
|
1227
|
-
best =
|
|
1277
|
+
best = item;
|
|
1228
1278
|
}
|
|
1229
1279
|
}
|
|
1230
1280
|
}
|
|
@@ -1235,6 +1285,10 @@ function createWorld(options = {}) {
|
|
|
1235
1285
|
for (const o of objs.values()) {
|
|
1236
1286
|
if (!interactableId.startsWith(o.id + ":")) continue;
|
|
1237
1287
|
const local = interactableId.slice(o.id.length + 1);
|
|
1288
|
+
if (local.startsWith(TAKE_PREFIX)) {
|
|
1289
|
+
const at = contentTakes(o).find((k) => k.id === interactableId);
|
|
1290
|
+
if (at) return at.act(actor);
|
|
1291
|
+
}
|
|
1238
1292
|
if (!o.interactions.some((i) => i.id === local)) continue;
|
|
1239
1293
|
found = interactablesOf(o).find((e) => e.spec.id === local) ?? null;
|
|
1240
1294
|
if (found) break;
|