This program takes a LORD Score Bulletin file that has unconverted LORD color codes (for example `1 for Dark Blue) and converts them to ANSI color codes.
/*LORD-Color-Fix.js -by- KenDB3 of KD3net (http://bbs.kd3.us) | |
This script is meant for use with Synchronet BBSes. | |
It requires JSexec.exe (from SBBS) to be run from command line. | |
Usage: | |
Do your LORD Score Bulletins look funky because people use multiple color | |
codes in their name? Do the extra LORD color codes throw off the alignment | |
of the bulletin? This program takes a LORD Score Bulletin file that has | |
unconverted LORD color codes (for example `1 for Dark Blue) and then | |
converts them to their equivalent ANSI color codes (Ex: ESC[0;34m). | |
Add the LORD-Color-Fix.js script to your mods (/sbbs/mods/) or your | |
exec (/sbbs/exec/) directory. | |
Command Line: | |
(be sure you're in the correct directory to call jsexec.exe, ie /sbbs/exec/) | |
jsexec.exe LORD-Color-Fix.js InputFile OutputFile | |
---All arguments are required--- | |
---InputFile cannot match OutputFile--- | |
Note: You probably need this for the original Legend of the Red Dragon, | |
but not for Legend of the Red Dragon II: New World. | |
LORD 2 makes the scores bulletin correctly. | |
Version 1.0 2017-03-21 Initial Release | |
*/ | |
//Make sure we have enough arguments to handle the conversion | |
if(argc < 2) { | |
alert(format("!!!Missing Argument!!! \r\n" + | |
"Format should look like this: \r\n" + | |
"jsexec.exe LORD-Color-Fix.js InputFile OutputFile \r\n\r\n" + | |
"InputFile = LORD Scores Bulletin in ANSI format that needs to be cleaned up.\r\n" + | |
"OutputFile = LORD Scores Bulletin you want saved after it has been cleaned up.\r\n" | |
, errno, LORDscoresInput)); | |
exit(); | |
} | |
var LORDscoresInput = argv[0]; | |
var LORDscoresOutput = argv[1]; | |
if(LORDscoresInput.toLowerCase() == LORDscoresOutput.toLowerCase()) { | |
alert(format("!!!InputeFile Cannot Match OutputFile!!! \r\n" + | |
"Format should look like this: \r\n" + | |
"jsexec.exe LORD-Color-Fix.js InputFile OutputFile \r\n\r\n" + | |
"InputFile = LORD Scores Bulletin in ANSI format that needs to be cleaned up.\r\n" + | |
"OutputFile = LORD Scores Bulletin you want saved after it has been cleaned up.\r\n" + | |
"Sorry, but unfortunately these files cannot be the same.\r\n" + | |
"I suggest making this part of a script that later deletes the original file.\r\n" | |
, errno, LORDscoresInput)); | |
exit(); | |
} | |
//Our input file | |
var file = new File(LORDscoresInput); | |
//Does the file open? Or are you messing with me? | |
if(!file.open("r")) { | |
alert(format("Error %d opening %s\n", errno, LORDscoresInput)); | |
exit(); | |
} | |
var LORDscoresFix = file.readAll(4096); | |
var line_num; | |
var line_num_out; | |
//RegEx to find and replace the text | |
for(line_num in LORDscoresFix) { | |
//Dark Blue | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`1/g, '\033' + '[0;34m'); | |
//Dark Green | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`2/g, '\033' + '[0;32m'); | |
//Dark Cyan | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`3/g, '\033' + '[0;36m'); | |
//Dark Red | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`4/g, '\033' + '[0;31m'); | |
//Dark Purple (Dark Magenta) | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`5/g, '\033' + '[0;35m'); | |
//Puke (Dark Yellow) | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`6/g, '\033' + '[0;33m'); | |
//Gray | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`7/g, '\033' + '[0m'); | |
//Dark Gray | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`8/g, '\033' + '[0;1;30m'); | |
//Bright Blue | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`9/g, '\033' + '[0;1;34m'); | |
//Bright Green | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`0/g, '\033' + '[0;1;32m'); | |
//Bright Cyan | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`!/g, '\033' + '[0;1;36m'); | |
//Bright Red | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`@/g, '\033' + '[0;1;31m'); | |
//Purpink (Magenta) | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`#/g, '\033' + '[0;1;35m'); | |
//Yellow | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`\$/g, '\033' + '[0;1;33m'); | |
//White | |
LORDscoresFix[line_num] = LORDscoresFix[line_num].replace(/`%/g, '\033' + '[0;1m'); | |
} | |
var file = new File(LORDscoresOutput); | |
//Does the new file open? | |
if(!file.open("w")) { | |
alert(format("Error %d opening %s\n", errno, LORDscoresOutput)); | |
exit(); | |
} | |
for(line_num_out in LORDscoresFix) { | |
var lineout = LORDscoresFix[line_num_out]; | |
file.writeln(lineout); | |
} | |
file.close(); | |
print(LORDscoresInput + " successfully converted to " + LORDscoresOutput); | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment