@adatechnology/game-floorplan 0.4.1 → 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 +14 -2
- package/dist/index.global.js +60 -10
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +60 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -251,6 +251,19 @@ var WINDOWLESS_ROOM_TYPES = /* @__PURE__ */ new Set([
|
|
|
251
251
|
]);
|
|
252
252
|
var CAR_CLEARANCE = { driver: 0.8, side: 0.6, end: 0.6 };
|
|
253
253
|
|
|
254
|
+
// src/layout-mode.ts
|
|
255
|
+
var visor = false;
|
|
256
|
+
var visorLayout = () => visor;
|
|
257
|
+
function withVisorLayout(on, fn) {
|
|
258
|
+
const previous = visor;
|
|
259
|
+
visor = on;
|
|
260
|
+
try {
|
|
261
|
+
return fn();
|
|
262
|
+
} finally {
|
|
263
|
+
visor = previous;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
254
267
|
// src/wall-thickness.ts
|
|
255
268
|
var active = WALL_THICKNESS;
|
|
256
269
|
var wallThickness = () => active;
|
|
@@ -730,6 +743,7 @@ function itemRect(slot, it, shift) {
|
|
|
730
743
|
}
|
|
731
744
|
return [u0, v0, u0 + extentU, v0 + extentV];
|
|
732
745
|
}
|
|
746
|
+
var BESIDE_GAP = 0.03;
|
|
733
747
|
var RELAXED_RADIUS = 0.12;
|
|
734
748
|
var MESH_FRONT = { "+z": [0, 1], "-z": [0, -1], "+x": [1, 0], "-x": [-1, 0] };
|
|
735
749
|
function rotationFor(f, front) {
|
|
@@ -745,6 +759,7 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
745
759
|
const state = {};
|
|
746
760
|
const solids = [];
|
|
747
761
|
const reserves = [];
|
|
762
|
+
const openings = [];
|
|
748
763
|
const rims = [];
|
|
749
764
|
const inners = usableParts(room, 0);
|
|
750
765
|
const grid = createGrid(plan, room);
|
|
@@ -767,11 +782,11 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
767
782
|
}
|
|
768
783
|
for (const u of units) u.required = u.members.some((m) => m.required);
|
|
769
784
|
const queue = units.filter((u) => u.required).concat(units.filter((u) => !u.required));
|
|
770
|
-
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)));
|
|
785
|
+
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)));
|
|
771
786
|
const done = /* @__PURE__ */ new Set();
|
|
772
787
|
const ready = (u) => dependencies(u).every((id) => done.has(id));
|
|
773
788
|
const make = (s, it, r, parent, overheadOff) => {
|
|
774
|
-
const f =
|
|
789
|
+
const f = facingOf(s);
|
|
775
790
|
const id = room.id + "." + s.id;
|
|
776
791
|
const m = {
|
|
777
792
|
id,
|
|
@@ -807,9 +822,31 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
807
822
|
if (parent && s.anchor === "inside") m.y = r2(parent.y || 0);
|
|
808
823
|
if (room.link) m.link = { from: room.link[0], to: room.link[1] };
|
|
809
824
|
state[s.id] = m;
|
|
825
|
+
if (s.group && !state[s.group]) state[s.group] = m;
|
|
810
826
|
items.push(m);
|
|
811
827
|
return m;
|
|
812
828
|
};
|
|
829
|
+
const facingOf = (s) => {
|
|
830
|
+
const parent = s.anchor === "beside" ? state[s.on] : void 0;
|
|
831
|
+
return parent ? [parent.frontU ?? 0, parent.frontV ?? 1] : [s.frontU, s.frontV];
|
|
832
|
+
};
|
|
833
|
+
const besideRects = (s, it) => {
|
|
834
|
+
const parent = state[s.on];
|
|
835
|
+
if (!parent) return [];
|
|
836
|
+
const f = [parent.frontU ?? 0, parent.frontV ?? 1];
|
|
837
|
+
const r = parent._r ?? parent.aabb;
|
|
838
|
+
const sign = s.side === "left" ? 1 : -1;
|
|
839
|
+
const t = [-f[1] * sign, f[0] * sign];
|
|
840
|
+
const [extentU, extentV] = extent([it.w, it.d], f);
|
|
841
|
+
const halfAlong = Math.abs(t[0]) * (r[2] - r[0]) / 2 + Math.abs(t[1]) * (r[3] - r[1]) / 2;
|
|
842
|
+
const itemAlong = Math.abs(t[0]) * extentU / 2 + Math.abs(t[1]) * extentV / 2;
|
|
843
|
+
const cu = (r[0] + r[2]) / 2 + t[0] * (halfAlong + BESIDE_GAP + itemAlong);
|
|
844
|
+
const cv = (r[1] + r[3]) / 2 + t[1] * (halfAlong + BESIDE_GAP + itemAlong);
|
|
845
|
+
const back = f[1] > 0 ? r[1] : f[1] < 0 ? r[3] : f[0] > 0 ? r[0] : r[2];
|
|
846
|
+
const u0 = f[0] > 0 ? back : f[0] < 0 ? back - extentU : cu - extentU / 2;
|
|
847
|
+
const v0 = f[1] > 0 ? back : f[1] < 0 ? back - extentV : cv - extentV / 2;
|
|
848
|
+
return [{ rect: [u0, v0, u0 + extentU, v0 + extentV] }];
|
|
849
|
+
};
|
|
813
850
|
const tryFit = (s, relax, overheadOff) => {
|
|
814
851
|
const cands = weightedOrder(candidatesOf(s.cats), rng);
|
|
815
852
|
if (s.anchor === "on" || s.anchor === "inside") {
|
|
@@ -828,13 +865,13 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
828
865
|
}
|
|
829
866
|
for (const { it } of cands) {
|
|
830
867
|
if (it.w > s.w + EPS || it.d > s.d + EPS) continue;
|
|
831
|
-
const f =
|
|
868
|
+
const f = facingOf(s);
|
|
832
869
|
const slide = s.anchor === "wall" ? s.slide == null ? 2 : s.slide : 0;
|
|
833
870
|
const shifts = [0];
|
|
834
871
|
for (let k = 1; k * 0.1 <= slide + 1e-9; k++) shifts.push(k * 0.1, -k * 0.1);
|
|
835
872
|
let found = null;
|
|
836
873
|
const car = it.category === "car" && !relax;
|
|
837
|
-
const tries = car ? carCandidates(s, it, plan.carClearance) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
|
|
874
|
+
const tries = car ? carCandidates(s, it, plan.carClearance) : s.anchor === "beside" ? besideRects(s, it) : shifts.map((shift) => ({ rect: itemRect(s, it, shift) }));
|
|
838
875
|
for (const attempt of tries) {
|
|
839
876
|
const r3 = attempt.rect;
|
|
840
877
|
if (!insideUnion(r3, inners)) continue;
|
|
@@ -846,6 +883,7 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
846
883
|
if (zones.some((z) => overlaps(r3, z))) continue;
|
|
847
884
|
if (windowZones.some(({ z, j }) => blocksWindow(it, j, overheadOff) && overlaps(r3, z))) continue;
|
|
848
885
|
if (solids.some((o) => overlaps(r3, o))) continue;
|
|
886
|
+
if (openings.some((o) => overlaps(r3, o))) continue;
|
|
849
887
|
if (!it.deck && rims.some((a) => overlaps(r3, a))) continue;
|
|
850
888
|
let cl2 = car ? attempt.clear : null;
|
|
851
889
|
if (!car && !relax && s.clearance > 0 && !it.low) {
|
|
@@ -853,6 +891,12 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
853
891
|
if (!insideUnion(cl2, inners)) continue;
|
|
854
892
|
if (items.some((m2) => !m2.low && !m2.flat && !m2.on && overlaps(cl2, m2._r ?? m2.aabb))) continue;
|
|
855
893
|
}
|
|
894
|
+
let front2 = null;
|
|
895
|
+
if (!car && it.opening && !visorLayout()) {
|
|
896
|
+
front2 = clearRect(r3, f, it.opening);
|
|
897
|
+
if (!insideUnion(front2, inners)) continue;
|
|
898
|
+
if (items.some((m2) => !m2.flat && !m2.on && overlaps(front2, m2._r ?? m2.aabb))) continue;
|
|
899
|
+
}
|
|
856
900
|
if (!it.low && reserves.some((q) => overlaps(r3, q))) continue;
|
|
857
901
|
let rimRect2 = null;
|
|
858
902
|
if (it.rim) {
|
|
@@ -860,11 +904,12 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
860
904
|
if (!insideUnion(rimRect2, inners) || solids.some((o) => overlaps(rimRect2, o)) || zones.some((z) => overlaps(rimRect2, z))) continue;
|
|
861
905
|
}
|
|
862
906
|
if (!(relax ? reachable(relaxedGrid, solids.concat([r3]), RELAXED_RADIUS) : reachable(grid, solids.concat([r3]), inflation))) continue;
|
|
863
|
-
found = { rect: r3, cl: cl2, rimRect: rimRect2 };
|
|
907
|
+
found = { rect: r3, cl: cl2, rimRect: rimRect2, front: front2 };
|
|
864
908
|
break;
|
|
865
909
|
}
|
|
866
910
|
if (!found) continue;
|
|
867
|
-
const { rect: r, cl, rimRect } = found;
|
|
911
|
+
const { rect: r, cl, rimRect, front } = found;
|
|
912
|
+
if (front) openings.push(front);
|
|
868
913
|
if (it.flat) return make(s, it, r, null);
|
|
869
914
|
const m = make(s, it, r, null, overheadOff);
|
|
870
915
|
if (cl) reserves.push(cl);
|
|
@@ -912,6 +957,7 @@ function fillRoom(plan, room, slots2, rng) {
|
|
|
912
957
|
const u = pending.splice(i, 1)[0];
|
|
913
958
|
process(u);
|
|
914
959
|
for (const m of u.members) done.add(m.id);
|
|
960
|
+
if (u.group) done.add(u.group);
|
|
915
961
|
}
|
|
916
962
|
return { items, missing };
|
|
917
963
|
}
|
|
@@ -1042,6 +1088,7 @@ function createPlacementContext(plan, items) {
|
|
|
1042
1088
|
continue;
|
|
1043
1089
|
}
|
|
1044
1090
|
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;
|
|
1091
|
+
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;
|
|
1045
1092
|
if (opts.without && opts.without(r)) continue;
|
|
1046
1093
|
if (!reachable(opts.railing || gridOf(room), solidList.concat([r]), room.outdoor ? 0.16 : plan.playerRadius)) continue;
|
|
1047
1094
|
return r;
|
|
@@ -1887,6 +1934,7 @@ function resolveSlots(plan) {
|
|
|
1887
1934
|
for (const def of defs) {
|
|
1888
1935
|
const s = resolveSlot(plan, room, def, byId, zones);
|
|
1889
1936
|
byId[def.id] = s;
|
|
1937
|
+
if (s.valid && def.group && !byId[def.group]) byId[def.group] = s;
|
|
1890
1938
|
all.push(s);
|
|
1891
1939
|
}
|
|
1892
1940
|
}
|
|
@@ -1914,7 +1962,7 @@ function resolveSlot(plan, room, def, byId, zones) {
|
|
|
1914
1962
|
reason: null
|
|
1915
1963
|
};
|
|
1916
1964
|
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 });
|
|
1917
|
-
if (def.anchor === "on" || def.anchor === "inside") {
|
|
1965
|
+
if (def.anchor === "on" || def.anchor === "inside" || def.anchor === "beside") {
|
|
1918
1966
|
const parent = def.parent ? byId[def.parent] : void 0;
|
|
1919
1967
|
if (!parent || !parent.valid) return invalid("invalid_parent");
|
|
1920
1968
|
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 });
|
|
@@ -2058,7 +2106,7 @@ var cleanSlot = (s) => {
|
|
|
2058
2106
|
function slots(template, options) {
|
|
2059
2107
|
const tpl = templateOf(template);
|
|
2060
2108
|
const o = resolveOptions(tpl, options || {});
|
|
2061
|
-
return withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o));
|
|
2109
|
+
return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => slotsWith(tpl, o)));
|
|
2062
2110
|
}
|
|
2063
2111
|
function slotsWith(tpl, o) {
|
|
2064
2112
|
const plan = buildPlan(tpl, o.w, o.d, o);
|
|
@@ -2104,7 +2152,7 @@ var loc = (key, locale, ns = "labels", vars) => key ? translate(ns, key, locale,
|
|
|
2104
2152
|
function generate(template, options) {
|
|
2105
2153
|
const tpl = templateOf(template);
|
|
2106
2154
|
const o = resolveOptions(tpl, options || {});
|
|
2107
|
-
return withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o));
|
|
2155
|
+
return withVisorLayout(o.visorLayout === true, () => withWallThickness(wallThicknessFor(tpl, o), () => generateWith(tpl, o)));
|
|
2108
2156
|
}
|
|
2109
2157
|
var resolveOptions = (tpl, options) => registries().OPTION_RESOLVERS.reduce((op, r) => r.resolve(tpl, op), options);
|
|
2110
2158
|
function generateWith(tpl, o) {
|
|
@@ -2272,7 +2320,8 @@ var slotKit = {
|
|
|
2272
2320
|
center: (id, fx, fz, size, cats, o) => Object.assign({ id, anchor: "center", fx, fz, size, cats }, o),
|
|
2273
2321
|
windowSlot: (id, size, cats, o) => Object.assign({ id, anchor: "window", size, cats }, o),
|
|
2274
2322
|
on: (id, parent, cats, o) => Object.assign({ id, anchor: "on", on: parent, cats }, o),
|
|
2275
|
-
inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o)
|
|
2323
|
+
inside: (id, parent, cats, o) => Object.assign({ id, anchor: "inside", on: parent, cats }, o),
|
|
2324
|
+
beside: (id, parent, side, cats, o) => Object.assign({ id, anchor: "beside", on: parent, side, cats }, o)
|
|
2276
2325
|
};
|
|
2277
2326
|
|
|
2278
2327
|
// src/locales/en.json
|
|
@@ -2846,6 +2895,7 @@ export {
|
|
|
2846
2895
|
translate,
|
|
2847
2896
|
validate,
|
|
2848
2897
|
version,
|
|
2898
|
+
visorLayout,
|
|
2849
2899
|
windowZone
|
|
2850
2900
|
};
|
|
2851
2901
|
//# sourceMappingURL=index.js.map
|