The mud I play has the ability to send out it's ASCII maps via GMCP, though no public plugins utilise this feature at all yet. The ASCII maps for each room come in different formats - the player can select raw "plaintext" (no colour codes, no mxp)... they can select colours and inverse colours... and they can have MXP enabled to make some of the rooms clickable. So maps may be plain... coloured by just ANSI... or a mix of ANSI and MXP colour and link codes. Mushclient handles them just fine, of course... but I have no idea how to handle it myself in LUA. (the end goal is to have it output to a floating window with windowtexts).
Here's one, single example room as it is received over GMCP, if you have colours + mxp enabled for your map option:
-- This is actually all received as a SINGLE line
-- I have inserted line-breaks so this forum post doesn't stretch out - the \n literal strings are received as text over GMCP, I have hit return after each!
sLastFullAscii = [[--
\u001b[3z\u001b[4zMXP<RedMXP>+\u001b[3z \n
\u001b[3z\u001b[4zMXP<YellowMXP>\u001b[4zMXP<send href=\"goto 3c\"MXP>@\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 4c\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 5c\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z \n
\u001b[3z|\u001b[3z \u001b[3z|\u001b[3z \n
\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 3d\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z \n
\u001b[3z|\u001b[3z \n
\u001b[3z\u001b[4zMXP<CyanMXP>\u001b[4zMXP<send href=\"goto 3e\"MXP>*\u001b[4zMXP<\/sendMXP>\u001b[3z-\u001b[3z \n]]
(NOTE: this is all *ONE* single line received, one single GMCP text packet, with the literal strings of "\n", and the intentional space padding at the start of each "line" etc.)
The map when NOT sent over GMCP, and instead handled and output by Mushclient, actually looks like this:
http://i.imgur.com/RRGyxcB.png
I've tried playing with "ANSINote", "StripANSI" and such but it seems these ANSI codes aren't normal, or the mix of MXP and newlines just makes it impossible. And I couldn't spot anything for handling MXP codes when receives in this raw format.
I've had a good go at making something primitive to strip down those codes (keep in mind I have never encountered ANSI codes before so I really have no idea what they are doing, what they mean etc., I've just taken wild stabs in the dark). Here's the code I came up with just to ATTEMPT to attack that garble of GMCP received text;
-- Delete this part of the ANSI codes, not needed?
sLastFullAscii = string.gsub(sLastFullAscii, "\u001b", "")
-- This code seems to mean "white", or "silver"?
sLastFullAscii = string.gsub(sLastFullAscii, "%[3z", "<silver>")
-- This code seems to mean "reset", which means let Mushclient use the default Note colour - turn it into a blank tag for now
sLastFullAscii = string.gsub(sLastFullAscii, "%[4z", "<>")
-- Delete the clickable links, not wanted
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<send href=\"goto %d%l\"MXP>', "")
-- And delete the closing tag for the links
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<\/sendMXP>', "")
-- Convert all the MXP-based colour tags to a simpler tag system just for ease of understanding
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<RedMXP>', "<red>")
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<GreenMXP>', "<green>")
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<CyanMXP>', "<cyan>")
sLastFullAscii = string.gsub(sLastFullAscii, 'MXP<YellowMXP>', "<yellow>")
-- Convert backslash-n to a pound symbol for now...
sLastFullAscii = string.gsub(sLastFullAscii, '\n', "£")
-- Split by the pound symbol and loop through each line
for sNewLine in sLastFullAscii:gmatch("([^£]+)") do
-- CREATE a new tag at the very beginning to make the gmatch work and handle the whitespace padding at the beginning of lines
sNewLine = "<white>" .. sNewLine
-- Gmatch through all my manually inserted colour codes and output the text associated with them
for sColourCode, sNewString in sNewLine:gmatch("<([^>]*)>([^<]+)") do
ColourTell(sColourCode, "", tostring(sNewString))
end
-- Blank note for a newline
Note("")
end
(I've done weird things I know, I was playing around).
Now, while that code DOES manage to strip out the MXP (I don't want/need them), and does actually output an identical looking map, with matching colours, into the Mushclient window... it's horribly clunky, and doesn't cover other possible unexpected colours, and doesn't handle if a user might have MXP disable so it's only ANSI codes (in which case I'll need to work out all the ANSI colours instead of using the MXP colours as I am above).... etc. etc.
I just wanted to show that I *HAD* made an attempt at breaking these codes down and turning it into something it's meant to look like (and this doesn't even dive into the fact I'm going to need to turn this into "WindowText" commands to put this into a miniwindow, rather than have nice easy to use ColourTell commands!)
What I'd love is a way to convert that huge mess received by GMCP, which may or may not contain just text... just ANSI... or ANSI and MXP... into a "Styles" table. A way to quickly strip all of those codes out, or to give the received GMCP data back to Mushclient and say "Please convert all these codes for me" as if it was being sent by the MUD itself. Or just some help! |