TheGiddyLimit / plutonium-scenes

Scene data for Plutonium.
5 stars 2 forks source link

Walls - HWAitW #142

Closed revilowaldow closed 2 months ago

revilowaldow commented 2 months ago

Add walls for maps in HWAitW

Should be 11, maps need setting up + grid data in advance

revilowaldow commented 2 months ago

Image

revilowaldow commented 2 months ago
revilowaldow commented 2 months ago

This one's def in need of dedicated player walls. All sorts of funky stuff going on like significant crops, 90° rotations etc.

revilowaldow commented 2 months ago

Rotate walls 90°, taken from Foundry discord https://discord.com/channels/170995199584108546/699750150674972743/1153310497765081180

let centerPoint = canvas.walls.controlled.reduce((acc, wall) => {
    let wallX = wall.document.c[0];
    let wallY = wall.document.c[1];
    acc.x += wallX;
    acc.y += wallY;
    return acc;
},{x: 0, y:0})
centerPoint.x = centerPoint.x / canvas.walls.controlled.length;
centerPoint.y = centerPoint.y / canvas.walls.controlled.length;
const walls = canvas.walls.controlled.map(wall => {
  let w = duplicate(wall.document);
  const mid_offset_0 = w.c[0] - centerPoint.x;
  const mid_offset_1 = w.c[1] - centerPoint.y;
  const mid_offset_2 = w.c[2] - centerPoint.x;
  const mid_offset_3 = w.c[3] - centerPoint.y;
  w.c[0] = centerPoint.x - mid_offset_1;
  w.c[1] = centerPoint.y + mid_offset_0;
  w.c[2] = centerPoint.x - mid_offset_3;
  w.c[3] = centerPoint.y + mid_offset_2;
  return {_id: w._id, c: w.c};
});
canvas.scene.updateEmbeddedDocuments("Wall", walls);
TheGiddyLimit commented 2 months ago

interesting that they use the first point of the wall to calculate the center, rather than e.g. the midpoint of the wall

wonder if it works any better if you swap that first statement out for:

let centerPoint = canvas.walls.controlled.reduce((acc, wall) => {
    const [x0, y0, x1, y1] = wall.document.c;
    let wallX = x0 + ((x1 - x0) / 2);
    let wallY = y0  + ((y1 - y0) / 2);
    acc.x += wallX;
    acc.y += wallY;
    return acc;
},{x: 0, y:0})

not that I imagine it matters for this use-case