- Joined
- Nov 17, 2007
- Messages
- 24
I have developed a system for RPG maps that generates color-coded text that can be read (from the screenshot) by a program, thus avoiding the need to write the code manually.
The JASS code, as well as the decoding program can be found here. This page contains more informations about the program and the script.
Anyways I post the JASS code here:
The JASS code, as well as the decoding program can be found here. This page contains more informations about the program and the script.
Anyways I post the JASS code here:
JASS:
function CharCode takes string char returns integer
local string charTable = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTIVWXYZ- "
local integer currentIndex = 1
local integer endIndex = 64
loop
exitwhen currentIndex > endIndex
if SubStringBJ(charTable, currentIndex, currentIndex) == char then
return currentIndex - 1
endif
set currentIndex = currentIndex + 1
endloop
// This is invalid
return -1
endfunction
function EncodeChar takes integer charCode returns string
local integer base = 3
local string array colors
local string result
set colors[0] = "|c00ff0000I" // Red
set colors[1] = "|c0000ff00I" // Green
set colors[2] = "|c000000ffI" // Blue
set result = colors[charCode - (charCode / base * base)]
set charCode = charCode / base
set result = colors[charCode - (charCode / base * base)] + result
set charCode = charCode / base
set result = colors[charCode - (charCode / base * base)] + result
set charCode = charCode / base
set result = colors[charCode] + result
return result
endfunction
function EncodeString takes string text returns string
local string result = ""
local integer currentChar
local integer currentIndex
local integer endIndex
set currentIndex = 1
set endIndex = StringLength(text)
loop
exitwhen currentIndex > endIndex
set currentChar = CharCode(SubStringBJ(text, currentIndex, currentIndex))
set result = result + EncodeChar(currentChar)
set currentIndex = currentIndex + 1
endloop
return result
endfunction