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 Create Line Portal ` ;
` #description Creates a quick portal (line action 301) between the selected lines. Only works in UDMF. Only works when exactly two lines are selected. Both lines must have exactly the same length. Draws a sector at the back of the selected lines. ` ;
` #scriptoptions
depth
{
description = "Depth of space behind portal" ;
default = 64 ;
type = 0 ; // Integer
}
texture
{
description = "Filler texture" ;
default = "FIREBLU1" ;
type = 6 ; // Texture
}
` ;
// Function to draw the space behind the portal line
function drawPortalSector ( line , depth )
{
// The origin is the bottom left point of the rectanble
let origin = line . v1 ;
// The base points of the rectangle. There are five because
// the first and last point need to be at the same position
// to get a complete drawing
let points = [
2022-01-06 17:46:37 +00:00
new UDB . Vector2D ( 0 , 0 ) ,
new UDB . Vector2D ( 0 , depth ) ,
new UDB . Vector2D ( line . getLength ( ) , depth ) ,
new UDB . Vector2D ( line . getLength ( ) , 0 ) ,
new UDB . Vector2D ( 0 , 0 )
2021-11-28 13:00:24 +00:00
] ;
// The points need to be rotated by the line's angle and moved
// by the origin's position
for ( let i = 0 ; i < points . length ; i ++ )
{
let v = points [ i ] . getRotated ( line . getAngle ( ) - 90 ) ;
points [ i ] = origin + v ;
}
// Draw the lines
2022-01-06 17:46:37 +00:00
if ( ! UDB . Map . drawLines ( points ) )
2021-11-28 13:00:24 +00:00
throw 'Failed drawing space behind line ' + line ;
// Set the front middle texture for the new 1-sided linedefs
2022-01-06 17:46:37 +00:00
UDB . Map . getMarkedLinedefs ( ) . filter ( ld => ld . back == null ) . forEach ( ld => ld . front . middleTexture = UDB . ScriptOptions . texture )
2021-11-28 13:00:24 +00:00
}
// The line action for portals only works in UDMF (GZDoom and Eternity Engine)
2022-01-06 17:46:37 +00:00
if ( ! UDB . Map . isUDMF )
2021-11-28 13:00:24 +00:00
throw 'This script only works in UDMF maps' ;
// Get selected linedefs
2022-01-06 17:46:37 +00:00
let lines = UDB . Map . getSelectedLinedefs ( ) ;
2021-11-28 13:00:24 +00:00
// Make sure exactly two lines are selected
if ( lines . length != 2 )
throw 'You need to select exactly two lines' ;
// Both lines have to have the same length, otherwise the portal will
// be broken
if ( lines [ 0 ] . line . getLength ( ) != lines [ 1 ] . line . getLength ( ) )
throw 'Both lines need to have the same length' ;
// Get a new tag to use for the portal
2022-01-06 17:46:37 +00:00
let newtag = UDB . Map . getNewTag ( ) ;
2021-11-28 13:00:24 +00:00
// Set the action, arg, and tag of both lines
lines [ 0 ] . action = lines [ 1 ] . action = 301 ; // Line_QuickPortal
lines [ 0 ] . args [ 0 ] = lines [ 1 ] . args [ 0 ] = 0 ;
lines [ 0 ] . tag = lines [ 1 ] . tag = newtag ;
// Draw the sectors behind the portal
2022-01-06 17:46:37 +00:00
drawPortalSector ( lines [ 0 ] . line , UDB . ScriptOptions . depth ) ;
drawPortalSector ( lines [ 1 ] . line , UDB . ScriptOptions . depth ) ;