Editor: doors and windows are now movable, resizable, deletable
Browse filesOpenings are real objects stored against their room + wall side as {t, w}, so
they survive room moves/resizes. Click to select, drag to slide along the wall,
drag an end dot to resize, Delete to remove. Editor-only, never scored.
Verified in Node: correct placement and 504/504 clamp checks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- floorplan_editor/frontend/index.html +197 -57
floorplan_editor/frontend/index.html
CHANGED
|
@@ -256,9 +256,8 @@ function draw() {
|
|
| 256 |
// eats half its thickness from each room; toggled by the Walls button
|
| 257 |
if (showWalls) drawWalls();
|
| 258 |
|
| 259 |
-
// Doors / Windows
|
| 260 |
-
if (showDoors)
|
| 261 |
-
if (showWindows) drawWindows();
|
| 262 |
|
| 263 |
// Locked-adjacency indicator (bright green on shared walls). Hidden while the
|
| 264 |
// Walls overlay is on, so walls read as ONE uniform material throughout
|
|
@@ -376,44 +375,20 @@ function accessNeighbours(name) {
|
|
| 376 |
return CIRC;
|
| 377 |
}
|
| 378 |
|
| 379 |
-
//
|
| 380 |
-
//
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
const allow = accessNeighbours(r.name);
|
| 388 |
-
const w = sharedSeg(r, o=>allow.indexOf(o.name)>=0);
|
| 389 |
-
if (!w) continue; // no legitimate access wall β no door
|
| 390 |
-
const D=Math.min(3, w.len); // 3 ft leaf
|
| 391 |
-
const mid=(w.lo+w.hi)/2, a=mid-D/2;
|
| 392 |
-
if (w.vert) {
|
| 393 |
-
const cx=cxOf(w.at), dir=(w.side==="L")?1:-1;
|
| 394 |
-
ctx.strokeStyle="#FFFFFF"; ctx.lineWidth=4;
|
| 395 |
-
ctx.beginPath(); ctx.moveTo(cx,cyOf(mid-D/2)); ctx.lineTo(cx,cyOf(mid+D/2)); ctx.stroke();
|
| 396 |
-
ctx.strokeStyle="#6D4C41"; ctx.lineWidth=1.5;
|
| 397 |
-
ctx.beginPath(); ctx.moveTo(cx,cyOf(a)); ctx.lineTo(cx+dir*D*scale,cyOf(a)); ctx.stroke();
|
| 398 |
-
ctx.beginPath(); ctx.arc(cx,cyOf(a),D*scale,dir>0?0:Math.PI,dir>0?-Math.PI/2:-Math.PI/2,dir>0); ctx.stroke();
|
| 399 |
-
} else {
|
| 400 |
-
const cy=cyOf(w.at), dir=(w.side==="B")?-1:1; // canvas y is flipped
|
| 401 |
-
ctx.strokeStyle="#FFFFFF"; ctx.lineWidth=4;
|
| 402 |
-
ctx.beginPath(); ctx.moveTo(cxOf(mid-D/2),cy); ctx.lineTo(cxOf(mid+D/2),cy); ctx.stroke();
|
| 403 |
-
ctx.strokeStyle="#6D4C41"; ctx.lineWidth=1.5;
|
| 404 |
-
ctx.beginPath(); ctx.moveTo(cxOf(a),cy); ctx.lineTo(cxOf(a),cy+dir*D*scale); ctx.stroke();
|
| 405 |
-
ctx.beginPath(); ctx.arc(cxOf(a),cy,D*scale,dir<0?Math.PI/2:-Math.PI/2,dir<0?Math.PI:0,dir<0); ctx.stroke();
|
| 406 |
-
}
|
| 407 |
-
}
|
| 408 |
-
ctx.restore();
|
| 409 |
-
}
|
| 410 |
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
function
|
| 414 |
-
const cxOf=X=>PAD.l+X*scale, cyOf=Y=>PAD.t+(plotH-Y)*scale;
|
| 415 |
const tol=0.6, minOv=1.0;
|
| 416 |
-
|
| 417 |
if (o===r) return false;
|
| 418 |
const yOv=Math.min(o.y+o.h,r.y+r.h)-Math.max(o.y,r.y)>=minOv;
|
| 419 |
const xOv=Math.min(o.x+o.w,r.x+r.w)-Math.max(o.x,r.x)>=minOv;
|
|
@@ -423,28 +398,129 @@ function drawWindows() {
|
|
| 423 |
if (side==="T") return Math.abs(r.y+r.h-o.y)<tol && xOv;
|
| 424 |
return false;
|
| 425 |
});
|
| 426 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
for (const r of rooms) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
for (const side of ["L","R","B","T"]) {
|
| 429 |
-
if (
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
if (
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
} else {
|
| 438 |
-
const
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
}
|
| 443 |
}
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
ctx.restore();
|
| 446 |
}
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
function drawGap(g) {
|
| 449 |
const cx=toCx(g.x), cy=toCy(g.y,g.h), cw=g.w*scale, ch=g.h*scale;
|
| 450 |
ctx.save();
|
|
@@ -778,6 +854,24 @@ function mousePos(e) {
|
|
| 778 |
// ββ Mouse handlers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 779 |
cv.addEventListener("mousedown", e => {
|
| 780 |
const {x:mx,y:my} = mousePos(e);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 781 |
const h = hitHandle(mx, my);
|
| 782 |
if (h) { // resize (allowed for every resizable room)
|
| 783 |
const r=rooms[selIdx];
|
|
@@ -801,6 +895,10 @@ cv.addEventListener("mousedown", e => {
|
|
| 801 |
cv.addEventListener("mousemove", e => {
|
| 802 |
if (mode) return;
|
| 803 |
const {x:mx,y:my} = mousePos(e);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
const h = hitHandle(mx, my);
|
| 805 |
if (h) { cv.style.cursor="nwse-resize"; return; }
|
| 806 |
const ri = hitRoom(mx,my);
|
|
@@ -812,6 +910,29 @@ document.addEventListener("mousemove", e => {
|
|
| 812 |
const {x:mx,y:my} = mousePos(e);
|
| 813 |
const dCx=mx-msx, dCy=my-msy;
|
| 814 |
const dFx=dCx/scale, dFy=-dCy/scale;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
if (mode==="drag") {
|
| 816 |
const r=rooms[iIdx], s=sb();
|
| 817 |
r.x = snap(Math.max(s.l, Math.min(rx0+dFx, plotW-s.r-r.w)));
|
|
@@ -833,6 +954,9 @@ document.addEventListener("mousemove", e => {
|
|
| 833 |
});
|
| 834 |
|
| 835 |
document.addEventListener("mouseup", () => {
|
|
|
|
|
|
|
|
|
|
| 836 |
if (!mode || iIdx < 0) { mode=null; iIdx=-1; cv.style.cursor="default"; return; }
|
| 837 |
if (checkLockedConstraints(iIdx)) { mode=null; iIdx=-1; cv.style.cursor="default"; refreshGap(); return; }
|
| 838 |
const r=rooms[iIdx];
|
|
@@ -893,17 +1017,32 @@ document.getElementById("btn-walls").addEventListener("click", (e) => {
|
|
| 893 |
document.getElementById("btn-doors").addEventListener("click", (e) => {
|
| 894 |
showDoors = !showDoors;
|
| 895 |
e.target.textContent = showDoors ? "Doors: On" : "Doors: Off";
|
| 896 |
-
|
| 897 |
-
|
|
|
|
|
|
|
|
|
|
| 898 |
draw();
|
| 899 |
});
|
| 900 |
document.getElementById("btn-windows").addEventListener("click", (e) => {
|
| 901 |
showWindows = !showWindows;
|
| 902 |
e.target.textContent = showWindows ? "Windows: On" : "Windows: Off";
|
| 903 |
-
|
| 904 |
-
|
|
|
|
|
|
|
|
|
|
| 905 |
draw();
|
| 906 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 907 |
document.getElementById("fill-balcony").addEventListener("click", ()=>fillGapWith("balcony"));
|
| 908 |
document.getElementById("fill-study").addEventListener("click", ()=>fillGapWith("study"));
|
| 909 |
document.getElementById("fill-passage").addEventListener("click", ()=>fillGapWith("passage"));
|
|
@@ -1034,6 +1173,7 @@ window.addEventListener("message", e => {
|
|
| 1034 |
// keep the staircase at the size the plan produced (10'Γ12' portrait for
|
| 1035 |
// N/S roads, 12'Γ10' landscape for E/W) β do NOT force a fixed size, that
|
| 1036 |
// used to grow a portrait staircase and push it out of the plot box
|
|
|
|
| 1037 |
origRooms = rooms.map(r=>({...r}));
|
| 1038 |
computeLockedConstraints();
|
| 1039 |
selIdx=-1; dirty=false;
|
|
|
|
| 256 |
// eats half its thickness from each room; toggled by the Walls button
|
| 257 |
if (showWalls) drawWalls();
|
| 258 |
|
| 259 |
+
// Doors / Windows β editable openings (slide, resize, delete)
|
| 260 |
+
if (showDoors || showWindows) drawOpenings();
|
|
|
|
| 261 |
|
| 262 |
// Locked-adjacency indicator (bright green on shared walls). Hidden while the
|
| 263 |
// Walls overlay is on, so walls read as ONE uniform material throughout
|
|
|
|
| 375 |
return CIRC;
|
| 376 |
}
|
| 377 |
|
| 378 |
+
// ββ Openings (doors / windows) as EDITABLE objects ββββββββββββββββββββββββββββ
|
| 379 |
+
// Each opening is stored against its room + wall side, with `t` = the centre's
|
| 380 |
+
// offset along that wall and `w` = its width, so it survives the room being
|
| 381 |
+
// moved or resized. They are auto-seeded once, then you can slide, resize or
|
| 382 |
+
// delete them. Editor-only: never sent to Python, never scored.
|
| 383 |
+
let openings = []; // {kind:"door"|"window", room, side:"L|R|B|T", t, w}
|
| 384 |
+
let selOpening = -1;
|
| 385 |
+
let opSaved = null, opEdge = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
+
function roomByName(n){ return rooms.find(r=>r.name===n); }
|
| 388 |
+
|
| 389 |
+
function sideHasNeighbour(r, side) {
|
|
|
|
| 390 |
const tol=0.6, minOv=1.0;
|
| 391 |
+
return rooms.some(o=>{
|
| 392 |
if (o===r) return false;
|
| 393 |
const yOv=Math.min(o.y+o.h,r.y+r.h)-Math.max(o.y,r.y)>=minOv;
|
| 394 |
const xOv=Math.min(o.x+o.w,r.x+r.w)-Math.max(o.x,r.x)>=minOv;
|
|
|
|
| 398 |
if (side==="T") return Math.abs(r.y+r.h-o.y)<tol && xOv;
|
| 399 |
return false;
|
| 400 |
});
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
// World geometry of an opening (clamped onto its wall), or null if room is gone
|
| 404 |
+
function openingGeom(o) {
|
| 405 |
+
const r = roomByName(o.room); if (!r) return null;
|
| 406 |
+
const vert = (o.side==="L"||o.side==="R");
|
| 407 |
+
const span = vert ? r.h : r.w;
|
| 408 |
+
const w = Math.max(0.8, Math.min(o.w, span));
|
| 409 |
+
const t = Math.max(w/2, Math.min(o.t, span - w/2));
|
| 410 |
+
const at = o.side==="L" ? r.x : o.side==="R" ? r.x+r.w
|
| 411 |
+
: o.side==="B" ? r.y : r.y+r.h;
|
| 412 |
+
const base = vert ? r.y : r.x;
|
| 413 |
+
return { vert, at, lo: base+t-w/2, hi: base+t+w/2, w, room:r };
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
// One door on each room's legitimate access wall, one window on each exterior
|
| 417 |
+
// wall β added only if that room/side has no opening yet, so user edits stick.
|
| 418 |
+
function seedOpenings() {
|
| 419 |
+
const isCirc=o=>o.name==="living_room"||o.name==="dining_room"||o.name==="internal_corridor";
|
| 420 |
+
const have = new Set(openings.map(o=>o.kind+"|"+o.room+"|"+o.side));
|
| 421 |
for (const r of rooms) {
|
| 422 |
+
if (!isCirc(r)) {
|
| 423 |
+
const allow = accessNeighbours(r.name);
|
| 424 |
+
const s = sharedSeg(r, o=>allow.indexOf(o.name)>=0);
|
| 425 |
+
if (s && !have.has("door|"+r.name+"|"+s.side)) {
|
| 426 |
+
const base = s.vert ? r.y : r.x;
|
| 427 |
+
openings.push({kind:"door", room:r.name, side:s.side,
|
| 428 |
+
t:(s.lo+s.hi)/2 - base, w:Math.min(3, s.len)});
|
| 429 |
+
have.add("door|"+r.name+"|"+s.side);
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
for (const side of ["L","R","B","T"]) {
|
| 433 |
+
if (sideHasNeighbour(r, side)) continue;
|
| 434 |
+
if (have.has("window|"+r.name+"|"+side)) continue;
|
| 435 |
+
const span = (side==="L"||side==="R") ? r.h : r.w;
|
| 436 |
+
if (span < 2) continue;
|
| 437 |
+
openings.push({kind:"window", room:r.name, side, t:span/2,
|
| 438 |
+
w:Math.min(3.5, span*0.6)});
|
| 439 |
+
have.add("window|"+r.name+"|"+side);
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
openings = openings.filter(o=>roomByName(o.room));
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
function drawOpenings() {
|
| 446 |
+
const cxOf=X=>PAD.l+X*scale, cyOf=Y=>PAD.t+(plotH-Y)*scale;
|
| 447 |
+
ctx.save();
|
| 448 |
+
openings.forEach((o,i)=>{
|
| 449 |
+
if (o.kind==="door" && !showDoors) return;
|
| 450 |
+
if (o.kind==="window" && !showWindows) return;
|
| 451 |
+
const g=openingGeom(o); if (!g) return;
|
| 452 |
+
const sel=(i===selOpening), R=(g.hi-g.lo)*scale;
|
| 453 |
+
if (o.kind==="door") {
|
| 454 |
+
if (g.vert) {
|
| 455 |
+
const cx=cxOf(g.at), hy=cyOf(g.lo);
|
| 456 |
+
const dir=(g.room.x+g.room.w/2 > g.at)?1:-1; // swing into the room
|
| 457 |
+
ctx.strokeStyle="#FFFFFF"; ctx.lineWidth=4;
|
| 458 |
+
ctx.beginPath(); ctx.moveTo(cx,cyOf(g.lo)); ctx.lineTo(cx,cyOf(g.hi)); ctx.stroke();
|
| 459 |
+
ctx.strokeStyle=sel?"#FFD700":"#6D4C41"; ctx.lineWidth=sel?2.5:1.5;
|
| 460 |
+
ctx.beginPath(); ctx.moveTo(cx,hy); ctx.lineTo(cx+dir*R,hy); ctx.stroke();
|
| 461 |
+
ctx.beginPath();
|
| 462 |
+
if (dir>0) ctx.arc(cx,hy,R,0,-Math.PI/2,true);
|
| 463 |
+
else ctx.arc(cx,hy,R,Math.PI,Math.PI*1.5,false);
|
| 464 |
+
ctx.stroke();
|
| 465 |
} else {
|
| 466 |
+
const cy=cyOf(g.at), hx=cxOf(g.lo);
|
| 467 |
+
const dir=(g.room.y+g.room.h/2 > g.at)?-1:1; // canvas y is flipped
|
| 468 |
+
ctx.strokeStyle="#FFFFFF"; ctx.lineWidth=4;
|
| 469 |
+
ctx.beginPath(); ctx.moveTo(cxOf(g.lo),cy); ctx.lineTo(cxOf(g.hi),cy); ctx.stroke();
|
| 470 |
+
ctx.strokeStyle=sel?"#FFD700":"#6D4C41"; ctx.lineWidth=sel?2.5:1.5;
|
| 471 |
+
ctx.beginPath(); ctx.moveTo(hx,cy); ctx.lineTo(hx,cy+dir*R); ctx.stroke();
|
| 472 |
+
ctx.beginPath();
|
| 473 |
+
if (dir<0) ctx.arc(hx,cy,R,-Math.PI/2,0,false);
|
| 474 |
+
else ctx.arc(hx,cy,R,0,Math.PI/2,false);
|
| 475 |
+
ctx.stroke();
|
| 476 |
+
}
|
| 477 |
+
} else {
|
| 478 |
+
ctx.strokeStyle=sel?"#FFD700":"#29B6F6"; ctx.lineWidth=sel?3:2;
|
| 479 |
+
if (g.vert) {
|
| 480 |
+
const cx=cxOf(g.at);
|
| 481 |
+
for (const off of [-1.5,1.5]) { ctx.beginPath(); ctx.moveTo(cx+off,cyOf(g.lo)); ctx.lineTo(cx+off,cyOf(g.hi)); ctx.stroke(); }
|
| 482 |
+
} else {
|
| 483 |
+
const cy=cyOf(g.at);
|
| 484 |
+
for (const off of [-1.5,1.5]) { ctx.beginPath(); ctx.moveTo(cxOf(g.lo),cy+off); ctx.lineTo(cxOf(g.hi),cy+off); ctx.stroke(); }
|
| 485 |
}
|
| 486 |
}
|
| 487 |
+
if (sel) { // round end handles for resize
|
| 488 |
+
ctx.fillStyle="#FFD700";
|
| 489 |
+
const pts = g.vert ? [[cxOf(g.at),cyOf(g.lo)],[cxOf(g.at),cyOf(g.hi)]]
|
| 490 |
+
: [[cxOf(g.lo),cyOf(g.at)],[cxOf(g.hi),cyOf(g.at)]];
|
| 491 |
+
for (const p of pts) { ctx.beginPath(); ctx.arc(p[0],p[1],3.5,0,Math.PI*2); ctx.fill(); }
|
| 492 |
+
}
|
| 493 |
+
});
|
| 494 |
ctx.restore();
|
| 495 |
}
|
| 496 |
|
| 497 |
+
// Hit-test an opening: {i, part:"move"|"lo"|"hi"} or null
|
| 498 |
+
function hitOpening(mx,my) {
|
| 499 |
+
const cxOf=X=>PAD.l+X*scale, cyOf=Y=>PAD.t+(plotH-Y)*scale;
|
| 500 |
+
for (let i=openings.length-1;i>=0;i--) {
|
| 501 |
+
const o=openings[i];
|
| 502 |
+
if (o.kind==="door" && !showDoors) continue;
|
| 503 |
+
if (o.kind==="window" && !showWindows) continue;
|
| 504 |
+
const g=openingGeom(o); if (!g) continue;
|
| 505 |
+
if (g.vert) {
|
| 506 |
+
const cx=cxOf(g.at), yHi=cyOf(g.hi), yLo=cyOf(g.lo);
|
| 507 |
+
if (Math.abs(mx-cx)<=6 && my>=yHi-6 && my<=yLo+6) {
|
| 508 |
+
if (Math.abs(my-yLo)<=6) return {i, part:"lo"};
|
| 509 |
+
if (Math.abs(my-yHi)<=6) return {i, part:"hi"};
|
| 510 |
+
return {i, part:"move"};
|
| 511 |
+
}
|
| 512 |
+
} else {
|
| 513 |
+
const cy=cyOf(g.at), xLo=cxOf(g.lo), xHi=cxOf(g.hi);
|
| 514 |
+
if (Math.abs(my-cy)<=6 && mx>=xLo-6 && mx<=xHi+6) {
|
| 515 |
+
if (Math.abs(mx-xLo)<=6) return {i, part:"lo"};
|
| 516 |
+
if (Math.abs(mx-xHi)<=6) return {i, part:"hi"};
|
| 517 |
+
return {i, part:"move"};
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
}
|
| 521 |
+
return null;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
function drawGap(g) {
|
| 525 |
const cx=toCx(g.x), cy=toCy(g.y,g.h), cw=g.w*scale, ch=g.h*scale;
|
| 526 |
ctx.save();
|
|
|
|
| 854 |
// ββ Mouse handlers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 855 |
cv.addEventListener("mousedown", e => {
|
| 856 |
const {x:mx,y:my} = mousePos(e);
|
| 857 |
+
// A door/window takes the click before any room does
|
| 858 |
+
if (showDoors || showWindows) {
|
| 859 |
+
const ho = hitOpening(mx, my);
|
| 860 |
+
if (ho) {
|
| 861 |
+
selOpening = ho.i; selIdx = -1; updateUI();
|
| 862 |
+
const o = openings[ho.i];
|
| 863 |
+
opSaved = {...o}; opEdge = ho.part;
|
| 864 |
+
mode = (ho.part==="move") ? "op-move" : "op-size";
|
| 865 |
+
msx = mx; msy = my;
|
| 866 |
+
cv.style.cursor = (ho.part==="move") ? "grabbing" : "move";
|
| 867 |
+
setInfo(`${o.kind==="door"?"Door":"Window"} on ${prettyName(o.room)} β `
|
| 868 |
+
+ `${o.w.toFixed(1)}' wide. Drag to slide Β· drag an end dot to `
|
| 869 |
+
+ `resize Β· Delete to remove.`);
|
| 870 |
+
draw();
|
| 871 |
+
return;
|
| 872 |
+
}
|
| 873 |
+
selOpening = -1;
|
| 874 |
+
}
|
| 875 |
const h = hitHandle(mx, my);
|
| 876 |
if (h) { // resize (allowed for every resizable room)
|
| 877 |
const r=rooms[selIdx];
|
|
|
|
| 895 |
cv.addEventListener("mousemove", e => {
|
| 896 |
if (mode) return;
|
| 897 |
const {x:mx,y:my} = mousePos(e);
|
| 898 |
+
if (showDoors || showWindows) {
|
| 899 |
+
const ho = hitOpening(mx, my);
|
| 900 |
+
if (ho) { cv.style.cursor = (ho.part==="move") ? "grab" : "move"; return; }
|
| 901 |
+
}
|
| 902 |
const h = hitHandle(mx, my);
|
| 903 |
if (h) { cv.style.cursor="nwse-resize"; return; }
|
| 904 |
const ri = hitRoom(mx,my);
|
|
|
|
| 910 |
const {x:mx,y:my} = mousePos(e);
|
| 911 |
const dCx=mx-msx, dCy=my-msy;
|
| 912 |
const dFx=dCx/scale, dFy=-dCy/scale;
|
| 913 |
+
if (mode==="op-move" || mode==="op-size") {
|
| 914 |
+
const o=openings[selOpening]; if (!o) return;
|
| 915 |
+
const r=roomByName(o.room); if (!r) return;
|
| 916 |
+
const vert=(o.side==="L"||o.side==="R");
|
| 917 |
+
const span=vert ? r.h : r.w;
|
| 918 |
+
const d = vert ? dFy : dFx; // travel along the wall, in ft
|
| 919 |
+
// NB: round FIRST, then clamp β rounding after clamping can nudge the
|
| 920 |
+
// value back past the wall end.
|
| 921 |
+
const r1=v=>Math.round(v*10)/10;
|
| 922 |
+
if (mode==="op-move") {
|
| 923 |
+
o.t = Math.max(o.w/2, Math.min(r1(opSaved.t + d), span - o.w/2));
|
| 924 |
+
} else {
|
| 925 |
+
// dragging an end changes the width and shifts the centre by half
|
| 926 |
+
const w = Math.max(0.8, Math.min(r1((opEdge==="hi") ? opSaved.w + d
|
| 927 |
+
: opSaved.w - d), span));
|
| 928 |
+
o.w = w;
|
| 929 |
+
o.t = Math.max(w/2, Math.min(r1(opSaved.t + d/2), span - w/2));
|
| 930 |
+
}
|
| 931 |
+
setInfo(`${o.kind==="door"?"Door":"Window"} on ${prettyName(o.room)} β `
|
| 932 |
+
+ `${o.w.toFixed(1)}' wide, ${o.t.toFixed(1)}' along the wall.`);
|
| 933 |
+
draw();
|
| 934 |
+
return;
|
| 935 |
+
}
|
| 936 |
if (mode==="drag") {
|
| 937 |
const r=rooms[iIdx], s=sb();
|
| 938 |
r.x = snap(Math.max(s.l, Math.min(rx0+dFx, plotW-s.r-r.w)));
|
|
|
|
| 954 |
});
|
| 955 |
|
| 956 |
document.addEventListener("mouseup", () => {
|
| 957 |
+
if (mode==="op-move" || mode==="op-size") { // openings are editor-only
|
| 958 |
+
mode=null; opSaved=null; opEdge=null; cv.style.cursor="default"; return;
|
| 959 |
+
}
|
| 960 |
if (!mode || iIdx < 0) { mode=null; iIdx=-1; cv.style.cursor="default"; return; }
|
| 961 |
if (checkLockedConstraints(iIdx)) { mode=null; iIdx=-1; cv.style.cursor="default"; refreshGap(); return; }
|
| 962 |
const r=rooms[iIdx];
|
|
|
|
| 1017 |
document.getElementById("btn-doors").addEventListener("click", (e) => {
|
| 1018 |
showDoors = !showDoors;
|
| 1019 |
e.target.textContent = showDoors ? "Doors: On" : "Doors: Off";
|
| 1020 |
+
if (showDoors) seedOpenings();
|
| 1021 |
+
setStatus(showDoors
|
| 1022 |
+
? "Doors on β click one to select, drag it to slide along the wall, drag a "
|
| 1023 |
+
+ "yellow end dot to resize, press Delete to remove it."
|
| 1024 |
+
: "Doors hidden.");
|
| 1025 |
draw();
|
| 1026 |
});
|
| 1027 |
document.getElementById("btn-windows").addEventListener("click", (e) => {
|
| 1028 |
showWindows = !showWindows;
|
| 1029 |
e.target.textContent = showWindows ? "Windows: On" : "Windows: Off";
|
| 1030 |
+
if (showWindows) seedOpenings();
|
| 1031 |
+
setStatus(showWindows
|
| 1032 |
+
? "Windows on β click one to select, drag it to slide along the wall, drag "
|
| 1033 |
+
+ "a yellow end dot to resize, press Delete to remove it."
|
| 1034 |
+
: "Windows hidden.");
|
| 1035 |
draw();
|
| 1036 |
});
|
| 1037 |
+
// Delete removes the selected door/window
|
| 1038 |
+
document.addEventListener("keydown", e => {
|
| 1039 |
+
if ((e.key==="Delete"||e.key==="Backspace") && selOpening>=0) {
|
| 1040 |
+
const o=openings[selOpening];
|
| 1041 |
+
openings.splice(selOpening,1); selOpening=-1;
|
| 1042 |
+
setInfo(`${o.kind==="door"?"Door":"Window"} removed.`);
|
| 1043 |
+
e.preventDefault(); draw();
|
| 1044 |
+
}
|
| 1045 |
+
});
|
| 1046 |
document.getElementById("fill-balcony").addEventListener("click", ()=>fillGapWith("balcony"));
|
| 1047 |
document.getElementById("fill-study").addEventListener("click", ()=>fillGapWith("study"));
|
| 1048 |
document.getElementById("fill-passage").addEventListener("click", ()=>fillGapWith("passage"));
|
|
|
|
| 1173 |
// keep the staircase at the size the plan produced (10'Γ12' portrait for
|
| 1174 |
// N/S roads, 12'Γ10' landscape for E/W) β do NOT force a fixed size, that
|
| 1175 |
// used to grow a portrait staircase and push it out of the plot box
|
| 1176 |
+
openings = []; selOpening = -1; // re-seed doors/windows for the new plan
|
| 1177 |
origRooms = rooms.map(r=>({...r}));
|
| 1178 |
computeLockedConstraints();
|
| 1179 |
selIdx=-1; dirty=false;
|