@adatechnology/game-floorplan 0.4.0 → 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 CHANGED
@@ -97,6 +97,8 @@ interface FurnitureDef {
97
97
  decor?: boolean;
98
98
  /** Hangs a wall cabinet over the counter (y 1.55 to 2.15 m): it blocks a window unless the fill dropped the cabinet. */
99
99
  overhead?: boolean;
100
+ /** Depth in front of the item that its doors or drawers sweep, with the reach to use them (metres): the fill keeps it clear of walls and of other items, even for a low item. */
101
+ opening?: number;
100
102
  /** Effective height that blocks a window when taller than `h` (a shower enclosure is 0.1 m tray plus 1.95 m glass). */
101
103
  windowHeight?: number;
102
104
  /** Plugs into a socket (lamps, appliances). */
@@ -108,7 +110,8 @@ interface FurnitureDef {
108
110
  color?: ItemColor;
109
111
  }
110
112
  type ItemInput = Pick<FurnitureDef, 'type' | 'category' | 'w' | 'd' | 'h'> & Partial<FurnitureDef>;
111
- type Anchor = 'wall' | 'corner' | 'center' | 'window' | 'on' | 'inside';
113
+ /** `beside`: on the floor next to the item of the slot `on`, backed on the same line as its back and facing the same way, on its `side` (`left` or `right`, seen from its front). */
114
+ type Anchor = 'wall' | 'corner' | 'center' | 'window' | 'on' | 'inside' | 'beside';
112
115
  type Side = 'left' | 'right' | 'front' | 'back' | 'any';
113
116
  type FacingRule = 'center' | 'door' | 'target' | 'u+' | 'u-' | 'v+' | 'v-';
114
117
  interface SlotDef {
@@ -152,6 +155,7 @@ interface SlotKit {
152
155
  windowSlot(id: string, size: number[], cats: Weights, o?: Partial<SlotDef>): SlotDef;
153
156
  on(id: string, parent: string, cats: Weights, o?: Partial<SlotDef>): SlotDef;
154
157
  inside(id: string, parent: string, cats: Weights, o?: Partial<SlotDef>): SlotDef;
158
+ beside(id: string, parent: string, side: 'left' | 'right', cats: Weights, o?: Partial<SlotDef>): SlotDef;
155
159
  }
156
160
  interface RoomDef {
157
161
  id: string;
@@ -434,6 +438,8 @@ interface FloorplanOptions {
434
438
  day?: number;
435
439
  /** Region of the world for the finds (`FindsQuery.region`), as the item pack names it. */
436
440
  region?: string;
441
+ /** Lays the furniture out as the Visor de casas 3D did (no room kept for doors and drawers, a nightstand in the bed's corner): the team's golden only. Default `false`. */
442
+ visorLayout?: boolean;
437
443
  [extra: string]: Json;
438
444
  }
439
445
  interface Room {
@@ -1343,6 +1349,12 @@ declare function defaultFloorplan(): FloorplanEngine;
1343
1349
  /** Builders for the slot definitions of a room library. */
1344
1350
  declare const slotKit: SlotKit;
1345
1351
 
1352
+ /**
1353
+ * The furniture is being laid out as the Visor de casas 3D did (`FloorplanOptions.visorLayout`, the team's golden only): no room kept for doors and drawers to
1354
+ * open, a nightstand in the bed's corner, the lights and curtains hung without looking at what stands under them.
1355
+ */
1356
+ declare const visorLayout: () => boolean;
1357
+
1346
1358
  /** One primitive of a far-away silhouette. Parts are listed in creation order; `parent` is the index of a group part (`-1` is the root). */
1347
1359
  type SilhouettePart = {
1348
1360
  shape: 'group';
@@ -1533,4 +1545,4 @@ declare function createDetachedHouse(p: DetachedHouseParams): Silhouette;
1533
1545
  */
1534
1546
  declare const engine: FloorplanEngine;
1535
1547
 
1536
- export { type Anchor, type BoundaryRule, type CarClearance, type ChaletParams, type CityBuildingParams, type ColonialParams, type CompanyHouseParams, type CreateFloorplanOptions, type DecorPass, type DecorPassContext, type DetachedHouseParams, type DoorDef, type Facade, type FacadeFields, type FacingRule, type FarmhouseParams, type FindStack, type FindsProvider, type FindsQuery, type FloorDef, type FloorplanEngine, type FloorplanLocale, type FloorplanOptions, type FloorplanPack, type FloorplanResult, type FloorplanResultFields, type FurnitureDef, type GateCfg, type GroundOverlayRule, type Hsl, type ItemColor, type ItemInput, type Json, type Lot, type LotBoundary, type LotConfig, type LotPath, type LotPerimeterPiece, type MeshFront, type Mount, type OptionResolver, type PaletteDraw, type PaletteEarly, type PaletteStyleDef, type PlaceOnFloorOptions, type PlacedItem, type PlacedItemFields, type PlacementContext, type PlacementKit, type Plan, type PlanAxis, type PlanDoor, type PlanGate, type PlanOpening, type PlanWall, type PlanWindow, type RandomSource, type RecordedSlot, type Rect, type ResultExtensionContext, type ResultExtensionOptions, type ResultExtensionRun, type ResultFacade, type ResultFloor, type ResultGate, type ResultItem, type ResultLot, type ResultRoom, type Room, type RoomColorDef, type RoomDef, type Side, type Silhouette, type SilhouettePart, type SilhouetteWindow, type SlabHouseParams, type Slot, type SlotCell, type SlotDef, type SlotFields, type SlotKit, type SlotLibrary, type StateContext, type StatePlugin, type StiltHouseParams, type StyleDef, type TemplateDef, type TwoStoreyParams, type Vec2, type ViewerLayer, type ViewerLayerContext, type ViewerLayerLegendEntry, type WalkGrid, type Weights, type WindowDef, type WindowFrame, type ZoneAdjustment, type ZoneCheckedLot, type ZoneCheckedPlan, type ZoneDef, type ZoneViolation, type ZoningReport, blocksWindow, boxRadius, checkLot, createChalet, createCityBuilding, createColonialHouse, createCompanyHouse, createDetachedHouse, createFarmhouse, createFloorplan, createRng, createSilhouetteRandom, createSlabHouse, createStiltHouse, createTwoStoreyHouse, defaultFloorplan, defineZone, engine, findsAnswer, findsFor, generate, getZone, hashString, limitsOf, listLocales, listStates, listTemplates, listZones, mulberry32, openingZones, overlaps, palette, registerDecorProfile, registerFindsProvider, registerGroundOverlay, registerItem, registerItems, registerLibrary, registerLibraryAlias, registerLocale, registerOptionResolver, registerPaletteStyle, registerPass, registerPermeableGround, registerResultExtension, registerRoomColors, registerSeedKeys, registerState, registerStyle, registerTemplate, registerViewerLayer, registerWallTop, setStateDistribution, slotKit, slots, translate, validate, version, windowZone };
1548
+ export { type Anchor, type BoundaryRule, type CarClearance, type ChaletParams, type CityBuildingParams, type ColonialParams, type CompanyHouseParams, type CreateFloorplanOptions, type DecorPass, type DecorPassContext, type DetachedHouseParams, type DoorDef, type Facade, type FacadeFields, type FacingRule, type FarmhouseParams, type FindStack, type FindsProvider, type FindsQuery, type FloorDef, type FloorplanEngine, type FloorplanLocale, type FloorplanOptions, type FloorplanPack, type FloorplanResult, type FloorplanResultFields, type FurnitureDef, type GateCfg, type GroundOverlayRule, type Hsl, type ItemColor, type ItemInput, type Json, type Lot, type LotBoundary, type LotConfig, type LotPath, type LotPerimeterPiece, type MeshFront, type Mount, type OptionResolver, type PaletteDraw, type PaletteEarly, type PaletteStyleDef, type PlaceOnFloorOptions, type PlacedItem, type PlacedItemFields, type PlacementContext, type PlacementKit, type Plan, type PlanAxis, type PlanDoor, type PlanGate, type PlanOpening, type PlanWall, type PlanWindow, type RandomSource, type RecordedSlot, type Rect, type ResultExtensionContext, type ResultExtensionOptions, type ResultExtensionRun, type ResultFacade, type ResultFloor, type ResultGate, type ResultItem, type ResultLot, type ResultRoom, type Room, type RoomColorDef, type RoomDef, type Side, type Silhouette, type SilhouettePart, type SilhouetteWindow, type SlabHouseParams, type Slot, type SlotCell, type SlotDef, type SlotFields, type SlotKit, type SlotLibrary, type StateContext, type StatePlugin, type StiltHouseParams, type StyleDef, type TemplateDef, type TwoStoreyParams, type Vec2, type ViewerLayer, type ViewerLayerContext, type ViewerLayerLegendEntry, type WalkGrid, type Weights, type WindowDef, type WindowFrame, type ZoneAdjustment, type ZoneCheckedLot, type ZoneCheckedPlan, type ZoneDef, type ZoneViolation, type ZoningReport, blocksWindow, boxRadius, checkLot, createChalet, createCityBuilding, createColonialHouse, createCompanyHouse, createDetachedHouse, createFarmhouse, createFloorplan, createRng, createSilhouetteRandom, createSlabHouse, createStiltHouse, createTwoStoreyHouse, defaultFloorplan, defineZone, engine, findsAnswer, findsFor, generate, getZone, hashString, limitsOf, listLocales, listStates, listTemplates, listZones, mulberry32, openingZones, overlaps, palette, registerDecorProfile, registerFindsProvider, registerGroundOverlay, registerItem, registerItems, registerLibrary, registerLibraryAlias, registerLocale, registerOptionResolver, registerPaletteStyle, registerPass, registerPermeableGround, registerResultExtension, registerRoomColors, registerSeedKeys, registerState, registerStyle, registerTemplate, registerViewerLayer, registerWallTop, setStateDistribution, slotKit, slots, translate, validate, version, visorLayout, windowZone };
@@ -79,6 +79,7 @@ var GameFloorplan = (() => {
79
79
  translate: () => translate,
80
80
  validate: () => validate,
81
81
  version: () => version,
82
+ visorLayout: () => visorLayout,
82
83
  windowZone: () => windowZone
83
84
  });
84
85
 
@@ -335,6 +336,19 @@ var GameFloorplan = (() => {
335
336
  ]);
336
337
  var CAR_CLEARANCE = { driver: 0.8, side: 0.6, end: 0.6 };
337
338
 
339
+ // src/layout-mode.ts
340
+ var visor = false;
341
+ var visorLayout = () => visor;
342
+ function withVisorLayout(on, fn) {
343
+ const previous = visor;
344
+ visor = on;
345
+ try {
346
+ return fn();
347
+ } finally {
348
+ visor = previous;
349
+ }
350
+ }
351
+
338
352
  // src/wall-thickness.ts
339
353
  var active = WALL_THICKNESS;
340
354
  var wallThickness = () => active;
@@ -814,6 +828,7 @@ var GameFloorplan = (() => {
814
828
  }
815
829
  return [u0, v0, u0 + extentU, v0 + extentV];
816
830
  }
831
+ var BESIDE_GAP = 0.03;
817
832
  var RELAXED_RADIUS = 0.12;
818
833
  var MESH_FRONT = { "+z": [0, 1], "-z": [0, -1], "+x": [1, 0], "-x": [-1, 0] };
819
834
  function rotationFor(f, front) {
@@ -829,6 +844,7 @@ var GameFloorplan = (() => {
829
844
  const state = {};
830
845
  const solids = [];
831
846
  const reserves = [];
847
+ const openings = [];
832
848
  const rims = [];
833
849
  const inners = usableParts(room, 0);
834
850
  const grid = createGrid(plan, room);
@@ -851,11 +867,11 @@ var GameFloorplan = (() => {
851
867
  }
852
868
  for (const u of units) u.required = u.members.some((m) => m.required);
853
869
  const queue = units.filter((u) => u.required).concat(units.filter((u) => !u.required));
854
- 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)));
870
+ 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)));
855
871
  const done = /* @__PURE__ */ new Set();
856
872
  const ready = (u) => dependencies(u).every((id) => done.has(id));
857
873
  const make = (s, it, r, parent, overheadOff) => {
858
- const f = [s.frontU, s.frontV];
874
+ const f = facingOf(s);
859
875
  const id = room.id + "." + s.id;
860
876
  const m = {
861
877
  id,
@@ -891,9 +907,31 @@ var GameFloorplan = (() => {
891
907
  if (parent && s.anchor === "inside") m.y = r2(parent.y || 0);
892
908
  if (room.link) m.link = { from: room.link[0], to: room.link[1] };
893
909
  state[s.id] = m;
910
+ if (s.group && !state[s.group]) state[s.group] = m;
894
911
  items.push(m);
895
912
  return m;
896
913
  };
914
+ const facingOf = (s) => {
915
+ const parent = s.anchor === "beside" ? state[s.on] : void 0;
916
+ return parent ? [parent.frontU ?? 0, parent.frontV ?? 1] : [s.frontU, s.frontV];
917
+ };
918
+ const besideRects = (s, it) => {
919
+ const parent = state[s.on];
920
+ if (!parent) return [];
921
+ const f = [parent.frontU ?? 0, parent.frontV ?? 1];
922
+ const r = parent._r ?? parent.aabb;
923
+ const sign = s.side === "left" ? 1 : -1;
924
+ const t = [-f[1] * sign, f[0] * sign];
925
+ const [extentU, extentV] = extent([it.w, it.d], f);
926
+ const halfAlong = Math.abs(t[0]) * (r[2] - r[0]) / 2 + Math.abs(t[1]) * (r[3] - r[1]) / 2;
927
+ const itemAlong = Math.abs(t[0]) * extentU / 2 + Math.abs(t[1]) * extentV / 2;
928
+ const cu = (r[0] + r[2]) / 2 + t[0] * (halfAlong + BESIDE_GAP + itemAlong);
929
+ const cv = (r[1] + r[3]) / 2 + t[1] * (halfAlong + BESIDE_GAP + itemAlong);
930
+ const back = f[1] > 0 ? r[1] : f[1] < 0 ? r[3] : f[0] > 0 ? r[0] : r[2];
931
+ const u0 = f[0] > 0 ? back : f[0] < 0 ? back - extentU : cu - extentU / 2;
932
+ const v0 = f[1] > 0 ? back : f[1] < 0 ? back - extentV : cv - extentV / 2;
933
+ return [{ rect: [u0, v0, u0 + extentU, v0 + extentV] }];
934
+ };
897
935
  const tryFit = (s, relax, overheadOff) => {
898
936
  const cands = weightedOrder(candidatesOf(s.cats), rng);
899
937
  if (s.anchor === "on" || s.anchor === "inside") {
@@ -912,13 +950,13 @@ var GameFloorplan = (() => {
912
950
  }
913
951
  for (const { it } of cands) {
914
952
  if (it.w > s.w + EPS || it.d > s.d + EPS) continue;
915
- const f = [s.frontU, s.frontV];
953
+ const f = facingOf(s);
916
954
  const slide = s.anchor === "wall" ? s.slide == null ? 2 : s.slide : 0;
917
955
  const shifts = [0];
918
956
  for (let k = 1; k * 0.1 <= slide + 1e-9; k++) shifts.push(k * 0.1, -k * 0.1);
919
957
  let found = null;
920
958
  const car = it.category === "car" && !relax;
921
- const tries = car ? carCandidates(s, it, plan.carClearance) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
959
+ const tries = car ? carCandidates(s, it, plan.carClearance) : s.anchor === "beside" ? besideRects(s, it) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
922
960
  for (const attempt of tries) {
923
961
  const r3 = attempt.rect;
924
962
  if (!insideUnion(r3, inners)) continue;
@@ -930,6 +968,7 @@ var GameFloorplan = (() => {
930
968
  if (zones.some((z) => overlaps(r3, z))) continue;
931
969
  if (windowZones.some(({ z, j }) => blocksWindow(it, j, overheadOff) && overlaps(r3, z))) continue;
932
970
  if (solids.some((o) => overlaps(r3, o))) continue;
971
+ if (openings.some((o) => overlaps(r3, o))) continue;
933
972
  if (!it.deck && rims.some((a) => overlaps(r3, a))) continue;
934
973
  let cl2 = car ? attempt.clear : null;
935
974
  if (!car && !relax && s.clearance > 0 && !it.low) {
@@ -937,6 +976,12 @@ var GameFloorplan = (() => {
937
976
  if (!insideUnion(cl2, inners)) continue;
938
977
  if (items.some((m2) => !m2.low && !m2.flat && !m2.on && overlaps(cl2, m2._r ?? m2.aabb))) continue;
939
978
  }
979
+ let front2 = null;
980
+ if (!car && it.opening && !visorLayout()) {
981
+ front2 = clearRect(r3, f, it.opening);
982
+ if (!insideUnion(front2, inners)) continue;
983
+ if (items.some((m2) => !m2.flat && !m2.on && overlaps(front2, m2._r ?? m2.aabb))) continue;
984
+ }
940
985
  if (!it.low && reserves.some((q) => overlaps(r3, q))) continue;
941
986
  let rimRect2 = null;
942
987
  if (it.rim) {
@@ -944,11 +989,12 @@ var GameFloorplan = (() => {
944
989
  if (!insideUnion(rimRect2, inners) || solids.some((o) => overlaps(rimRect2, o)) || zones.some((z) => overlaps(rimRect2, z))) continue;
945
990
  }
946
991
  if (!(relax ? reachable(relaxedGrid, solids.concat([r3]), RELAXED_RADIUS) : reachable(grid, solids.concat([r3]), inflation))) continue;
947
- found = { rect: r3, cl: cl2, rimRect: rimRect2 };
992
+ found = { rect: r3, cl: cl2, rimRect: rimRect2, front: front2 };
948
993
  break;
949
994
  }
950
995
  if (!found) continue;
951
- const { rect: r, cl, rimRect } = found;
996
+ const { rect: r, cl, rimRect, front } = found;
997
+ if (front) openings.push(front);
952
998
  if (it.flat) return make(s, it, r, null);
953
999
  const m = make(s, it, r, null, overheadOff);
954
1000
  if (cl) reserves.push(cl);
@@ -996,6 +1042,7 @@ var GameFloorplan = (() => {
996
1042
  const u = pending.splice(i, 1)[0];
997
1043
  process2(u);
998
1044
  for (const m of u.members) done.add(m.id);
1045
+ if (u.group) done.add(u.group);
999
1046
  }
1000
1047
  return { items, missing };
1001
1048
  }
@@ -1126,6 +1173,7 @@ var GameFloorplan = (() => {
1126
1173
  continue;
1127
1174
  }
1128
1175
  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;
1176
+ 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;
1129
1177
  if (opts.without && opts.without(r)) continue;
1130
1178
  if (!reachable(opts.railing || gridOf(room), solidList.concat([r]), room.outdoor ? 0.16 : plan.playerRadius)) continue;
1131
1179
  return r;
@@ -1971,6 +2019,7 @@ var GameFloorplan = (() => {
1971
2019
  for (const def of defs) {
1972
2020
  const s = resolveSlot(plan, room, def, byId, zones);
1973
2021
  byId[def.id] = s;
2022
+ if (s.valid && def.group && !byId[def.group]) byId[def.group] = s;
1974
2023
  all.push(s);
1975
2024
  }
1976
2025
  }
@@ -1998,7 +2047,7 @@ var GameFloorplan = (() => {
1998
2047
  reason: null
1999
2048
  };
2000
2049
  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 });
2001
- if (def.anchor === "on" || def.anchor === "inside") {
2050
+ if (def.anchor === "on" || def.anchor === "inside" || def.anchor === "beside") {
2002
2051
  const parent = def.parent ? byId[def.parent] : void 0;
2003
2052
  if (!parent || !parent.valid) return invalid("invalid_parent");
2004
2053
  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 });
@@ -2142,7 +2191,7 @@ var GameFloorplan = (() => {
2142
2191
  function slots(template, options) {
2143
2192
  const tpl = templateOf(template);
2144
2193
  const o = resolveOptions(tpl, options || {});
2145
- return withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o));
2194
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o)));
2146
2195
  }
2147
2196
  function slotsWith(tpl, o) {
2148
2197
  const plan = buildPlan(tpl, o.w, o.d, o);
@@ -2188,7 +2237,7 @@ var GameFloorplan = (() => {
2188
2237
  function generate(template, options) {
2189
2238
  const tpl = templateOf(template);
2190
2239
  const o = resolveOptions(tpl, options || {});
2191
- return withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o));
2240
+ return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o)));
2192
2241
  }
2193
2242
  var resolveOptions = (tpl, options) => registries().OPTION_RESOLVERS.reduce((op, r) => r.resolve(tpl, op), options);
2194
2243
  function generateWith(tpl, o) {
@@ -2487,7 +2536,8 @@ var GameFloorplan = (() => {
2487
2536
  center: (id, fx, fz, size, cats, o) => Object.assign({ id, anchor: "center", fx, fz, size, cats }, o),
2488
2537
  windowSlot: (id, size, cats, o) => Object.assign({ id, anchor: "window", size, cats }, o),
2489
2538
  on: (id, parent, cats, o) => Object.assign({ id, anchor: "on", on: parent, cats }, o),
2490
- inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o)
2539
+ inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o),
2540
+ beside: (id, parent, side, cats, o) => Object.assign({ id, anchor: "beside", on: parent, side, cats }, o)
2491
2541
  };
2492
2542
 
2493
2543
  // src/locales/en.json