@adatechnology/game-urban 0.5.1 → 0.5.3

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.
@@ -514,6 +514,17 @@ var GameUrban = (() => {
514
514
  "outhouse"
515
515
  ]);
516
516
  var CAR_CLEARANCE = { driver: 0.8, side: 0.6, end: 0.6 };
517
+ var visor = false;
518
+ var visorLayout = () => visor;
519
+ function withVisorLayout(on2, fn) {
520
+ const previous = visor;
521
+ visor = on2;
522
+ try {
523
+ return fn();
524
+ } finally {
525
+ visor = previous;
526
+ }
527
+ }
517
528
  var active = WALL_THICKNESS;
518
529
  var wallThickness = () => active;
519
530
  var wallMargin = () => active / 2;
@@ -982,6 +993,7 @@ var GameUrban = (() => {
982
993
  }
983
994
  return [u0, v0, u0 + extentU, v0 + extentV];
984
995
  }
996
+ var BESIDE_GAP = 0.03;
985
997
  var RELAXED_RADIUS = 0.12;
986
998
  var MESH_FRONT = { "+z": [0, 1], "-z": [0, -1], "+x": [1, 0], "-x": [-1, 0] };
987
999
  function rotationFor(f, front) {
@@ -997,6 +1009,7 @@ var GameUrban = (() => {
997
1009
  const state = {};
998
1010
  const solids = [];
999
1011
  const reserves = [];
1012
+ const openings = [];
1000
1013
  const rims = [];
1001
1014
  const inners = usableParts(room, 0);
1002
1015
  const grid = createGrid(plan, room);
@@ -1019,11 +1032,11 @@ var GameUrban = (() => {
1019
1032
  }
1020
1033
  for (const u of units) u.required = u.members.some((m) => m.required);
1021
1034
  const queue = units.filter((u) => u.required).concat(units.filter((u) => !u.required));
1022
- const dependencies = (u) => u.members.flatMap((m) => [m.requires, m.on]).filter(Boolean).filter((id) => slots2.some((s) => s.id === id && !u.members.includes(s)));
1035
+ const dependencies = (u) => u.members.flatMap((m) => [m.requires, m.on]).filter(Boolean).filter((id) => slots2.some((s) => (s.id === id || s.group === id) && !u.members.includes(s)));
1023
1036
  const done = /* @__PURE__ */ new Set();
1024
1037
  const ready = (u) => dependencies(u).every((id) => done.has(id));
1025
1038
  const make = (s, it, r, parent, overheadOff) => {
1026
- const f = [s.frontU, s.frontV];
1039
+ const f = facingOf(s);
1027
1040
  const id = room.id + "." + s.id;
1028
1041
  const m = {
1029
1042
  id,
@@ -1059,9 +1072,31 @@ var GameUrban = (() => {
1059
1072
  if (parent && s.anchor === "inside") m.y = r2(parent.y || 0);
1060
1073
  if (room.link) m.link = { from: room.link[0], to: room.link[1] };
1061
1074
  state[s.id] = m;
1075
+ if (s.group && !state[s.group]) state[s.group] = m;
1062
1076
  items.push(m);
1063
1077
  return m;
1064
1078
  };
1079
+ const facingOf = (s) => {
1080
+ const parent = s.anchor === "beside" ? state[s.on] : void 0;
1081
+ return parent ? [parent.frontU ?? 0, parent.frontV ?? 1] : [s.frontU, s.frontV];
1082
+ };
1083
+ const besideRects = (s, it) => {
1084
+ const parent = state[s.on];
1085
+ if (!parent) return [];
1086
+ const f = [parent.frontU ?? 0, parent.frontV ?? 1];
1087
+ const r = parent._r ?? parent.aabb;
1088
+ const sign = s.side === "left" ? 1 : -1;
1089
+ const t = [-f[1] * sign, f[0] * sign];
1090
+ const [extentU, extentV] = extent([it.w, it.d], f);
1091
+ const halfAlong = Math.abs(t[0]) * (r[2] - r[0]) / 2 + Math.abs(t[1]) * (r[3] - r[1]) / 2;
1092
+ const itemAlong = Math.abs(t[0]) * extentU / 2 + Math.abs(t[1]) * extentV / 2;
1093
+ const cu = (r[0] + r[2]) / 2 + t[0] * (halfAlong + BESIDE_GAP + itemAlong);
1094
+ const cv = (r[1] + r[3]) / 2 + t[1] * (halfAlong + BESIDE_GAP + itemAlong);
1095
+ const back = f[1] > 0 ? r[1] : f[1] < 0 ? r[3] : f[0] > 0 ? r[0] : r[2];
1096
+ const u0 = f[0] > 0 ? back : f[0] < 0 ? back - extentU : cu - extentU / 2;
1097
+ const v0 = f[1] > 0 ? back : f[1] < 0 ? back - extentV : cv - extentV / 2;
1098
+ return [{ rect: [u0, v0, u0 + extentU, v0 + extentV] }];
1099
+ };
1065
1100
  const tryFit = (s, relax, overheadOff) => {
1066
1101
  const cands = weightedOrder(candidatesOf(s.cats), rng);
1067
1102
  if (s.anchor === "on" || s.anchor === "inside") {
@@ -1080,13 +1115,13 @@ var GameUrban = (() => {
1080
1115
  }
1081
1116
  for (const { it } of cands) {
1082
1117
  if (it.w > s.w + EPS || it.d > s.d + EPS) continue;
1083
- const f = [s.frontU, s.frontV];
1118
+ const f = facingOf(s);
1084
1119
  const slide = s.anchor === "wall" ? s.slide == null ? 2 : s.slide : 0;
1085
1120
  const shifts = [0];
1086
1121
  for (let k = 1; k * 0.1 <= slide + 1e-9; k++) shifts.push(k * 0.1, -k * 0.1);
1087
1122
  let found = null;
1088
1123
  const car = it.category === "car" && !relax;
1089
- const tries = car ? carCandidates(s, it, plan.carClearance) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
1124
+ const tries = car ? carCandidates(s, it, plan.carClearance) : s.anchor === "beside" ? besideRects(s, it) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
1090
1125
  for (const attempt of tries) {
1091
1126
  const r3 = attempt.rect;
1092
1127
  if (!insideUnion(r3, inners)) continue;
@@ -1098,6 +1133,7 @@ var GameUrban = (() => {
1098
1133
  if (zones.some((z) => overlaps(r3, z))) continue;
1099
1134
  if (windowZones.some(({ z, j }) => blocksWindow(it, j, overheadOff) && overlaps(r3, z))) continue;
1100
1135
  if (solids.some((o) => overlaps(r3, o))) continue;
1136
+ if (openings.some((o) => overlaps(r3, o))) continue;
1101
1137
  if (!it.deck && rims.some((a) => overlaps(r3, a))) continue;
1102
1138
  let cl2 = car ? attempt.clear : null;
1103
1139
  if (!car && !relax && s.clearance > 0 && !it.low) {
@@ -1105,6 +1141,12 @@ var GameUrban = (() => {
1105
1141
  if (!insideUnion(cl2, inners)) continue;
1106
1142
  if (items.some((m2) => !m2.low && !m2.flat && !m2.on && overlaps(cl2, m2._r ?? m2.aabb))) continue;
1107
1143
  }
1144
+ let front2 = null;
1145
+ if (!car && it.opening && !visorLayout()) {
1146
+ front2 = clearRect(r3, f, it.opening);
1147
+ if (!insideUnion(front2, inners)) continue;
1148
+ if (items.some((m2) => !m2.flat && !m2.on && overlaps(front2, m2._r ?? m2.aabb))) continue;
1149
+ }
1108
1150
  if (!it.low && reserves.some((q) => overlaps(r3, q))) continue;
1109
1151
  let rimRect2 = null;
1110
1152
  if (it.rim) {
@@ -1112,11 +1154,12 @@ var GameUrban = (() => {
1112
1154
  if (!insideUnion(rimRect2, inners) || solids.some((o) => overlaps(rimRect2, o)) || zones.some((z) => overlaps(rimRect2, z))) continue;
1113
1155
  }
1114
1156
  if (!(relax ? reachable(relaxedGrid, solids.concat([r3]), RELAXED_RADIUS) : reachable(grid, solids.concat([r3]), inflation))) continue;
1115
- found = { rect: r3, cl: cl2, rimRect: rimRect2 };
1157
+ found = { rect: r3, cl: cl2, rimRect: rimRect2, front: front2 };
1116
1158
  break;
1117
1159
  }
1118
1160
  if (!found) continue;
1119
- const { rect: r, cl, rimRect } = found;
1161
+ const { rect: r, cl, rimRect, front } = found;
1162
+ if (front) openings.push(front);
1120
1163
  if (it.flat) return make(s, it, r, null);
1121
1164
  const m = make(s, it, r, null, overheadOff);
1122
1165
  if (cl) reserves.push(cl);
@@ -1164,6 +1207,7 @@ var GameUrban = (() => {
1164
1207
  const u = pending.splice(i, 1)[0];
1165
1208
  process2(u);
1166
1209
  for (const m of u.members) done.add(m.id);
1210
+ if (u.group) done.add(u.group);
1167
1211
  }
1168
1212
  return { items, missing };
1169
1213
  }
@@ -1290,6 +1334,7 @@ var GameUrban = (() => {
1290
1334
  continue;
1291
1335
  }
1292
1336
  if (occupied.some((m) => !m.low && !m.flat && !m.on && !m.decor && (m.clearance ?? 0) > 0 && overlaps(r, clearRect(m._r, [m.frontU ?? 0, m.frontV ?? 1], m.clearance ?? 0)))) continue;
1337
+ if (!visorLayout() && occupied.some((m) => !m.flat && !m.on && !m.decor && (registries().CATALOG[m.type]?.opening ?? 0) > 0 && overlaps(r, clearRect(m._r, [m.frontU ?? 0, m.frontV ?? 1], registries().CATALOG[m.type]?.opening ?? 0)))) continue;
1293
1338
  if (opts.without && opts.without(r)) continue;
1294
1339
  if (!reachable(opts.railing || gridOf(room), solidList.concat([r]), room.outdoor ? 0.16 : plan.playerRadius)) continue;
1295
1340
  return r;
@@ -2123,6 +2168,7 @@ var GameUrban = (() => {
2123
2168
  for (const def of defs) {
2124
2169
  const s = resolveSlot(plan, room, def, byId2, zones);
2125
2170
  byId2[def.id] = s;
2171
+ if (s.valid && def.group && !byId2[def.group]) byId2[def.group] = s;
2126
2172
  all.push(s);
2127
2173
  }
2128
2174
  }
@@ -2150,7 +2196,7 @@ var GameUrban = (() => {
2150
2196
  reason: null
2151
2197
  };
2152
2198
  const invalid = (m) => Object.assign(base, { valid: false, reason: m, x: 0, z: 0, ry: 0, w: 0, d: 0, frontU: 0, frontV: 1, aabb: [0, 0, 0, 0], _cell: null });
2153
- if (def.anchor === "on" || def.anchor === "inside") {
2199
+ if (def.anchor === "on" || def.anchor === "inside" || def.anchor === "beside") {
2154
2200
  const parent = def.parent ? byId2[def.parent] : void 0;
2155
2201
  if (!parent || !parent.valid) return invalid("invalid_parent");
2156
2202
  return Object.assign(base, { x: parent.x, z: parent.z, ry: parent.ry, w: parent.w, d: parent.d, frontU: parent.frontU, frontV: parent.frontV, aabb: parent.aabb, _cell: parent._cell });
@@ -2292,7 +2338,7 @@ var GameUrban = (() => {
2292
2338
  function slots(template, options) {
2293
2339
  const tpl = templateOf(template);
2294
2340
  const o = resolveOptions(tpl, options || {});
2295
- return withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o));
2341
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o)));
2296
2342
  }
2297
2343
  function slotsWith(tpl, o) {
2298
2344
  const plan = buildPlan(tpl, o.w, o.d, o);
@@ -2338,7 +2384,7 @@ var GameUrban = (() => {
2338
2384
  function generate(template, options) {
2339
2385
  const tpl = templateOf(template);
2340
2386
  const o = resolveOptions(tpl, options || {});
2341
- return withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o));
2387
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o)));
2342
2388
  }
2343
2389
  var resolveOptions = (tpl, options) => registries().OPTION_RESOLVERS.reduce((op, r) => r.resolve(tpl, op), options);
2344
2390
  function generateWith(tpl, o) {
@@ -2499,7 +2545,8 @@ var GameUrban = (() => {
2499
2545
  center: (id, fx, fz, size, cats, o) => Object.assign({ id, anchor: "center", fx, fz, size, cats }, o),
2500
2546
  windowSlot: (id, size, cats, o) => Object.assign({ id, anchor: "window", size, cats }, o),
2501
2547
  on: (id, parent, cats, o) => Object.assign({ id, anchor: "on", on: parent, cats }, o),
2502
- inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o)
2548
+ inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o),
2549
+ beside: (id, parent, side, cats, o) => Object.assign({ id, anchor: "beside", on: parent, side, cats }, o)
2503
2550
  };
2504
2551
  var en_default = {
2505
2552
  labels: {