@adatechnology/game-urban-three 0.5.1 → 0.5.2

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.
@@ -2576,6 +2576,17 @@ var GameUrbanThree = (() => {
2576
2576
  "outhouse"
2577
2577
  ]);
2578
2578
  var CAR_CLEARANCE = { driver: 0.8, side: 0.6, end: 0.6 };
2579
+ var visor = false;
2580
+ var visorLayout = () => visor;
2581
+ function withVisorLayout(on2, fn) {
2582
+ const previous = visor;
2583
+ visor = on2;
2584
+ try {
2585
+ return fn();
2586
+ } finally {
2587
+ visor = previous;
2588
+ }
2589
+ }
2579
2590
  var active = WALL_THICKNESS;
2580
2591
  var wallThickness = () => active;
2581
2592
  var wallMargin = () => active / 2;
@@ -3044,6 +3055,7 @@ var GameUrbanThree = (() => {
3044
3055
  }
3045
3056
  return [u0, v0, u0 + extentU, v0 + extentV];
3046
3057
  }
3058
+ var BESIDE_GAP = 0.03;
3047
3059
  var RELAXED_RADIUS = 0.12;
3048
3060
  var MESH_FRONT = { "+z": [0, 1], "-z": [0, -1], "+x": [1, 0], "-x": [-1, 0] };
3049
3061
  function rotationFor(f, front) {
@@ -3059,6 +3071,7 @@ var GameUrbanThree = (() => {
3059
3071
  const state = {};
3060
3072
  const solids = [];
3061
3073
  const reserves = [];
3074
+ const openings = [];
3062
3075
  const rims = [];
3063
3076
  const inners = usableParts(room, 0);
3064
3077
  const grid = createGrid(plan, room);
@@ -3081,11 +3094,11 @@ var GameUrbanThree = (() => {
3081
3094
  }
3082
3095
  for (const u of units) u.required = u.members.some((m) => m.required);
3083
3096
  const queue = units.filter((u) => u.required).concat(units.filter((u) => !u.required));
3084
- 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)));
3097
+ 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)));
3085
3098
  const done = /* @__PURE__ */ new Set();
3086
3099
  const ready = (u) => dependencies(u).every((id) => done.has(id));
3087
3100
  const make2 = (s, it, r, parent, overheadOff) => {
3088
- const f = [s.frontU, s.frontV];
3101
+ const f = facingOf(s);
3089
3102
  const id = room.id + "." + s.id;
3090
3103
  const m = {
3091
3104
  id,
@@ -3121,9 +3134,31 @@ var GameUrbanThree = (() => {
3121
3134
  if (parent && s.anchor === "inside") m.y = r2(parent.y || 0);
3122
3135
  if (room.link) m.link = { from: room.link[0], to: room.link[1] };
3123
3136
  state[s.id] = m;
3137
+ if (s.group && !state[s.group]) state[s.group] = m;
3124
3138
  items.push(m);
3125
3139
  return m;
3126
3140
  };
3141
+ const facingOf = (s) => {
3142
+ const parent = s.anchor === "beside" ? state[s.on] : void 0;
3143
+ return parent ? [parent.frontU ?? 0, parent.frontV ?? 1] : [s.frontU, s.frontV];
3144
+ };
3145
+ const besideRects = (s, it) => {
3146
+ const parent = state[s.on];
3147
+ if (!parent) return [];
3148
+ const f = [parent.frontU ?? 0, parent.frontV ?? 1];
3149
+ const r = parent._r ?? parent.aabb;
3150
+ const sign2 = s.side === "left" ? 1 : -1;
3151
+ const t = [-f[1] * sign2, f[0] * sign2];
3152
+ const [extentU, extentV] = extent([it.w, it.d], f);
3153
+ const halfAlong = Math.abs(t[0]) * (r[2] - r[0]) / 2 + Math.abs(t[1]) * (r[3] - r[1]) / 2;
3154
+ const itemAlong = Math.abs(t[0]) * extentU / 2 + Math.abs(t[1]) * extentV / 2;
3155
+ const cu = (r[0] + r[2]) / 2 + t[0] * (halfAlong + BESIDE_GAP + itemAlong);
3156
+ const cv = (r[1] + r[3]) / 2 + t[1] * (halfAlong + BESIDE_GAP + itemAlong);
3157
+ const back = f[1] > 0 ? r[1] : f[1] < 0 ? r[3] : f[0] > 0 ? r[0] : r[2];
3158
+ const u0 = f[0] > 0 ? back : f[0] < 0 ? back - extentU : cu - extentU / 2;
3159
+ const v0 = f[1] > 0 ? back : f[1] < 0 ? back - extentV : cv - extentV / 2;
3160
+ return [{ rect: [u0, v0, u0 + extentU, v0 + extentV] }];
3161
+ };
3127
3162
  const tryFit = (s, relax, overheadOff) => {
3128
3163
  const cands = weightedOrder(candidatesOf(s.cats), rng);
3129
3164
  if (s.anchor === "on" || s.anchor === "inside") {
@@ -3142,13 +3177,13 @@ var GameUrbanThree = (() => {
3142
3177
  }
3143
3178
  for (const { it } of cands) {
3144
3179
  if (it.w > s.w + EPS || it.d > s.d + EPS) continue;
3145
- const f = [s.frontU, s.frontV];
3180
+ const f = facingOf(s);
3146
3181
  const slide = s.anchor === "wall" ? s.slide == null ? 2 : s.slide : 0;
3147
3182
  const shifts = [0];
3148
3183
  for (let k = 1; k * 0.1 <= slide + 1e-9; k++) shifts.push(k * 0.1, -k * 0.1);
3149
3184
  let found = null;
3150
3185
  const car = it.category === "car" && !relax;
3151
- const tries = car ? carCandidates(s, it, plan.carClearance) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
3186
+ const tries = car ? carCandidates(s, it, plan.carClearance) : s.anchor === "beside" ? besideRects(s, it) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
3152
3187
  for (const attempt of tries) {
3153
3188
  const r3 = attempt.rect;
3154
3189
  if (!insideUnion(r3, inners)) continue;
@@ -3160,6 +3195,7 @@ var GameUrbanThree = (() => {
3160
3195
  if (zones.some((z) => overlaps(r3, z))) continue;
3161
3196
  if (windowZones.some(({ z, j }) => blocksWindow(it, j, overheadOff) && overlaps(r3, z))) continue;
3162
3197
  if (solids.some((o) => overlaps(r3, o))) continue;
3198
+ if (openings.some((o) => overlaps(r3, o))) continue;
3163
3199
  if (!it.deck && rims.some((a) => overlaps(r3, a))) continue;
3164
3200
  let cl2 = car ? attempt.clear : null;
3165
3201
  if (!car && !relax && s.clearance > 0 && !it.low) {
@@ -3167,6 +3203,12 @@ var GameUrbanThree = (() => {
3167
3203
  if (!insideUnion(cl2, inners)) continue;
3168
3204
  if (items.some((m2) => !m2.low && !m2.flat && !m2.on && overlaps(cl2, m2._r ?? m2.aabb))) continue;
3169
3205
  }
3206
+ let front2 = null;
3207
+ if (!car && it.opening && !visorLayout()) {
3208
+ front2 = clearRect(r3, f, it.opening);
3209
+ if (!insideUnion(front2, inners)) continue;
3210
+ if (items.some((m2) => !m2.flat && !m2.on && overlaps(front2, m2._r ?? m2.aabb))) continue;
3211
+ }
3170
3212
  if (!it.low && reserves.some((q) => overlaps(r3, q))) continue;
3171
3213
  let rimRect2 = null;
3172
3214
  if (it.rim) {
@@ -3174,11 +3216,12 @@ var GameUrbanThree = (() => {
3174
3216
  if (!insideUnion(rimRect2, inners) || solids.some((o) => overlaps(rimRect2, o)) || zones.some((z) => overlaps(rimRect2, z))) continue;
3175
3217
  }
3176
3218
  if (!(relax ? reachable(relaxedGrid, solids.concat([r3]), RELAXED_RADIUS) : reachable(grid, solids.concat([r3]), inflation))) continue;
3177
- found = { rect: r3, cl: cl2, rimRect: rimRect2 };
3219
+ found = { rect: r3, cl: cl2, rimRect: rimRect2, front: front2 };
3178
3220
  break;
3179
3221
  }
3180
3222
  if (!found) continue;
3181
- const { rect: r, cl, rimRect } = found;
3223
+ const { rect: r, cl, rimRect, front } = found;
3224
+ if (front) openings.push(front);
3182
3225
  if (it.flat) return make2(s, it, r, null);
3183
3226
  const m = make2(s, it, r, null, overheadOff);
3184
3227
  if (cl) reserves.push(cl);
@@ -3226,6 +3269,7 @@ var GameUrbanThree = (() => {
3226
3269
  const u = pending.splice(i, 1)[0];
3227
3270
  process2(u);
3228
3271
  for (const m of u.members) done.add(m.id);
3272
+ if (u.group) done.add(u.group);
3229
3273
  }
3230
3274
  return { items, missing };
3231
3275
  }
@@ -3352,6 +3396,7 @@ var GameUrbanThree = (() => {
3352
3396
  continue;
3353
3397
  }
3354
3398
  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;
3399
+ 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;
3355
3400
  if (opts.without && opts.without(r)) continue;
3356
3401
  if (!reachable(opts.railing || gridOf(room), solidList.concat([r]), room.outdoor ? 0.16 : plan.playerRadius)) continue;
3357
3402
  return r;
@@ -4185,6 +4230,7 @@ var GameUrbanThree = (() => {
4185
4230
  for (const def of defs) {
4186
4231
  const s = resolveSlot(plan, room, def, byId2, zones);
4187
4232
  byId2[def.id] = s;
4233
+ if (s.valid && def.group && !byId2[def.group]) byId2[def.group] = s;
4188
4234
  all.push(s);
4189
4235
  }
4190
4236
  }
@@ -4212,7 +4258,7 @@ var GameUrbanThree = (() => {
4212
4258
  reason: null
4213
4259
  };
4214
4260
  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 });
4215
- if (def.anchor === "on" || def.anchor === "inside") {
4261
+ if (def.anchor === "on" || def.anchor === "inside" || def.anchor === "beside") {
4216
4262
  const parent = def.parent ? byId2[def.parent] : void 0;
4217
4263
  if (!parent || !parent.valid) return invalid("invalid_parent");
4218
4264
  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 });
@@ -4354,7 +4400,7 @@ var GameUrbanThree = (() => {
4354
4400
  function slots(template, options) {
4355
4401
  const tpl = templateOf(template);
4356
4402
  const o = resolveOptions(tpl, options || {});
4357
- return withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o));
4403
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o)));
4358
4404
  }
4359
4405
  function slotsWith(tpl, o) {
4360
4406
  const plan = buildPlan(tpl, o.w, o.d, o);
@@ -4400,7 +4446,7 @@ var GameUrbanThree = (() => {
4400
4446
  function generate2(template, options) {
4401
4447
  const tpl = templateOf(template);
4402
4448
  const o = resolveOptions(tpl, options || {});
4403
- return withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o));
4449
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o)));
4404
4450
  }
4405
4451
  var resolveOptions = (tpl, options) => registries().OPTION_RESOLVERS.reduce((op, r) => r.resolve(tpl, op), options);
4406
4452
  function generateWith(tpl, o) {
@@ -4561,7 +4607,8 @@ var GameUrbanThree = (() => {
4561
4607
  center: (id, fx, fz, size, cats, o) => Object.assign({ id, anchor: "center", fx, fz, size, cats }, o),
4562
4608
  windowSlot: (id, size, cats, o) => Object.assign({ id, anchor: "window", size, cats }, o),
4563
4609
  on: (id, parent, cats, o) => Object.assign({ id, anchor: "on", on: parent, cats }, o),
4564
- inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o)
4610
+ inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o),
4611
+ beside: (id, parent, side, cats, o) => Object.assign({ id, anchor: "beside", on: parent, side, cats }, o)
4565
4612
  };
4566
4613
  var en_default = {
4567
4614
  labels: {