feat: add outdoor snapping, terrain types and procedural textures
This commit is contained in:
1 parent
992c3e18f2
commit
d8cf076019
30 files changed
+2251
-1549
No files matched your search
@@ -77,7 +77,7 @@ import { LibraryState, renderLibrary, renderPreview, type LibraryActions } from
|
||||
import { arcFreeWall, arcRoomEdge, insertCorner } from "./editor/ops/rooms.ts";
|
||||
import type { ArcActions, ArcEdit } from "./editor/forms/arc.ts";
|
||||
import { dragStep, facingAngle, gridPositionAfter, hasLeftStart, headingAngle, outlineWithCornerAt, shifted, steppedDelta, straightEnd } from "./editor/ops/drags.ts";
|
||||
import { snapToPlan } from "./editor/ops/snapping.ts";
|
||||
import { snapOutdoorMove, snapToPlan, type SnapOptions } from "./editor/ops/snapping.ts";
|
||||
import { draftLayer, guidesLayer } from "./editor/canvas/draft.ts";
|
||||
import { devicesLayer, furnitureLayer, notesLayer } from "./editor/canvas/items.ts";
|
||||
import { dimensionsLayer } from "./editor/canvas/plan.ts";
|
||||
@@ -1239,10 +1239,10 @@ export class NfEditor extends LitElement {
|
||||
// ------------------------------------------------------------------ snapping
|
||||
|
||||
/** The place in the plan a point lands on: corners and walls of other rooms, then the grid. `free` skips all of that. */
|
||||
private snap(p: Vec2, skip?: { roomId: string; index?: number }, free = false): Vec2 {
|
||||
private snap(p: Vec2, skip?: SnapOptions["skip"], free = false, outdoor = false): Vec2 {
|
||||
this._guides = {};
|
||||
if (free) return p;
|
||||
const snapped = snapToPlan(p, { rooms: this.floor?.rooms ?? [], grid: this._doc.settings.grid, reach: SNAP_PX / this._view.scale, skip });
|
||||
const snapped = snapToPlan(p, { rooms: this.floor?.rooms ?? [], outdoor: outdoor ? this.floor?.outdoor : undefined, grid: this._doc.settings.grid, reach: SNAP_PX / this._view.scale, skip });
|
||||
this._guides = snapped.guides;
|
||||
return snapped.point;
|
||||
}
|
||||
@@ -1481,7 +1481,7 @@ export class NfEditor extends LitElement {
|
||||
private pressDrawingTool(press: Press): Gesture | undefined {
|
||||
const tool = this._tool;
|
||||
if (tool === "rect" || tool === "outdoor" || tool === "hole" || tool === "stairs") {
|
||||
const start = this.snap(press.world, undefined, press.fine);
|
||||
const start = this.snap(press.world, undefined, press.fine, tool === "outdoor");
|
||||
return { kind: "rect", start, end: start, outdoor: tool === "outdoor", hole: tool === "hole", stairs: tool === "stairs" };
|
||||
}
|
||||
if (tool === "polygon" || tool === "measure") return { kind: "tap", startScreen: press.local, last: press.local, panning: false };
|
||||
@@ -1613,7 +1613,7 @@ export class NfEditor extends LitElement {
|
||||
const world = this.toWorld(...local);
|
||||
const drag = this.drag;
|
||||
if (!drag) {
|
||||
if (this._tool !== "select" && this._tool !== "furniture" && this.floor) this._cursor = this.snap(world, undefined, e.altKey);
|
||||
if (this._tool !== "select" && this._tool !== "furniture" && this.floor) this._cursor = this.snap(world, undefined, e.altKey, this._tool === "outdoor");
|
||||
return;
|
||||
}
|
||||
this.moveDrag(drag, { local, world, fine: e.altKey, straight: e.shiftKey });
|
||||
@@ -1661,7 +1661,7 @@ export class NfEditor extends LitElement {
|
||||
drag.last = local;
|
||||
return;
|
||||
case "rect":
|
||||
drag.end = this.snap(world, undefined, fine);
|
||||
drag.end = this.snap(world, undefined, fine, !!drag.outdoor);
|
||||
this.requestUpdate();
|
||||
return;
|
||||
case "freewall":
|
||||
@@ -1786,13 +1786,16 @@ export class NfEditor extends LitElement {
|
||||
drag.moved = true;
|
||||
const area = this.floorOf(drag)?.outdoor.find((o) => o.id === drag.id);
|
||||
if (!area) return;
|
||||
const by = steppedDelta(drag.start, world, dragStep(grid, fine));
|
||||
const initial = this.floorOf(drag)!;
|
||||
const snapped = fine ? { by: steppedDelta(drag.start, world, dragStep(grid, true)), guides: {} } : snapOutdoorMove(area.points, [world[0] - drag.start[0], world[1] - drag.start[1]], { rooms: initial.rooms, outdoor: initial.outdoor, grid, reach: SNAP_PX / this._view.scale, skip: { outdoorId: drag.id } });
|
||||
const { by } = snapped;
|
||||
this._guides = snapped.guides;
|
||||
this.live(drag, (_, floor) => void (floor.outdoor.find((o) => o.id === drag.id)!.points = area.points.map((p) => shifted(p, by))));
|
||||
return;
|
||||
}
|
||||
case "outvertex": {
|
||||
drag.moved = true;
|
||||
const to = this.snap(world, undefined, fine);
|
||||
const to = this.snap(world, { outdoorId: drag.id }, fine, true);
|
||||
const area = this.floorOf(drag)?.outdoor.find((o) => o.id === drag.id);
|
||||
if (!area) return;
|
||||
this.live(drag, (_, floor) => {
|
||||
|
||||
Reference in new issue
Block a user