@adatechnology/game-floorplan-structure 2.0.0 → 2.0.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.
package/dist/index.js CHANGED
@@ -947,9 +947,10 @@ function addRoof(context) {
947
947
  }
948
948
 
949
949
  // src/structure/stairs.ts
950
+ var isStair = (item) => item.category === "stairs" && typeof item.link === "object" && item.link !== null;
950
951
  function flightsOf(items) {
951
952
  const flights = /* @__PURE__ */ new Map();
952
- for (const item of items.filter((it) => it.category === "stairs" && it.link)) {
953
+ for (const item of items.filter(isStair)) {
953
954
  const key = `${item.link.from}_${item.link.to}`;
954
955
  if (!flights.has(key) || item.floor === item.link.from) flights.set(key, item);
955
956
  }
@@ -1527,12 +1528,12 @@ function placeEntrance(layout) {
1527
1528
  const rect = lot.rect;
1528
1529
  const poleU = clamp(gate ? gate.u + 3 : plan.w / 2, rect[0] + 0.5, rect[2] - 0.5);
1529
1530
  const poleV = rect[1] - 0.6;
1530
- let meter;
1531
+ let placed;
1531
1532
  if (gate) {
1532
1533
  const direction = gate.u - gate.width / 2 - 0.4 >= rect[0] + 0.3 ? -1 : 1;
1533
- meter = { place: "gate_pillar", u: round22(gate.u + direction * (gate.width / 2 + 0.25)), v: round22(gate.v), y: 1.4, side: "front", ...METER_SIZE };
1534
- } else meter = { place: "facade", u: round22(door ? door.at + 1.2 : plan.w / 2), v: -0.1, y: 1.4, side: "front", ...METER_SIZE };
1535
- meter.id = "meter";
1534
+ placed = { place: "gate_pillar", u: round22(gate.u + direction * (gate.width / 2 + 0.25)), v: round22(gate.v), y: 1.4, side: "front", ...METER_SIZE };
1535
+ } else placed = { place: "facade", u: round22(door ? door.at + 1.2 : plan.w / 2), v: -0.1, y: 1.4, side: "front", ...METER_SIZE };
1536
+ const meter = Object.assign(placed, { id: "meter" });
1536
1537
  electrical.serviceEntrance = { pole: { u: round22(poleU), v: round22(poleV), h: 7.5 }, drop: [[round22(poleU), round22(poleV), 6.5], [meter.u, meter.v, 2.6]], meter, descent: [[meter.u, meter.v, 2.6], [meter.u, meter.v, 1.65]], internalRun: null };
1537
1538
  } else if (lot === null || plan.style === "commercial") {
1538
1539
  const front = door ? { u: round22(door.at + 1), v: -0.1 } : { u: round22(plan.w / 2), v: -0.1 };
@@ -1566,7 +1567,8 @@ function placePanel(layout) {
1566
1567
  }
1567
1568
  if (electrical.serviceEntrance && electrical.panel) {
1568
1569
  const entrance = electrical.serviceEntrance;
1569
- entrance.internalRun = [[entrance.meter.u, entrance.meter.v, 0.1], [electrical.panel.u, electrical.panel.v, heightOf(plan, electrical.panel.floor, electrical.panel.y)]];
1570
+ const meterOf = entrance.meter;
1571
+ entrance.internalRun = [[meterOf.u, meterOf.v, 0.1], [electrical.panel.u, electrical.panel.v, heightOf(plan, electrical.panel.floor, electrical.panel.y)]];
1570
1572
  }
1571
1573
  }
1572
1574
 
@@ -1655,9 +1657,9 @@ function planElectrical(context) {
1655
1657
  placePanel(layout);
1656
1658
  addSwitches(layout);
1657
1659
  addConduits(layout);
1658
- if (mode === "tap" && electrical.serviceEntrance?.meter) {
1659
- const entrance = electrical.serviceEntrance;
1660
- const meter = entrance.meter;
1660
+ const entrance = electrical.serviceEntrance;
1661
+ const meter = entrance?.meter;
1662
+ if (mode === "tap" && entrance && meter) {
1661
1663
  entrance.tap = true;
1662
1664
  entrance.connection = { u: meter.u, v: meter.v, y: 2.6 };
1663
1665
  entrance.meter = null;
@@ -1688,11 +1690,11 @@ function placeMeter(plan) {
1688
1690
  };
1689
1691
  }
1690
1692
  function besideStove(context, stove, room, solids, doorZones) {
1691
- const t = [-stove.frontV, stove.frontU];
1693
+ const t = [-(stove.frontV ?? 1), stove.frontU ?? 0];
1692
1694
  const parts = room.parts.map(inner);
1693
1695
  for (const s of context.rng() < 0.5 ? [1, -1] : [-1, 1]) {
1694
- const cx = stove.x + t[0] * s * (stove.w / 2 + CYLINDER.w / 2 + 0.03) - stove.frontU * (stove.d - CYLINDER.d) / 2;
1695
- const cz = stove.z + t[1] * s * (stove.w / 2 + CYLINDER.w / 2 + 0.03) - stove.frontV * (stove.d - CYLINDER.d) / 2;
1696
+ const cx = stove.x + t[0] * s * (stove.w / 2 + CYLINDER.w / 2 + 0.03) - (stove.frontU ?? 0) * (stove.d - CYLINDER.d) / 2;
1697
+ const cz = stove.z + t[1] * s * (stove.w / 2 + CYLINDER.w / 2 + 0.03) - (stove.frontV ?? 1) * (stove.d - CYLINDER.d) / 2;
1696
1698
  const rect = [cx - CYLINDER.w / 2, cz - CYLINDER.d / 2, cx + CYLINDER.w / 2, cz + CYLINDER.d / 2].map(round22);
1697
1699
  const inside = parts.some((q) => rect[0] >= q[0] - 0.011 && rect[2] <= q[2] + 0.011 && rect[1] >= q[1] - 0.011 && rect[3] <= q[3] + 0.011);
1698
1700
  if (inside && !solids.some((o) => overlaps(rect, o, 0.011)) && !doorZones.some((z) => overlaps(rect, z, 0.011))) return { mode: "beside", x: cx, z: cz, rect };
@@ -1748,8 +1750,8 @@ function cylinderItem(stove, spot) {
1748
1750
  d: CYLINDER.d,
1749
1751
  h: CYLINDER.h,
1750
1752
  y: 0,
1751
- frontU: -stove.frontU,
1752
- frontV: -stove.frontV,
1753
+ frontU: -(stove.frontU ?? 0),
1754
+ frontV: -(stove.frontV ?? 1),
1753
1755
  room: stove.room,
1754
1756
  floor: stove.floor,
1755
1757
  outdoor: !!spot.outdoor,
@@ -2009,9 +2011,11 @@ function planOutbuildings(context) {
2009
2011
  for (const item of items.filter((m) => m.category === "outbuilding")) {
2010
2012
  const rng = context.rngFor(streamOf(item.id));
2011
2013
  const [a0, a1, a2, a3] = item.aabb;
2012
- const n = [item.frontU, item.frontV];
2013
- const t = [-item.frontV, item.frontU];
2014
- const horizontal = Math.abs(item.frontU) === 1;
2014
+ const frontU = item.frontU ?? 0;
2015
+ const frontV = item.frontV ?? 1;
2016
+ const n = [frontU, frontV];
2017
+ const t = [-frontV, frontU];
2018
+ const horizontal = Math.abs(frontU) === 1;
2015
2019
  const cx = (a0 + a2) / 2;
2016
2020
  const cz = (a1 + a3) / 2;
2017
2021
  const depth = horizontal ? a2 - a0 : a3 - a1;
@@ -2248,7 +2252,7 @@ function constructionExtension(context) {
2248
2252
  }
2249
2253
  function structureExtension(context) {
2250
2254
  const cache = cacheOf(context.result);
2251
- const options = { construction: cache.build.construction, extras: cache.build.extras ?? {}, tank: context.result.waterTank ?? null, wallDetail: context.options.wallDetail ?? "panels" };
2255
+ const options = { construction: cache.build.construction, extras: cache.build.extras ?? {}, tank: tankOf(context), wallDetail: context.options.wallDetail ?? "panels" };
2252
2256
  const { roof, ...structure } = buildStructure(context.result, options);
2253
2257
  cache.roof = roof;
2254
2258
  for (const part of structure.parts) {
@@ -2259,6 +2263,7 @@ function structureExtension(context) {
2259
2263
  return structure;
2260
2264
  }
2261
2265
  var COOKING_CYLINDER = { type: "cooking_gas_cylinder", category: "cooking_gas_cylinder", w: 0.36, d: 0.36, h: 0.48 };
2266
+ var tankOf = (context) => context.result.waterTank ?? null;
2262
2267
  function energyOf(context) {
2263
2268
  const energy = context.plan.tpl.energy;
2264
2269
  return typeof energy === "function" ? energy(context.options, context.plan.w, context.plan.d) : void 0;
@@ -2289,7 +2294,7 @@ function register(engine, options = {}) {
2289
2294
  if (context.result.lot) addOutbuildingPaths(context.result.lot, outbuildings, context.result.items);
2290
2295
  return outbuildings;
2291
2296
  }, { after: ["contents"] });
2292
- engine.registerResultExtension("utilities", (context) => planUtilities({ plan: context.plan, items: context.result.items, stateItems: context.result.stateItems, tank: context.result.waterTank ?? null, ...energyOf(context) ? { energy: energyOf(context) } : {}, rngFor: (key) => engine.createRng(context.seed, key) }), { after: ["outbuildings", "waterTank"] });
2297
+ engine.registerResultExtension("utilities", (context) => planUtilities({ plan: context.plan, items: context.result.items, stateItems: context.result.stateItems, tank: tankOf(context), ...energyOf(context) ? { energy: energyOf(context) } : {}, rngFor: (key) => engine.createRng(context.seed, key) }), { after: ["outbuildings", "waterTank"] });
2293
2298
  }
2294
2299
 
2295
2300
  // src/to-destructible-spec.ts