Skip to content

Commit 38212e5

Browse files
committed
Updated mapper to handle new GMCP Room.Info structure and improved game detection
Added: - Support for new GMCP Room.Info structure with exits directly under Room.Info.Exits - Door details handling with state in exitData.details.state instead of exitData.status - Exit locking/unlocking based on door states (closed/locked doors prevent pathfinding) - Generic mmp.setEnvironmentColors() function for automatic room coloring - mmp.setGame() function to ensure game names are always lowercase - Game detection requirement for mconfig command - "mmp game" diagnostic command to check game detection status - Debug messages for coordinate parsing and room repositioning Changed: - Door update logic to check exitData.details.type == "door" and use details.state - All game name comparisons to use lowercase consistently - GoMud environment data registration to apply colors immediately - mconfig to require game detection before showing options Fixed: - Game name inconsistency between "GoMud" and "gomud" - Coordinate positioning for rooms with GMCP coordinates - Game-specific options not showing due to incorrect filtering - Exit locking now properly affects speedwalking pathfinding Removed: - GoMud-specific mmp.setgomudcolorcodes() function (replaced with generic version)
1 parent 9ac1c11 commit 38212e5

25 files changed

+766
-202
lines changed

mfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"package": "GoMudMapper",
33
"title": "GoMud Mapper",
44
"description": "Custom GMCP mapper for GoMud.",
5-
"version": "2.0.2",
5+
"version": "2.0.3",
66
"author": "Morquin - forked from the IRE Mudlet Mapper",
77
"icon": "gomud-mapper-icon.png",
88
"dependencies": "",

src/aliases/GoMudMapper/utility/aliases.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@
5151
{
5252
"name": "option",
5353
"isActive": "yes",
54-
"regex": "^mconfig( (\\w+) (.*))?$",
54+
"regex": "^mconfig(?: (\\w+)(?: (.*))?)?$",
55+
"script": "",
56+
"isFolder": "no"
57+
},
58+
{
59+
"name": "mmp_game",
60+
"isActive": "yes",
61+
"regex": "^mmp game$",
5562
"script": "",
5663
"isFolder": "no"
5764
},
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Alias to show current game detection status
2+
if mmp.game then
3+
mmp.echo(string.format("Game detected: %s", mmp.game))
4+
5+
-- Show if there are any game-specific features enabled
6+
local gameSpecificOptions = {}
7+
for name, def in pairs(mmp.option_definitions or {}) do
8+
if def.games and table.contains(def.games, mmp.game) then
9+
table.insert(gameSpecificOptions, name)
10+
end
11+
end
12+
13+
if #gameSpecificOptions > 0 then
14+
mmp.echo(string.format("Game-specific options available: %s", table.concat(gameSpecificOptions, ", ")))
15+
end
16+
else
17+
mmp.echo("No game detected yet.")
18+
mmp.echo("The mapper will try to detect your game from GMCP when you connect.")
19+
mmp.echo("Your game should set gmcp.Game.Info.engine to identify itself.")
20+
21+
-- Show current GMCP status if available
22+
if gmcp and gmcp.Game and gmcp.Game.Info then
23+
if gmcp.Game.Info.engine then
24+
mmp.echo(string.format("GMCP reports engine as: %s", gmcp.Game.Info.engine))
25+
mmp.echo("Try reconnecting to properly initialize the mapper.")
26+
else
27+
mmp.echo("GMCP is available but engine is not set.")
28+
end
29+
else
30+
mmp.echo("No GMCP game information available.")
31+
end
32+
end
Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
1+
-- matches[1] is the full command
2+
-- matches[2] is the option name (if provided)
3+
-- matches[3] is the value (if provided)
4+
5+
-- Check if game is detected
6+
if not mmp.game then
7+
mmp.echo("Game not detected. Please reconnect to your MUD so the mapper can identify which game you're playing.")
8+
mmp.echo("Games should either set gmcp.Game.Info.engine or use a login trigger to set mmp.game")
9+
return
10+
end
11+
112
if not matches[2] then
13+
-- Show all options with the new display format
214
mmp.settings:showAllOptions(mmp.game)
315
return
416
end
517

6-
local val = matches[4]
18+
local option = matches[2]
19+
local val = matches[3]
20+
21+
-- If only option name is provided (no value), show description
22+
if option and (not val or val == "") then
23+
-- Use the new getOptionDef method to get the option definition
24+
local optionDef = mmp.settings:getOptionDef(option)
25+
26+
if optionDef then
27+
-- Use mapper color scheme: light green for labels, white for values
28+
echo("\n")
29+
decho("<112,229,0>" .. option .. ":<255,255,255> " .. (optionDef.use or "No description available") .. "\n")
30+
-- Show current value
31+
local currentValue = mmp.settings[option]
32+
if type(currentValue) == "boolean" then
33+
currentValue = currentValue and "on" or "off"
34+
end
35+
decho("<112,229,0>Current value: <255,255,255>" .. tostring(currentValue) .. "\n")
36+
37+
-- Show accepted values
38+
if optionDef.allowedVarTypes and table.contains(optionDef.allowedVarTypes, "boolean") then
39+
decho("<112,229,0>Accepted values: <128,128,128>on, off\n")
40+
elseif option == "laglevel" then
41+
decho("<112,229,0>Accepted values: <128,128,128>1-5 (1=fast, 5=very slow)\n")
42+
elseif option == "echocolour" then
43+
decho("<112,229,0>Accepted values: <128,128,128>Any valid color name (see 'mcolor' for options)\n")
44+
end
45+
else
46+
mmp.echo("Unknown option: " .. option)
47+
end
48+
return
49+
end
50+
51+
-- Convert values
752
if val == "true" or val == "yes" or val == "on" then
853
val = true
954
end
@@ -12,4 +57,4 @@ if val == "false" or val == "no" or val == "off" then
1257
end
1358
local numberVal = tonumber(val)
1459
val = numberVal and numberVal or val
15-
mmp.settings:setOption(matches[3], val)
60+
mmp.settings:setOption(option, val)

src/aliases/aliases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"name": "gomud_mapper",
3+
"name": "GoMudMapper",
44
"isActive": "yes",
55
"script": "",
66
"isFolder": "yes"

src/scripts/GoMudMapper/core/create_option_table.lua

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ function mmp.createOptionsTable(defaultTable)
6868
end
6969

7070
function proxyTable:showAllOptions(game)
71-
proxyTable.disp("Available options: \n")
71+
-- Display header using mapper color scheme
72+
decho("<112,229,0>Setting: <255,255,255>State: <128,128,128>Option:\n")
73+
decho("<128,128,128>" .. string.rep("-", 60) .. "\n")
74+
75+
-- Display all options
7276
for k, v in spairs(self[index]) do
7377
if not game or not v.games or v.games[game] then
7478
self.dispOption(k, v)
7579
end
7680
end
77-
echo("\n")
7881
for k, v in spairs(self["_customOptions"]) do
7982
self.dispOption(k, v)
8083
end
@@ -88,12 +91,41 @@ function mmp.createOptionsTable(defaultTable)
8891

8992
return t
9093
end
94+
95+
function proxyTable:getOptionDef(option)
96+
-- Check custom options first
97+
if self["_customOptions"][option] then
98+
return self["_customOptions"][option]
99+
-- Then check default options
100+
elseif self[index][option] then
101+
return self[index][option]
102+
end
103+
return nil
104+
end
91105

92106
function proxyTable:setOption(option, value, silent)
93107
if self[option] == nil then
94108
proxyTable.disp("No such option!\n")
95109
return
96110
end
111+
112+
-- Convert on/off to boolean for boolean options
113+
local optionDef = self["_customOptions"][option] or self[index][option]
114+
if optionDef and optionDef.allowedVarTypes and table.contains(optionDef.allowedVarTypes, "boolean") then
115+
if value == "on" then
116+
value = true
117+
elseif value == "off" then
118+
value = false
119+
elseif type(value) == "string" then
120+
-- Try to parse other string boolean values
121+
local lowerValue = value:lower()
122+
if lowerValue == "true" or lowerValue == "yes" or lowerValue == "1" then
123+
value = true
124+
elseif lowerValue == "false" or lowerValue == "no" or lowerValue == "0" then
125+
value = false
126+
end
127+
end
128+
end
97129

98130
-- otherwise, set the option
99131
if self["_customOptions"][option] then

src/scripts/GoMudMapper/core/load_settings.lua

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ mmp.lagtable = {
2525
[4] = { description = "Bad. Terrible. Terribad.", time = 5 },
2626
[5] = { description = "Carrier Pigeon", time = 10 },
2727
}
28-
local newversion = "2.0.2"
28+
local newversion = "__VERSION__"
2929
if mmp.version and mmp.version ~= newversion then
3030
if not mmp.game then
3131
-- Check if this is GoMud via GMCP
32-
if gmcp and gmcp.Game and gmcp.Game.Info and gmcp.Game.Info.engine == "GoMud" then
33-
mmp.game = "GoMud"
32+
if gmcp and gmcp.Game and gmcp.Game.Info and gmcp.Game.Info.engine then
33+
mmp.setGame(gmcp.Game.Info.engine)
3434
mmp.echo("Mapper script updated - thanks! You don't need to restart.")
3535
else
3636
mmp.echo(
@@ -54,78 +54,55 @@ function mmp.startup()
5454
if not mmp.firstRun then
5555
return
5656
end
57-
local private_settings = {}
5857

59-
--General settings
58+
-- Load options from the simple definition table
59+
local private_settings = mmp.convertOptionsFromDefinitions()
6060

61-
private_settings["echocolour"] = mmp.createOption(
62-
"cyan",
63-
mmp.changeEchoColour,
64-
{ "string" },
65-
"Set the color for room number echos?",
66-
function(newSetting)
67-
return color_table[newSetting] ~= nil
61+
mmp.settings = mmp.createOptionsTable(private_settings)
62+
mmp.settings.disp = mmp.echo
63+
64+
-- Detect game type if not already set
65+
if not mmp.game then
66+
if gmcp and gmcp.Game and gmcp.Game.Info and gmcp.Game.Info.engine then
67+
mmp.setGame(gmcp.Game.Info.engine)
68+
else
69+
mmp.game = false
6870
end
69-
)
70-
private_settings["crowdmap"] = mmp.createOption(
71-
false,
72-
mmp.changeMapSource,
73-
{ "boolean" },
74-
"Use a crowd-sourced map instead of games default?",
75-
nil,
76-
{ gomud = true }
77-
)
78-
private_settings["showcmds"] = mmp.createOption(true, mmp.changeBoolFunc, { "boolean" }, "Show walking commands?")
79-
private_settings["laglevel"] = mmp.createOption(
80-
1,
81-
mmp.changeLaglevel,
82-
{ "number" },
83-
"How laggy is your connection, (fast 1<->5 slow)?",
84-
mmp.verifyLaglevel
85-
)
86-
private_settings["slowwalk"] =
87-
mmp.createOption(false, mmp.setSlowWalk, { "boolean" }, "Walk slowly instead of as quick as possible?")
88-
private_settings["fastwalk"] = mmp.createOption(
89-
false,
90-
mmp.changeBoolFunc,
91-
{ "boolean" },
92-
"Walk as quick as possible instead of waiting for prompts?"
93-
)
94-
private_settings["updatemap"] =
95-
mmp.createOption(true, mmp.changeUpdateMap, { "boolean" }, "Check for new maps from your MUD?")
96-
private_settings["autopositionrooms"] = mmp.createOption(
97-
true,
98-
mmp.setAutoPositionRooms,
99-
{ "boolean" },
100-
"Auto position rooms when mapping?",
101-
nil,
102-
{ gomud = true }
103-
)
104-
private_settings["debug"] = mmp.createOption(false, mmp.changeBoolFunc, { "boolean" }, "Enable debug messages?")
71+
end
10572

106-
--Settings that lock things
73+
mmp.settings.dispOption = function(opt, val)
74+
-- Format boolean values as on/off
75+
local displayValue = val.value
76+
if type(val.value) == "boolean" then
77+
displayValue = val.value and "on" or "off"
78+
end
10779

108-
private_settings["lockspecials"] =
109-
mmp.createOption(false, mmp.lockSpecials, { "boolean" }, "Lock all special exits?")
80+
-- Determine options available
81+
local options = ""
82+
if val.allowedVarTypes and table.contains(val.allowedVarTypes, "boolean") then
83+
options = "on|off"
84+
elseif opt == "laglevel" then
85+
options = "1-5"
86+
elseif opt == "echocolour" then
87+
options = "See mcolor for options"
88+
else
89+
options = tostring(displayValue)
90+
end
11091

111-
mmp.settings = mmp.createOptionsTable(private_settings)
112-
mmp.settings.disp = mmp.echo
113-
mmp.game = false
114-
mmp.settings.dispOption = function(opt, val)
115-
cecho(
116-
"<green>"
117-
.. val.use
118-
.. "<white> ("
119-
.. opt
120-
.. ") "
121-
.. string.rep(" ", 50 - val.use:len() - opt:len())
122-
.. tostring(val.value)
123-
.. "\n"
124-
)
92+
-- Display in columns: Setting, State, Option
93+
-- Using mapper's color scheme: light green for settings, white for values, dim gray for options
94+
decho(string.format("<112,229,0>%-22s <255,255,255>%-15s <128,128,128>%s\n", opt, tostring(displayValue), options))
12595
end
96+
12697
mmp.settings.dispDefaultWriteError = function()
12798
mmp.echo("Please use the mconfig alias to set options!")
12899
end
100+
101+
-- Set environment colors if they're defined
102+
if mmp.setEnvironmentColors then
103+
mmp.setEnvironmentColors()
104+
end
105+
129106
raiseEvent("mmp areas changed")
130107
mmp.firstRun = false
131108
mmp.echon("Mudlet Mapper script for GoMud (" .. tostring(mmp.version) .. ") loaded! (")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Event handler for when the package is installed or reinstalled
2+
-- This ensures the mapper reinitializes properly after package updates
3+
4+
function mmp.onPackageInstalled(_, package)
5+
-- Check if this is our package being installed
6+
if package and (package:find("MudletMapper") or package:find("GoMudMapper")) then
7+
-- Small delay to ensure all files are loaded
8+
tempTimer(0.5, function()
9+
if mmp and mmp.reload then
10+
mmp.reload()
11+
mmp.echo("GoMudMapper reinitialized after package installation.")
12+
end
13+
end)
14+
end
15+
end
16+
17+
-- Register the event handler
18+
if mmp.packageInstalledHandler then
19+
killAnonymousEventHandler(mmp.packageInstalledHandler)
20+
end
21+
mmp.packageInstalledHandler = registerAnonymousEventHandler("sysInstallPackage", "mmp.onPackageInstalled")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Generic function to set environment colors if mmp.colorcodes is defined
2+
function mmp.setEnvironmentColors()
3+
-- Check if color codes are defined
4+
if not mmp.colorcodes or type(mmp.colorcodes) ~= "table" then
5+
return false
6+
end
7+
8+
-- Apply color codes to environments
9+
local count = 0
10+
for id, rgba in pairs(mmp.colorcodes) do
11+
if type(rgba) == "table" and #rgba >= 3 then
12+
-- setCustomEnvColor expects RGB values, with optional alpha (default 255)
13+
local r, g, b, a = rgba[1], rgba[2], rgba[3], rgba[4] or 255
14+
setCustomEnvColor(id, r, g, b, a)
15+
count = count + 1
16+
end
17+
end
18+
19+
if count > 0 and mmp.settings and mmp.settings.debug then
20+
mmp.echo(string.format("Applied custom colors to %d environments", count))
21+
end
22+
23+
return count > 0
24+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Function to set the game, ensuring it's always lowercase
2+
function mmp.setGame(gameName)
3+
if gameName and type(gameName) == "string" then
4+
mmp.game = string.lower(gameName)
5+
6+
-- Initialize game-specific data if needed
7+
if mmp.game == "gomud" and mmp.registergomudenvdata then
8+
mmp.registergomudenvdata(nil, mmp.game)
9+
end
10+
11+
if mmp.settings and mmp.settings.debug then
12+
mmp.echo(string.format("Game set to: %s", mmp.game))
13+
end
14+
15+
-- Raise event for other scripts that might need to know
16+
raiseEvent("mmp game detected", mmp.game)
17+
else
18+
mmp.game = false
19+
if mmp.settings and mmp.settings.debug then
20+
mmp.echo("Game detection cleared")
21+
end
22+
end
23+
end

0 commit comments

Comments
 (0)