| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
| My preliminary attempt, which isn't perfect by any means, seems to show that, on my PC at least, which is fairly fast, I can't really see a flicker.
You are welcome to try it, the plugin is:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 30, 2007, 10:48 -->
<!-- MuClient version 4.13 -->
<muclient>
<plugin
name="Aardwolf_BigMap"
author="Nick Gammon"
id="1768db7d075059476f4879a0"
language="Lua"
purpose="Redirects Aardwolf bigmap messages to another world"
date_written="2008-06-29"
requires="4.28"
version="1.0"
>
<description trim="y">
Redirects the bigmap to the specified world.
</description>
</plugin>
<!-- Triggers -->
<triggers>
<trigger
enabled="y"
match="+------------------------------------------------------------+"
script="map_redirect"
omit_from_output="y"
name="map_start"
sequence="100"
>
</trigger>
<trigger
enabled="n"
match="*"
script="map_redirect"
name="multi_line_map"
omit_from_output="y"
sequence="10"
>
</trigger>
<trigger
enabled="y"
match="^You are in (.+?)\, coordinates\: (\d+?)\, (\d+?)$"
omit_from_output="y"
regexp="y"
script="updatelocation"
sequence="100"
>
</trigger>
<trigger
enabled="y"
match="[Exits: *]"
send_to="12"
sequence="100"
>
<send>
SendNoEcho ("coordinates")
</send>
</trigger>
</triggers>
<aliases>
<alias
match="blah"
enabled="y"
send_to="12"
sequence="100"
>
<send>DrawMap ()</send>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
map_world = "Aardwolf Big Map"
require "getworld"
map = {}
function InsertLocation (line, x)
t = {}
col = 1
for i, item in ipairs (line) do
-- to make it easier for me, I will expand out multiple-column runs
if item.length > 1 then
for j = item.length, 2, -1 do
table.insert (line, i + 1,
{ text = item.text:sub (j, j),
textcolour = item.textcolour,
backcolour = item.backcolour,
length = 1,
style = style } )
end -- adding new ones
item.length = 1
item.text = item.text:sub (1, 1)
end -- if multiple columns
-- at column, do *
if col == x then
table.insert (t, { text = "*", textcolour = 0x00FFFF, backcolour = 0x000000 } )
else
table.insert (t, item)
end -- if column
col = col + item.length
end -- for
return t
end -- InsertLocation
function DrawMap ()
w = get_a_world (map_world)
if not w then return end
w:DeleteOutput ()
for i, v in ipairs (map) do
if i == y then
send_to_world (map_world, InsertLocation (v, x))
else
send_to_world (map_world, v)
end
end -- for
end -- DrawMap
function updatelocation (name, line, wildcards)
continent = wildcards [1]
x = tonumber (wildcards [2]) + 2 -- allow for border, make 1-relative
y = tonumber (wildcards [3]) + 2 -- allow for border, make 1-relative
DrawMap ()
end -- updatelocation
-- map redirector
function map_redirect (name, line, wildcards, styles)
w = get_a_world (map_world)
if not w then return end
EnableTrigger ("multi_line_map", true) -- capture subsequent lines
if name == "map_start" then
map = {} -- start new map
table.insert (map, styles)
elseif line == "+------------------------------------------------------------+" then
EnableTrigger ("multi_line_map", false) -- no more lines to go
table.insert (map, styles)
DrawMap ()
else
table.insert (map, styles)
end -- if
end -- function map_redirect
function OnPluginInstall ()
-- ensure world file exists
make_world (map_world, [[
<!-- plugins -->
<include name="Send_Input_To_Main_World.xml" plugin="y" />
<include name="Copy_Output.xml" plugin="y" />
]])
local w = get_a_world (map_world)
if w then
w:Note "The map will appear here."
w:SetOption ("do_not_show_outstanding_lines", 1)
w:SetCommandWindowHeight (0) -- no command window
end -- no world
assert (GetOption ("enable_triggers") == 1, "Triggers not enabled")
end -- OnPluginInstall
]]>
</script>
</muclient>
It calls an improved getworld.lua file, see below. This goes in the lua subdirectory under MUSHclient, and you need to trust the plugin, because it opens a world file.
-- table of worlds we couldn't open
cannot_open_world = cannot_open_world or {} -- set flag here if can't open world
-- getworld.lua
--
--[[
See forum thread: http://www.gammon.com.au/forum/?id=7991
This simplifies sending triggered lines to another, dummy, world.
get_a_world (name) - returns a world pointer to the named world, opening it if necessary
send_to_world (name, styles) - sends the style runs to the named world, calling get_a_world
to get it
--]]
-- make the named world, if necessary - adds "extra" lines to the world file (eg. plugins)
function make_world (name, extra)
local filename = GetInfo (57) .. name .. ".mcl"
local f = io.open (filename, "r")
if f then
f:close ()
return
end -- world file exists
f = io.output (filename) -- create world file
assert (f:write ([[
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- MUSHclient world file -->
<!-- Written by Nick Gammon -->
<!-- Home Page: http://www.mushclient.com/ -->
<!-- Generated by getworld.lua plugin -->
<muclient>
<world defaults="y"
name="]] .. name .. [["
site="0.0.0.0"
port="4000"
/>
]] .. extra .. [[
</muclient>
]]))
f:close () -- close world file now
-- and open the file ;P
Open (filename)
end -- make_world
-- open a world by name, return world object or nil if cannot
function get_a_world (name)
-- try to find world
local w = GetWorld (name) -- get world
-- if not found, try to open it in worlds directory
if not cannot_open_world [name] and not w then
local filename = GetInfo (57) .. name .. ".mcl"
Open (filename) -- get MUSHclient to open it
Activate () -- make our original world active again
w = GetWorld (name) -- try again to get the world object
if w then
w:DeleteOutput () -- delete "welcome to MUSHclient" message
else
ColourNote ("white", "red", "Can't open world file: " .. filename)
cannot_open_world [name] = true -- don't repeatedly show failure message
end -- can't find world
end -- can't find world first time around
return w
end -- get_a_world
-- send the styles (eg. from a trigger) to the named world, opening it if necessary
function send_to_world (name, styles)
local w = get_a_world (name)
if w then -- if present
for _, v in ipairs (styles) do
w:ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end -- for each style run
w:Note ("") -- wrap up line
end -- world found
return w -- so they can check if we succeeded
end -- send_to_world
Alternatively, delete these lines from the plugin:
-- ensure world file exists
make_world (map_world, [[
<!-- plugins -->
<include name="Send_Input_To_Main_World.xml" plugin="y" />
<include name="Copy_Output.xml" plugin="y" />
]])
... and just make a world file yourself. (IP address 0.0.0.0 and call it "Aardwolf Big Map").
Now to test it, type 'bigmap' which will put the map in the secondary window. I am testing for a specific number of hyphens here, so it works for me outside Aylor, it may not work on other continents right now.
Then as you move the [Exits: *] line triggers sending "coordinates" which are suppressed by the plugin, and update your x/y position.
The plugin cached the whole map's style runs, and then when it gets coordinates it updates where it draws the star. Right now I am doing it in yellow so I can see it, but you can change that back to red.
A couple of problems with it right now:
- The red star which it originally got does not move, because that was part of the map. I'm not sure how to know what it should be replaced with.
- It doesn't update once you go inside an area.
However as a proof of concept, you may want to see how flicker-free it is for you. This is really only a first preliminary version. :)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|