Jump to content

Need help with a Lua script or similar to batch copy textures in a map


Recommended Posts

Hello,

 

I'm helping a friend with mapping and saw they had at some point accidentally made the "outside" of their map a sector, namely all boundary linedefs were 2-sided.

 

Deleting the sector fixed that but now there are nearly thousand linedefs missing a middle texture. The old texture is still there as either upper or lower though for most if not all, as they probably had retextured a lot of them after the sector accident.

 

Could I write a script to copy upper or lower texture to middle texture for 1-sided linedefs with missing middle texture? That would make fixing the map so much easier.

I'm using Doom Builder X but if for example UDB has better tools for such I'm all in. Or if Slade etc would be better suited.

 

All help massively appreciated, I wanna help my friend make the map as they are naturally quite down now. Ofc can do it manually but hoping a script would be possible.

 

So to recap along the lines:

 

- IF linedef is 1-sided AND if linedef has upper OR lower texture AND no middle texture, copy upper/lower texture to middle texture (and optionally delete the upper/lower texture)

Share this post


Link to post

You could do this with UDB scripting.

Here is an UDB script that could work:
 

Spoiler

`#version 4`;

`#name Fill missing midtextures on 1-sided lines with lower or upper textures`;

`#description Fills missing midtextures on 1-sided lines which contain textures on lower or upper parts. If both are present, lower takes priority over upper texture.`;

// Get all selected lidedefs
let lines = UDB.Map.getSelectedLinedefs(true);

if(lines.length == 0)
UDB.die('You need to select at least one linedef.');

let fill_count = 0;
let progress_count = 0;

lines.forEach(l => {
    // If line has no back side (1-sided)
    if (l.back == null)
    {
        if (l.front != null)
        {
            // Get the front sidedef.
            let s = l.front;
            
	    // Middle texture must be missing
	    if (s.middleTexture == "-")
	    {
                // If lower texture exists, use it for middle
                if (s.lowerTexture !== "-")
    	        {
                    s.middleTexture = s.lowerTexture;
                    fill_count++;
		    UDB.log("Linedef " + l.index + " middle texture filled with lower texture '" + s.lowerTexture + "'.");
                }
                // Otherwise if upper texture exists, use it for middle
                else if (s.upperTexture !== "-")
                {
                    s.middleTexture = s.upperTexture;
                    fill_count++;
		    UDB.log("Linedef " + l.index + " middle texture filled with upper texture '" + s.upperTexture + "'.");
                }
            }
        }
    }
    progress_count++;
    UDB.setProgress( Math.round((progress_count/lines.length)*100) );
});

UDB.setProgress(100);
UDB.log('Middle textures filled: ' + fill_count);

 


The script needs to be saved in a text file with the '.js' (javascript) extension, for example "1sidedlinemidtexfill.js" and saved under the "UDBScript\Scripts" folder found inside the UltimateDoomBuilder folder. Then in UDB there is a bar on the right side of the editor that has a "Scripts" tab. From there you can select the script, and run it with the "Run" button at the bottom of that tab.

Note that for this script, you need to select the lines that it should apply to. If you want, you can just select all lines in the map. It will still only apply it to 1-sided linedefs that match the conditions.

 

Share this post


Link to post

Oh thanks a literal metric tonne! i'll give it a spin right away!

 

Been thinking of moving to UDB anyway since it seems to be most feature rich even if I intend to keep to vanilla / LR / Boom mapping myself

Share this post


Link to post
1 hour ago, Worst said:

You could do this with UDB scripting.

Here is an UDB script that could work:
 

  Reveal hidden contents


`#version 4`;

`#name Fill missing midtextures on 1-sided lines with lower or upper textures`;

`#description Fills missing midtextures on 1-sided lines which contain textures on lower or upper parts. If both are present, lower takes priority over upper texture.`;

// Get all selected lidedefs
let lines = UDB.Map.getSelectedLinedefs(true);

if(lines.length == 0)
UDB.die('You need to select at least one linedef.');

let fill_count = 0;
let progress_count = 0;

lines.forEach(l => {
    // If line has no back side (1-sided)
    if (l.back == null)
    {
        if (l.front != null)
        {
            // Get the front sidedef.
            let s = l.front;
            
	    // Middle texture must be missing
	    if (s.middleTexture == "-")
	    {
                // If lower texture exists, use it for middle
                if (s.lowerTexture !== "-")
    	        {
                    s.middleTexture = s.lowerTexture;
                    fill_count++;
		    UDB.log("Linedef " + l.index + " middle texture filled with lower texture '" + s.lowerTexture + "'.");
                }
                // Otherwise if upper texture exists, use it for middle
                else if (s.upperTexture !== "-")
                {
                    s.middleTexture = s.upperTexture;
                    fill_count++;
		    UDB.log("Linedef " + l.index + " middle texture filled with upper texture '" + s.upperTexture + "'.");
                }
            }
        }
    }
    progress_count++;
    UDB.setProgress( Math.round((progress_count/lines.length)*100) );
});

UDB.setProgress(100);
UDB.log('Middle textures filled: ' + fill_count);

 


The script needs to be saved in a text file with the '.js' (javascript) extension, for example "1sidedlinemidtexfill.js" and saved under the "UDBScript\Scripts" folder found inside the UltimateDoomBuilder folder. Then in UDB there is a bar on the right side of the editor that has a "Scripts" tab. From there you can select the script, and run it with the "Run" button at the bottom of that tab.

Note that for this script, you need to select the lines that it should apply to. If you want, you can just select all lines in the map. It will still only apply it to 1-sided linedefs that match the conditions.

 

 

It worked perfectly, thank you thank you thank you!

Share this post


Link to post

For what it's worth, the Eureka editor would not have left the middle textures as "-", but copied the lower texture to the middle when deleting the outer sector.

 

It surprises me that DoomBuilder just leaves things broken like that.....

Share this post


Link to post
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...