initial release
This commit is contained in:
213
cosmic rage/worlds/plugins/ColourNote.xml
Normal file
213
cosmic rage/worlds/plugins/ColourNote.xml
Normal file
@@ -0,0 +1,213 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE muclient>
|
||||
<!-- Saved on Wednesday, October 23, 2002, 12:48 PM -->
|
||||
<!-- MuClient version 3.26 -->
|
||||
|
||||
<!-- Plugin "ColourNote" generated by Plugin Wizard -->
|
||||
|
||||
<!--
|
||||
You can edit the lookup_colour function to add more colour codes.
|
||||
-->
|
||||
|
||||
<muclient>
|
||||
<plugin
|
||||
name="ColourNote"
|
||||
author="Nick Gammon"
|
||||
id="8f86e2da6eea3806f1836050"
|
||||
language="JScript"
|
||||
purpose="Lets you send a string with colour codes to the world window"
|
||||
date_written="2002-10-23 12:46:12"
|
||||
requires="3.23"
|
||||
version="1.0"
|
||||
>
|
||||
<description trim="y">
|
||||
<![CDATA[
|
||||
This is designed to be called from a script like this:
|
||||
|
||||
world.CallPlugin "8f86e2da6eea3806f1836050", _
|
||||
"colournote", _
|
||||
"~R red ~G green ~B blue ~RG red-on-green"
|
||||
|
||||
To simplify things, make a "stub" routine in your main script file, like this:
|
||||
|
||||
// example in Jscript:
|
||||
function ColourNote (text)
|
||||
{
|
||||
world.CallPlugin ("8f86e2da6eea3806f1836050", "colournote", text);
|
||||
}
|
||||
|
||||
' example in VBscript:
|
||||
sub ColourNote (text)
|
||||
world.CallPlugin "8f86e2da6eea3806f1836050", "colournote", text
|
||||
end sub
|
||||
|
||||
Then you can just do colour text like this:
|
||||
|
||||
ColourNote ("~R This is red ~G This is green ~B This is blue");
|
||||
|
||||
|
||||
ColourNote:help - this help
|
||||
]]>
|
||||
</description>
|
||||
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- Script -->
|
||||
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
function lookup_colour (which)
|
||||
{
|
||||
var c;
|
||||
|
||||
// add more codes below if you want to process different letters
|
||||
// Reserved characters are: space, and: . # ^ ~
|
||||
|
||||
switch (which)
|
||||
{
|
||||
case "K": c = "gray"; break;
|
||||
case "k": c = "black"; break;
|
||||
|
||||
case "R": c = "red"; break;
|
||||
case "r": c = "maroon"; break;
|
||||
|
||||
case "G": c = "lime"; break;
|
||||
case "g": c = "green"; break;
|
||||
|
||||
case "Y": c = "yellow"; break;
|
||||
case "y": c = "olive"; break;
|
||||
|
||||
case "B": c = "blue"; break;
|
||||
case "b": c = "navy"; break;
|
||||
|
||||
case "M": c = "magenta"; break;
|
||||
case "m": c = "purple"; break;
|
||||
|
||||
case "C": c = "aqua"; break;
|
||||
case "c": c = "teal"; break;
|
||||
|
||||
case "W": c = "white"; break;
|
||||
case "w": c = "silver"; break;
|
||||
|
||||
default: c = ""; break; // unknown ones are no change
|
||||
} // end of switch on which colour code
|
||||
|
||||
return c;
|
||||
} // end of lookup_colour
|
||||
|
||||
/*
|
||||
This sends a coloured message to the world window.
|
||||
|
||||
Colour codes are like this: ~fb
|
||||
|
||||
~ = colour code delimiter
|
||||
f = foreground colour (eg. R = bright red, g = dull green)
|
||||
b = background colour (same meanings)
|
||||
|
||||
If the background colour is a space, then it is assumed to be
|
||||
unchanged. eg. ~R red ~G green ~B blue
|
||||
|
||||
Otherwise, it is processed as the background colour,
|
||||
eg. ~RB red-on-blue ~.G red-on-green ~yc dark-yellow on dark-cyan
|
||||
|
||||
Special colours:
|
||||
|
||||
. = no change (eg. to change background only)
|
||||
# = save colours (save current foreground/background colour)
|
||||
^ = restore colours (restore to saved colour)
|
||||
|
||||
eg.
|
||||
|
||||
colournote ("This will be a ~R red ~G green ~B blue.");
|
||||
|
||||
*/
|
||||
|
||||
function colournote (msg)
|
||||
{
|
||||
var msg_array, // split up line
|
||||
stext, // what we are sending
|
||||
fcolour, // foreground colour code
|
||||
bcolour, // background colour code
|
||||
foreground, // converted foreground colour
|
||||
background, // converted background colour
|
||||
save_foreground, // saved foreground colour
|
||||
save_background // saved background colour
|
||||
|
||||
// save colours for later restore
|
||||
|
||||
save_foreground = world.RGBColourToName (world.NoteColourFore ());
|
||||
save_background = world.RGBColourToName (world.NoteColourBack ());
|
||||
foreground = save_foreground;
|
||||
background = save_background;
|
||||
|
||||
// convert into an array
|
||||
|
||||
msg_array = msg.split ("~");
|
||||
|
||||
// first element in array (before tilde) is just shown as is
|
||||
|
||||
world.Tell (msg_array [0]);
|
||||
|
||||
for (i = 1; i < msg_array.length; i++)
|
||||
{
|
||||
fcolour = msg_array [i].substring (0, 1); // foreground colour
|
||||
bcolour = msg_array [i].substring (1, 2); // background colour
|
||||
stext = msg_array [i].substring (2); // rest is message
|
||||
|
||||
// get foreground colour, handle special cases, lookup others
|
||||
switch (fcolour)
|
||||
{
|
||||
case ".": break; // colour unchanged
|
||||
case "#": save_foreground = foreground; break;
|
||||
case "^": foreground = save_foreground; break;
|
||||
default: foreground = lookup_colour (fcolour); break;
|
||||
} // end of switch on fcolour
|
||||
|
||||
// get background colour, handle special cases, lookup others
|
||||
switch (bcolour)
|
||||
{
|
||||
case " ":
|
||||
case ".": break; // colour unchanged
|
||||
case "#": save_background = background; break;
|
||||
case "^": background = save_background; break;
|
||||
default: background = lookup_colour (bcolour); break;
|
||||
} // end of switch on fcolour
|
||||
|
||||
//
|
||||
// now display the text in the appropriate colour
|
||||
//
|
||||
world.ColourTell (foreground, background, stext);
|
||||
|
||||
} // end of loop on each colour change
|
||||
|
||||
world.Note (""); // finish off line
|
||||
|
||||
} // end of colournote
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
|
||||
<!-- Plugin help -->
|
||||
|
||||
<aliases>
|
||||
<alias
|
||||
script="OnHelp"
|
||||
match="ColourNote:help"
|
||||
enabled="y"
|
||||
>
|
||||
</alias>
|
||||
</aliases>
|
||||
|
||||
<script>
|
||||
<![CDATA[
|
||||
function OnHelp (sName, sLine, wildcards)
|
||||
{
|
||||
world.Note (world.GetPluginInfo (world.GetPluginID, 3));
|
||||
}
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</muclient>
|
||||
Reference in New Issue
Block a user