I have been able to Capture an ascii map from the mud I play and add it to your mudlet map file. (This will be included in the mapping script I have posted.... whenever I update It.)
This is what the ascii map looks like for the "The Two Towers".( minus the "map reset" and "*" echos)
- mud output
I use two triggers:
The first/last triggers on the top and bottom of the output.
per regex: ^\+\-\-\-\-(.+)\-\-\-\-\-\-\-\-\-\-\-\-\-\+$
With the following code it resets the global table/variables used or sends them to a script to add to your map.
local t = matches[1]
if string.find (t, "\-") then
if li then
echo("map reset")
AMhieght = li
li=nil--mudMAP = t
transMudMap(HX,HY,Gid)
else
mudMAP={}
end
end
The other trigger captures the room char, color info, your position on the map, and the size of the map.
perl regex: ^\|(.*)\|$
Using this code.
echo("*")
if li == nil then
li=1
else
li=li+1
end
resetFormat()
deselect()
for i=2,string.len(line)-1 do
local cl =i-1
mudMAP[cl] = mudMAP[cl] or {}
mudMAP[cl][li] = mudMAP[cl][li] or {}
selectSection(i-1,1)
local r,g,b = getFgColor()
local rb,gb,bb = getBgColor()
mudMAP[cl][li]["r"] = r
mudMAP[cl][li]["g"] = g
mudMAP[cl][li]["b"] = b
mudMAP[cl][li]["Room"] = string.sub(line,i,i)
deselect() -- this is important to prevent color bleeding as setBgColor() affects the current selection if there is one
if rb ~= 0 then
HX = cl
HY = li
end
resetFormat()
end
AMlength = string.len(matches [2])
The real magic of this is that it can be added to your map with the following function.
function transMudMap(MmX,MmY,roomid)
local Caa= getRoomArea(roomid)
local Cxx,Cyy,Czz = getRoomCoordinates( roomid )
local xx,yy,tt,r,g,b,zz,LocX,LocY,CurLo,roomcolor,Rid,SD
yy=1
while yy <= AMhieght do
LocY = (AMhieght-yy+2) + Cyy-MmY
xx=1
while xx <= AMlength do
LocX = xx+ Cxx-MmX
r = mudMAP[xx][yy]["r"] or 0
g =mudMAP[xx][yy]["g"] or 0
b = mudMAP[xx][yy]["b"] or 0
tt = mudMAP[xx][yy]["Room"]
if tt ~= "X" then
roomcolor = FindColorCK(r,g,b)
CurLo = getRoomsByPosition(Caa, LocX,LocY,Czz)
if CurLo[0]then
Rid = CurLo[0]
--update
else
--record
Rid = createRoomID()
addRoom(Rid)
setRoomArea(Rid, Caa)
setRoomCoordinates(Rid, LocX,LocY,Czz)
end
setRoomEnv( Rid, roomcolor )
setRoomChar(Rid, tt)
end
xx=xx+1
end--while
xx=1
yy=yy+1
end--while
centerview(roomid)
end--func
This function calls anouther function I have written that finds the env variable based on the rgb values
roomcolor = FindColorCK(r,g,b)
Here is the code to make that work. (I feel this is the weakest part of this but have not rewritten it yet)
ColorLkp = ColorLkp or {}
Oresults = getCustomEnvColorTable()
local maxc=1000
local ct = 1
while ct<=maxc do
if Oresults[ct] then
--display(Oresults[ct])
local lkp = (Oresults[ct][1].."r"..Oresults[ct][3].."g"..Oresults[ct][3].."b")
ColorLkp[lkp]=ct
GcolorCount = ct
end
ct=ct+1
end
function NewColorID()
GcolorCount = GcolorCount + 1
--Oresults[1]["cid"] = GcolorCount
--db:update(savecolor.idcounts, Oresults[1])
return GcolorCount
end
function FindColorCK(RR,GG,BB)
local Cid,huh
local lkp = (RR.."r"..GG.."g"..BB.."b");
if ColorLkp[lkp]~=nil then
Cid = ColorLkp[lkp]
else
Cid = NewColorID()
ColorLkp[lkp]=Cid
setCustomEnvColor(Cid, RR, GG, BB,255);
end;--end--if
--echo("RGB>")
return Cid
end--function
(Just thought I would try to document this.)