<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Compass"
   author="Trevize"
   id="043e0976013412f26cf9a395"
   language="Lua"
   purpose="Nexus compass"
   date_written="2008-08-20"
   requires="4.35"
   version="1.05"
   >
</plugin>

<script><![CDATA[

loadstring(GetPluginVariable("7c08e2961c5e20e5bdbf7fc5", "Utilities"))()

Z = {
  tpairs = function (tbl)
    local i = 0
    return function ()
      i = i + 1
      if tbl[i] ~= nil then return tbl[i] end
    end -- func
  end, -- func

  ansicolor = function (fore, back)
    local bold = false
    local fore = tonumber (fore) or 7
    if fore >= 0 and fore <= 7 then
      fore = fore + 30
    elseif fore >= 8 and fore <= 15 then
      fore = fore + 22
      bold = true
    else
      fore = 37
    end -- if
    local back = tonumber (back) or 0
    if back > 0 and back <= 7 then
      back = back + 40
    else
      back = 40
    end -- if
    if not bold then
      return ANSI (0, fore, back)
    else
      return ANSI (0, fore, 1, back)
    end -- if
  end, -- func
  }

tpairs = Z.tpairs
ansicolor = Z.ansicolor



if string.sub (GetInfo (60), 1, 1) == "." then
  plugindir = GetInfo (66) .. string.sub (GetInfo (60), 3)
else
  plugindir = GetInfo (60)
end -- if



OnPluginBroadcast = function (msg, id, name, text)
  if (id == idATCP) then
    if (msg == 0) then
      EnableModuleATCP("room_exits")
    else
      msg, text = UnpackATCP(text)

      if (msg == "Room.Exits" and text ~= "") then
        compass.active = utils.split (text, ",")
        compass.draw ()
      end -- if
    end -- if
  end -- if
end -- func



mousedown = function (a, dir)
  local t = {i = "in", o = "out"}
  local com = t[dir] or dir
  Send (com)
end -- func



compass = {
  name = GetWorldID () .. "2",

  directions = {
    n  = true,
    ne = true,
    e  = true,
    se = true,
    s  = true,
    sw = true,
    w  = true,
    nw = true,
    u  = true,
    d  = true,
    i  = true,
    o  = true,
    },


  location = {
    n  = {57, 25},
    ne = {73, 37},
    e  = {80, 57},
    se = {73, 72},
    s  = {57, 80},
    sw = {38, 72},
    w  = {27, 57},
    nw = {38, 38},
    u  = {115, 31},
    d  = {115, 79},
    i  = {81, 116},
    o  = {33, 114},
    },

  dimension = {},

  active = {},

  create = function ()
    for dir in tpairs (compass.active) do
      if compass.directions[dir] then
        local left = compass.location[dir][1]
        local top = compass.location[dir][2]
        local right = compass.location[dir][1] + compass.dimension[dir][1]
        local bottom = compass.location[dir][2] + compass.dimension[dir][2]
        WindowDrawImage (compass.name, dir,
                         left, top, right, bottom, 1)
        WindowAddHotspot (compass.name, dir,
                          left, top, right, bottom,
                          "", "", "mousedown", "", "", "", 0, 0)
      end -- if
    end -- for
  end, -- func

  draw = function ()
    WindowDrawImage (compass.name, "compass", 0, 0, 0, 0, 1)
    WindowDeleteAllHotspots (compass.name)
    compass.create ()
  end, -- func

  err = function (x)
    AnsiNote (ansicolor(), "Compass disabled, image not found. Compass images should be in:")
    AnsiNote (ansicolor(), plugindir .. "compass")
    EnablePlugin (GetPluginID (), false)
    WindowDelete (compass.name)
  end, -- func
  }

WindowCreate (compass.name, 0, 0, 150, 150, 6, 0, ColourNameToRGB ("black"))
x = WindowLoadImage (compass.name, "compass", plugindir .. [[compass\compass.bmp]])
for dir in pairs (compass.directions) do
  y = WindowLoadImage (compass.name, dir, plugindir .. [[compass/arrow_]] .. dir .. ".bmp")
  compass.dimension[dir] = {}
  compass.dimension[dir][1] = WindowImageInfo(compass.name, dir, 2)
  compass.dimension[dir][2] = WindowImageInfo(compass.name, dir, 3)
end -- for
compass.draw ()
WindowShow (compass.name, true)
if (x ~= 0) or (y ~= 0) then compass.err (x or y) else x, y = nil, nil end

]]></script> 

</muclient>