2022-11-13 00:15:17 +00:00
|
|
|
/// <reference path="../../udbscript.d.ts" />
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
`#version 4`;
|
|
|
|
|
2021-11-28 13:00:24 +00:00
|
|
|
`#name Flip Triangular Sectors`;
|
|
|
|
|
|
|
|
`#description Flips two selected triangular sectors, so that the connecting linedef is between the vertices that previously didn't share a linedef`;
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
let sectors = UDB.Map.getSelectedSectors();
|
2021-11-28 13:00:24 +00:00
|
|
|
let vertices = new Set();
|
|
|
|
let sharedline = null;
|
|
|
|
|
|
|
|
if(sectors.length != 2)
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.die('You have to select exactly 2 sectors');
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
// Make sure we have triangular sectors selected, and collect all vertices
|
|
|
|
sectors.forEach(s => {
|
|
|
|
let sidedefs = s.getSidedefs();
|
|
|
|
|
|
|
|
if(sidedefs.length != 3)
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.die(s + ' does not have exactly 3 sides');
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
sidedefs.forEach(sd => {
|
|
|
|
// Does this sidedef belong to the linedef that's shared between the sectors?
|
|
|
|
if(sd.other != null && sectors.includes(sd.sector) && sectors.includes(sd.other.sector))
|
|
|
|
sharedline = sd.line;
|
|
|
|
|
|
|
|
// Add the vertices to the set
|
|
|
|
vertices.add(sd.line.start)
|
|
|
|
vertices.add(sd.line.end)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete the vertices of the shared line from the set
|
|
|
|
vertices.delete(sharedline.start);
|
|
|
|
vertices.delete(sharedline.end);
|
|
|
|
|
|
|
|
// There should be exactly 2 vertices
|
|
|
|
if(vertices.size != 2)
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.die('Expected to find 2 vertices to draw the new line between, but got ' + vertices.size);
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
// Merge the sectors...
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.Map.mergeSectors(sectors);
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
// ... and draw the new line
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.Map.drawLines(Array.from(vertices, v => v.position));
|