#!/usr/bin/perl # activestate perl for windows ############################################################### ## Author: Dan Barrett a.k.a. FSK405 wily duck (wilyduck2011 @digitalamusement com) ## Date: 6/8/2011 ## Program: versioneer.pl ## Purpose: Automatically progress a map version. ## ## Notes: 1. This script belongs in q3ut4/maps. ## 2. Mod the first two sections below as needed. ## 3. It does NOT search for shader dependencies, nor reference external shaders - ## meaning that this script works great for stand-alone maps, but will give ## unexpected results otherwise. You've been warned. ## 4. Only copies files, except for ©same which rewrites a file. ## 5. Isn't reversable, but also isn't destructive to existing data (see above note). ## 6. Can be re-run immediately if say a folder didn't copy correctly and you fixed ## that folder. ## ## Version: v1.2 - 06142011.0 - Added safety check to verify if new map already exists. Copying ## the .map file is now the last action. ## v1.1 - 06112011.0 - Restructured the configuration sections. Lots more commenting. ## Added second arg to ©dir. No longer need to double backslash ## folder names. ## v1.0 - 06082011.1 - Works just fine. Should have made this years ago. ## v0.0 - 06082011.0 - Starting new script from newscript template 03262010.2 ## ## Bugs: #0 - 06082011.0 - None. ## ## To-do: 1. None. Considering adding a packager routine. ## ## Usage: versioneer.pl [[old mapname] [new mapname]] ############################################################### ### Section 1 ### ################################ ### Map names specified here ### ################################ $map1 = "ut4_temple2_alpha4"; $map2 = "ut4_temple2_beta"; ################################ &startup(); ### Section 2 ### ############################################## ### Non-default actions specified by user #### ############################################## ©map("../scripts/","-plant.shader"); ©same("../scripts/shaderlist.txt","-plant.shader"); ©dir("../textures/","/tf1"); # Available actions: # copymap ([dir],[file_suffix]) - subs the map name text within a file to new mapname file [for .map, .shader primarily] # copyone ([dir],[file_suffix]) - copies old mapname file to new mapname file [minimap, levelshot] # copydir ([dir],[leaf]) - copies old mapname folder in a dir to new mapname in that folder, then any leaf folders under that dir # copysame ([file]) - subs map name text within a file and rewrites that file # ..where [file_suffix] is any text after the mapname, i.e. ut4_yourmap[.txt] to take action on ut4_yourmap.txt # ..where [dir] is a dir that can either be blank to specify the default maps/ dir, or specified like ../scripts/ # ..where [file] is the dir and file name, i.e. ../scripts/shaderlist.txt # ..where [leaf] is a folder path suffix of a mapname dir, i.e. for textures/yourmap/editor you specify ("../textures/","/editor") ############################################## #### End of standard script configuration #### ############################################## # That means go away or prepare to wield your sword of +3 Perling! ########################### ### Normal file actions ### ########################### ©map("../scripts/",".shader"); ©same("../scripts/shaderlist.txt"); ©one("../levelshots/",".tga"); # copies old mapname file to new mapname file [minimap, levelshot] ©dir("../sound/"); # copies old mapname dir to new mapname dir ©dir("../textures/"); ©one("",".tga"); ©map("",".map"); ## Note: no change for env/ or models/ (unless needed, specify in non-default action section above) print "\nComplete. Press any key to continue.\n"; `pause`; ################################################ #### SUBS - no modifications required below #### ################################################ sub startup { ## Override defaults above if map names are specified in CLI args if ($ARGV[0]) { ($map1,$map2) = @ARGV; } die "check your map name and try again.\n" if ! -e "$map1.map"; # Sanity check die "New .map file already exists! Aborting as a precaution.\n" if -e "$map2.map"; # Safety check } sub copydir { my ($dir,$leaf) = @_; print "copydir $dir$map2$leaf\n"; $dir =~ s/\//\\\\/g; $leaf =~ s/\//\\\\/g; `mkdir $dir$map2$leaf`; `copy $dir$map1$leaf\\* $dir$map2$leaf\\*`; } sub copyone { my ($pre,$suf) = (); ($pre,$suf) = @_; print "copyone $pre$map2$suf\n"; `copy $pre$map1$suf $pre$map2$suf`; } sub copymap { my ($file,$suf) = (); ($pre,$suf) = @_; print "copymap $pre$map2$suf\n"; open (NEW, ">$pre$map2$suf") || die $!; open (MAP, "$pre$map1$suf") || die $!; while ($line = ) { $line =~ s/$map1/$map2/g; print NEW $line; } close MAP; close NEW; } sub copysame { my ($file,$suf) = (); ($file,$suf) = @_; print "copysame $file $suf\n"; open (NEW, ">$file.tmp") || die $!; open (MAP, "$file") || die $!; while ($line = ) { $line =~ s/$map1$suf/$map2$suf/g; print NEW $line; } close MAP; close NEW; `move $file.tmp $file`; }