Tukki
is Skeleton Pirate.
- Reaction score
- 29
Current Version: 1.0
A simple and easy-to-use script with the purpose of colorizing a given string. It colorizes upper-case, lower-case and numbers/symbols differently.
There're even two functions for peope who hate public prefixes!
JASS:
//===========================================================================
// COLORIZE [1.0]
//===========================================================================
//
// QUICK INFO:
//
// Importing : Paste this text into an empty, custom-text trigger
// Author : Tukki (credits are not required)
// Requirements: JASS/vJASS knowledge ?
//
// FUNCTIONS:
//
// call Colorize_Text(<sometext>) --> colorized version
// call ColorText(<sometext>) --> colorized version
//
// EXAMPLES:
//
// local string text = Colorize_Text("AJF88-KG783-59DE")
// call DisplayTextToPlayer(Player(0), 0, 0, "Your Code: "+text)
//
// call DisplayTextToPlayer(Player(0), 0, 0, ColorText("TH1S 1S SP4RT4!"))
//
// set text = null
//
// NOTES:
//
// * There're two functions which do exactly the same thing, the difference
// is that one requires the Colorize_ prefix and the other doesn't.
// (Some people hate the public prefix, so for comfortability's sake it's there)
//
// * This function makes no difference between symbols (like &%@£$) and numbers
//
// * If you are using this to colorize a save/load-code and don't want it to
// colorize the spacing characters (often "-") check the function IsCharAllowed
// further down.
//===========================================================================
library Colorize
//===========================================================================
// CALIBRATION SECTION
globals
private constant string UPPER = "|CFFAA0000" // Color of upper-case chars
private constant string LOWER = "|CFF00AA00" // Color of lower-case chars
private constant string SYMBOL = "|CFF0000AA" // Color of symbols/numbers
// Options if you want to add a legend to the returned string:
// * Leave it as it is for normal legend
// * Make it LEGEND = "" if you wish to disable it
private constant string LEGEND = "\n\nLegend: "+UPPER+"Upper Case / "+LOWER+"Lower Case / "+SYMBOL+"Symbol/Number|r"
endglobals
// END OF CALIBRATION
//===========================================================================
//===========================================================================
// CHARACTER CHECK - Checks if a character is allowed
//
// * Example of having 2 not-allowed characters:
//
// return char!="-" and char!="@"
//
// This will make the colorize function ignore - and @ characters
// and add them as white-colored.
//===========================================================================
private function IsCharAllowed takes string char returns boolean
return true
endfunction
//===========================================================================
// MAIN ENGINE - Colorizes a given string
//===========================================================================
private function ColorizeEngine takes string base returns string
local integer length = StringLength(base)
local integer i = 0
local string part = ""
local string new = ""
local boolean case
local boolean symbol
loop
exitwhen i>=length
set part = SubString(base, i, i+ 1 )
set case = (StringCase(part, true)==part and StringCase(part, false)!=part)
set symbol = (StringCase(part, true)==part and StringCase(part, false)==part)
if (part!="" and IsCharAllowed(part)) then
if (case and not symbol) then
set new = new + UPPER + part + "|r"
elseif (not case and not symbol) then
set new = new + LOWER + part + "|r"
elseif (not case and symbol) then
set new = new + SYMBOL + part + "|r"
endif
elseif (not IsCharAllowed(part) and part!="") then
set new = new + part
endif
set i = i + 1
endloop
if (LEGEND!="" and LEGEND!=null) then
set new = new + LEGEND
endif
return new
endfunction
//===========================================================================
// FUNCTIONS - Functions YOU can use (one public and one normal)
//===========================================================================
public function Text takes string text returns string
return ColorizeEngine(text)
endfunction
//===========================================================================
function ColorText takes string text returns string
return ColorizeEngine(text)
endfunction
endlibrary
A simple and easy-to-use script with the purpose of colorizing a given string. It colorizes upper-case, lower-case and numbers/symbols differently.
There're even two functions for peope who hate public prefixes!
JASS:
local string text = Colorize_Text("AJF88-KG783-59DE")
call DisplayTextToPlayer(Player(0), 0, 0, "Your Code: "+text)
call DisplayTextToPlayer(Player(0), 0, 0, ColorText("TH1S 1S SP4RT4!"))
set text = null