diff --git a/MDK/demontools.lua b/MDK/demontools.lua index 04d069c..defcb4a 100644 --- a/MDK/demontools.lua +++ b/MDK/demontools.lua @@ -93,32 +93,11 @@ local htmlHeaderPattern = [=[ ]=] --- internal function, recursively digs for a value within subtables if possible -local function digForValue(dataFrom, tableTo) - if dataFrom == nil or table.size(tableTo) == 0 then - return dataFrom - else - local newData = dataFrom[tableTo[1]] - table.remove(tableTo, 1) - return digForValue(newData, tableTo) - end -end - -- Internal function, used to turn a string variable name into a value local function getValueAt(accessString) - if accessString == "" then - return nil - end - local tempTable = accessString:split("%.") - local accessTable = {} - for i, v in ipairs(tempTable) do - if tonumber(v) then - accessTable[i] = tonumber(v) - else - accessTable[i] = v - end - end - return digForValue(_G, accessTable) + local ok, err = pcall(loadstring("return " .. tostring(accessString))) + if ok then return err end + return nil, err end -- internal sorting function, sorts first by hue, then luminosity, then value @@ -832,7 +811,7 @@ function string.tocolor(self) local strTable = {} local part1 = {} local part2 = {} - self:gsub(".", function(c) + _ = self:gsub(".", function(c) table.insert(strTable, c) end) for index, value in ipairs(strTable) do @@ -1104,29 +1083,29 @@ end -- -- -- --- format --- What format to return the text as? 'h' for html, 'c' for cecho, 'a' for ansi, 'd' for decho, and 'x' for hecho --- "d" +-- format +-- What format to return the text as? 'h' for html, 'c' for cecho, 'a' for ansi, 'd' for decho, and 'x' for hecho +-- "d" -- -- --- win --- what console/window to dump the buffer of? --- "main" +-- win +-- what console/window to dump the buffer of? +-- "main" -- -- --- start_line --- What line to start dumping the buffer from? --- 0 +-- start_line +-- What line to start dumping the buffer from? +-- 0 -- -- --- end_line --- What line to stop dumping the buffer on? --- Last line of the console +-- end_line +-- What line to stop dumping the buffer on? +-- Last line of the console -- -- --- includeHtmlWrapper --- If the format is html, should it include the front and back portions required to make it a functioning html page? --- true +-- includeHtmlWrapper +-- If the format is html, should it include the front and back portions required to make it a functioning html page? +-- true -- -- -- @@ -1146,49 +1125,49 @@ end -- -- -- --- cols --- Number of columsn wide to display the colors in --- 4 +-- cols +-- Number of columsn wide to display the colors in +-- 4 -- -- --- search --- If not the empty string, will check colors against string.find using this property.
IE if set to "blue" only colors which include the word 'blue' would be listed --- "" +-- search +-- If not the empty string, will check colors against string.find using this property.
IE if set to "blue" only colors which include the word 'blue' would be listed +-- "" -- -- --- sort --- If true, sorts alphabetically. Otherwise sorts based on the color value --- false +-- sort +-- If true, sorts alphabetically. Otherwise sorts based on the color value +-- false -- -- --- echoOnly --- If true, colors will not be clickable links --- false +-- echoOnly +-- If true, colors will not be clickable links +-- false -- -- --- window --- What window/console to echo the colors out to. --- "main" +-- window +-- What window/console to echo the colors out to. +-- "main" -- -- --- removeDupes --- If true, will remove snake_case entries and 'gray' in favor of 'grey' --- true +-- removeDupes +-- If true, will remove snake_case entries and 'gray' in favor of 'grey' +-- true -- -- --- columnSort --- If true, will print top-to-bottom, then left-to-right. false is like showColors --- true +-- columnSort +-- If true, will print top-to-bottom, then left-to-right. false is like showColors +-- true -- -- --- justText --- If true, will echo the text in the color and leave the background black.
If false, the background will be the colour(like showColors). --- false +-- justText +-- If true, will echo the text in the color and leave the background black.
If false, the background will be the colour(like showColors). +-- false -- -- --- color_table --- Table of colors to display. If you provide your own table, it must be in the same format as Mudlet's own color_table --- color_table +-- color_table +-- Table of colors to display. If you provide your own table, it must be in the same format as Mudlet's own color_table +-- color_table -- -- -- diff --git a/MDK/emco.lua b/MDK/emco.lua index 56eb222..123ac13 100644 --- a/MDK/emco.lua +++ b/MDK/emco.lua @@ -42,6 +42,11 @@ local EMCO = Geyser.Container:new({ gags = {}, notifyTabs = {}, notifyWithFocus = false, + cmdLineStyleSheet = [[ + QPlainTextEdit { + border: 1px solid grey; + } + ]] }) -- patch Geyser.MiniConsole if it does not have its own display method defined @@ -80,275 +85,280 @@ end -- -- -- --- timestamp --- display timestamps on the miniconsoles? --- false +-- timestamp +-- display timestamps on the miniconsoles? +-- false -- -- --- blankLine --- put a blank line between appends/echos? --- false +-- blankLine +-- put a blank line between appends/echos? +-- false -- -- --- scrollbars --- enable scrollbars for the miniconsoles? --- false +-- scrollbars +-- enable scrollbars for the miniconsoles? +-- false -- -- --- customTimestampColor --- if showing timestamps, use a custom color? --- false +-- customTimestampColor +-- if showing timestamps, use a custom color? +-- false -- -- --- mapTab --- should we attach the Mudlet Mapper to this EMCO? --- false +-- mapTab +-- should we attach the Mudlet Mapper to this EMCO? +-- false -- -- --- mapTabName --- Which tab should we attach the map to? +-- mapTabName +-- Which tab should we attach the map to? --
If mapTab is true and you do not set this, it will throw an error --- +-- -- -- --- blinkFromAll --- should tabs still blink, even if you're on the 'all' tab? --- false +-- blinkFromAll +-- should tabs still blink, even if you're on the 'all' tab? +-- false -- -- --- preserveBackground --- preserve the miniconsole background color during append()? --- false +-- preserveBackground +-- preserve the miniconsole background color during append()? +-- false -- -- --- gag --- when running :append(), should we also gag the line? --- false +-- gag +-- when running :append(), should we also gag the line? +-- false -- -- --- timestampFormat --- Format string for the timestamp. Uses getTime() --- "HH:mm:ss" +-- timestampFormat +-- Format string for the timestamp. Uses getTime() +-- "HH:mm:ss" -- -- --- timestampBGColor --- Custom BG color to use for timestamps. Any valid Geyser.Color works. --- "blue" +-- timestampBGColor +-- Custom BG color to use for timestamps. Any valid Geyser.Color works. +-- "blue" -- -- --- timestampFGColor --- Custom FG color to use for timestamps. Any valid Geyser.Color works --- "red" +-- timestampFGColor +-- Custom FG color to use for timestamps. Any valid Geyser.Color works +-- "red" -- -- --- allTab --- Should we send everything to an 'all' tab? --- false +-- allTab +-- Should we send everything to an 'all' tab? +-- false -- -- --- allTabName --- And which tab should we use for the 'all' tab? --- "All" +-- allTabName +-- And which tab should we use for the 'all' tab? +-- "All" -- -- --- blink --- Should we blink tabs that have been written to since you looked at them? --- false +-- blink +-- Should we blink tabs that have been written to since you looked at them? +-- false -- -- --- blinkTime --- How long to wait between blinks, in seconds? --- 3 +-- blinkTime +-- How long to wait between blinks, in seconds? +-- 3 -- -- --- fontSize --- What font size to use for the miniconsoles? --- 9 +-- fontSize +-- What font size to use for the miniconsoles? +-- 9 -- -- --- font --- What font to use for the miniconsoles? --- +-- font +-- What font to use for the miniconsoles? +-- -- -- --- tabFont --- What font to use for the tabs? --- +-- tabFont +-- What font to use for the tabs? +-- -- -- --- activeTabCss --- What css to use for the active tab? --- "" +-- activeTabCss +-- What css to use for the active tab? +-- "" -- -- --- inactiveTabCSS --- What css to use for the inactive tabs? --- "" +-- inactiveTabCSS +-- What css to use for the inactive tabs? +-- "" -- -- --- activeTabFGColor --- What color to use for the text on the active tab. Any Geyser.Color works. --- "purple" +-- activeTabFGColor +-- What color to use for the text on the active tab. Any Geyser.Color works. +-- "purple" -- -- --- inactiveTabFGColor --- What color to use for the text on the inactive tabs. Any Geyser.Color works. --- "white" +-- inactiveTabFGColor +-- What color to use for the text on the inactive tabs. Any Geyser.Color works. +-- "white" -- -- --- activeTabBGColor --- What BG color to use for the active tab? Any Geyser.Color works. Overriden by activeTabCSS --- "<0,180,0>" +-- activeTabBGColor +-- What BG color to use for the active tab? Any Geyser.Color works. Overriden by activeTabCSS +-- "<0,180,0>" -- -- --- inactiveTabBGColor --- What BG color to use for the inactavie tabs? Any Geyser.Color works. Overridden by inactiveTabCSS --- "<60,60,60>" +-- inactiveTabBGColor +-- What BG color to use for the inactavie tabs? Any Geyser.Color works. Overridden by inactiveTabCSS +-- "<60,60,60>" -- -- --- consoleColor --- Default background color for the miniconsoles. Any Geyser.Color works --- "black" +-- consoleColor +-- Default background color for the miniconsoles. Any Geyser.Color works +-- "black" -- -- --- tabBoxCSS --- tss for the entire tabBox (not individual tabs) --- "" +-- tabBoxCSS +-- tss for the entire tabBox (not individual tabs) +-- "" -- -- --- tabBoxColor --- What color to use for the tabBox? Any Geyser.Color works. Overridden by tabBoxCSS --- "black" +-- tabBoxColor +-- What color to use for the tabBox? Any Geyser.Color works. Overridden by tabBoxCSS +-- "black" -- -- --- consoleContainerCSS --- CSS to use for the container holding the miniconsoles --- "" +-- consoleContainerCSS +-- CSS to use for the container holding the miniconsoles +-- "" -- -- --- consoleContainerColor --- Color to use for the container holding the miniconsole. Any Geyser.Color works. Overridden by consoleContainerCSS --- "black" +-- consoleContainerColor +-- Color to use for the container holding the miniconsole. Any Geyser.Color works. Overridden by consoleContainerCSS +-- "black" -- -- --- gap --- How many pixels to place between the tabs and the miniconsoles? --- 1 +-- gap +-- How many pixels to place between the tabs and the miniconsoles? +-- 1 -- -- --- consoles --- List of the tabs for this EMCO in table format --- { "All" } +-- consoles +-- List of the tabs for this EMCO in table format +-- { "All" } -- -- --- allTabExclusions --- List of the tabs which should never echo to the 'all' tab in table format --- {} +-- allTabExclusions +-- List of the tabs which should never echo to the 'all' tab in table format +-- {} -- -- --- tabHeight --- How many pixels high should the tabs be? --- 25 +-- tabHeight +-- How many pixels high should the tabs be? +-- 25 -- -- --- autoWrap --- Use autoWrap for the miniconsoles? --- true +-- autoWrap +-- Use autoWrap for the miniconsoles? +-- true -- -- --- wrapAt --- How many characters to wrap it, if autoWrap is turned off? --- 300 +-- wrapAt +-- How many characters to wrap it, if autoWrap is turned off? +-- 300 -- -- --- leftMargin --- Number of pixels to put between the left edge of the EMCO and the miniconsole? --- 0 +-- leftMargin +-- Number of pixels to put between the left edge of the EMCO and the miniconsole? +-- 0 -- -- --- rightMargin --- Number of pixels to put between the right edge of the EMCO and the miniconsole? --- 0 +-- rightMargin +-- Number of pixels to put between the right edge of the EMCO and the miniconsole? +-- 0 -- -- --- bottomMargin --- Number of pixels to put between the bottom edge of the EMCO and the miniconsole? --- 0 +-- bottomMargin +-- Number of pixels to put between the bottom edge of the EMCO and the miniconsole? +-- 0 -- -- --- topMargin --- Number of pixels to put between the top edge of the miniconsole container, and the miniconsole? This is in addition to gap --- 0 +-- topMargin +-- Number of pixels to put between the top edge of the miniconsole container, and the miniconsole? This is in addition to gap +-- 0 -- -- --- timestampExceptions --- Table of tabnames which should not get timestamps even if timestamps are turned on --- {} +-- timestampExceptions +-- Table of tabnames which should not get timestamps even if timestamps are turned on +-- {} -- -- --- tabFontSize --- Font size for the tabs --- 8 +-- tabFontSize +-- Font size for the tabs +-- 8 -- -- --- tabBold --- Should the tab text be bold? Boolean value --- false +-- tabBold +-- Should the tab text be bold? Boolean value +-- false -- -- --- tabItalics --- Should the tab text be italicized? --- false +-- tabItalics +-- Should the tab text be italicized? +-- false -- -- --- tabUnderline --- Should the tab text be underlined? --- false +-- tabUnderline +-- Should the tab text be underlined? +-- false -- -- --- tabAlignment --- Valid alignments are 'c', 'center', 'l', 'left', 'r', 'right', or '' to not include the alignment as part of the echo (to allow the stylesheet to handle it) --- 'c' +-- tabAlignment +-- Valid alignments are 'c', 'center', 'l', 'left', 'r', 'right', or '' to not include the alignment as part of the echo (to allow the stylesheet to handle it) +-- 'c' -- -- --- commandLine --- Should we enable commandlines for the miniconsoles? --- false +-- commandLine +-- Should we enable commandlines for the miniconsoles? +-- false -- -- --- cmdActions --- A table with console names as keys, and values which are templates for the command to send. see the setCustomCommandline function for more --- {} +-- cmdActions +-- A table with console names as keys, and values which are templates for the command to send. see the setCustomCommandline function for more +-- {} -- -- --- backgroundImages --- A table containing definitions for the background images. Each entry should have a key the same name as the tab it applies to, with entries "image" which is the path to the image file,
and "mode" which determines how it is displayed. "border" stretches, "center" center, "tile" tiles, and "style". See Mudletwikilink for details. --- {} +-- cmdLineStyleSheet +-- What stylesheet to use for the command lines. +-- "QPlainTextEdit {\n border: 1px solid grey;\n }\n" -- -- --- bufferSize --- Number of lines of scrollback to keep for the miniconsoles --- 100000 +-- backgroundImages +-- A table containing definitions for the background images. Each entry should have a key the same name as the tab it applies to, with entries "image" which is the path to the image file,
and "mode" which determines how it is displayed. "border" stretches, "center" center, "tile" tiles, and "style". See Mudletwikilink for details. +-- {} -- -- --- deleteLines --- Number of lines to delete if a console's buffer fills up. --- 1000 +-- bufferSize +-- Number of lines of scrollback to keep for the miniconsoles +-- 100000 -- -- --- gags --- A table of Lua patterns you wish to gag from being added to the EMCO. Useful for removing mob says and such example: {[[^A green leprechaun says, ".*"$]], "^Bob The Dark Lord of the Keep mutters darkly to himself.$"} see this tutorial on Lua patterns for more information. --- {} +-- deleteLines +-- Number of lines to delete if a console's buffer fills up. +-- 1000 -- -- --- notifyTabs --- Tables containing the names of all tabs you want to send notifications. IE {"Says", "Tells", "Org"} --- {} +-- gags +-- A table of Lua patterns you wish to gag from being added to the EMCO. Useful for removing mob says and such example: {[[^A green leprechaun says, ".*"$]], "^Bob The Dark Lord of the Keep mutters darkly to himself.$"} see this tutorial on Lua patterns for more information. +-- {} -- -- --- notifyWithFocus --- If true, EMCO will send notifications even if Mudlet has focus. If false, it will only send them when Mudlet does NOT have focus. --- false +-- notifyTabs +-- Tables containing the names of all tabs you want to send notifications. IE {"Says", "Tells", "Org"} +-- {} +-- +-- +-- notifyWithFocus +-- If true, EMCO will send notifications even if Mudlet has focus. If false, it will only send them when Mudlet does NOT have focus. +-- false -- -- -- @@ -701,7 +711,6 @@ function EMCO:createComponentsForTab(tabName) if self.tabFont then tab:setFont(self.tabFont) end - tab:echo(tabName, self.inactiveTabFGColor) tab:setAlignment(self.tabAlignment) tab:setFontSize(self.tabFontSize) tab:setItalics(self.tabItalics) @@ -710,6 +719,7 @@ function EMCO:createComponentsForTab(tabName) tab:setClickCallback(self.switchTab, self, tabName) self.tabs[tabName] = tab self:adjustTabBackground(tabName) + tab:echo(tabName, self.inactiveTabFGColor) local window local windowConstraints = { x = self.leftMargin, @@ -718,6 +728,7 @@ function EMCO:createComponentsForTab(tabName) width = string.format("-%dpx", self.rightMargin), name = string.format("%sWindow%s", self.name, tabName), commandLine = self.commandLine, + cmdLineStyleSheet = self.cmdLineStyleSheet, path = self:processTemplate(self.path, tabName), fileName = self:processTemplate(self.fileName, tabName), logFormat = self.logFormat @@ -758,6 +769,7 @@ function EMCO:createComponentsForTab(tabName) end window:hide() self:processImage(tabName) + self:switchTab(tabName) end --- Sets the buffer size and number of lines to delete for all managed miniconsoles. @@ -899,6 +911,57 @@ function EMCO:setFileName(fileName) end end +--- Sets the stylesheet for command lines in this EMCO +-- @tparam string styleSheet the stylesheet to use for the command line. See https://wiki.mudlet.org/w/Manual:Lua_Functions#setCmdLineStyleSheet for examples +function EMCO:setCmdLineStyleSheet(styleSheet) + self.cmdLineStyleSheet = styleSheet + if not styleSheet then + return + end + for _, window in pairs(self.mc) do + window:setCmdLineStyleSheet(styleSheet) + end +end +--- Enables the commandLine on the specified tab. +-- @tparam string tabName the name of the tab to turn the commandLine on for +-- @param template the template for the commandline to use, or the function to run when enter is hit. +-- @usage myEMCO:enableCmdLine(tabName, template) +function EMCO:enableCmdLine(tabName, template) + if not table.contains(self.consoles, tabName) then + return nil, f"{self.name}:enableCmdLine(tabName,template) tabName is not in the console list. Valid options are {table.concat(self.consoles, 'm')}" + end + local window = self.mc[tabName] + window:enableCommandLine() + if self.cmdLineStyleSheet then + window:setCmdLineStyleSheet(self.cmdLineStyleSheet) + end + self:setCmdAction(tabName, template) +end + +--- Enables all command lines, using whatever template they may currently have set +function EMCO:enableAllCmdLines() + for _, tabName in ipairs(self.consoles) do + self:enableCmdLine(tabName, self.cmdActions[tabName]) + end +end + +--- Disables all commands line, but does not change their template +function EMCO:disableAllCmdLines() + for _, tabName in ipairs(self.consoles) do + self:disableCmdLine(tabName) + end +end + +--- Disables the command line for a particular tab +-- @tparam string tabName the name of the tab to disable the command line of. +function EMCO:disableCmdLine(tabName) + if not table.contains(self.consoles, tabName) then + return nil, f"{self.name}:disableCmdLine(tabName,template) tabName is not in the console list. Valid options are {table.concat(self.consoles, 'm')}" + end + local window = self.mc[tabName] + window:disableCommandLine() +end + --- Sets the command action for a tab's command line. Can either be a template string to send where '|t' is replaced by the text sent, or a funnction which takes the text --- @tparam string tabName the name of the tab to set the command action on --- @param template the template for the commandline to use, or the function to run when enter is hit. @@ -968,12 +1031,8 @@ function EMCO:reset() for _, tabName in ipairs(self.consoles) do self:createComponentsForTab(tabName) end - local default - if self.currentTab == "" then - default = self.allTabName or self.consoles[1] - else - default = self.currentTab - end + + local default = self.allTabName or self.consoles[1] self:switchTab(default) end @@ -1002,7 +1061,7 @@ function EMCO:createContainers() end function EMCO:stripTimeChars(str) - return string.gsub(string.trim(str), '[hHmMszZaApPdy:. ]', '') + return string.gsub(string.trim(str), '[ThHmMszZaApPdy0-9%-%+:. ]', '') end --- Expands boolean definitions to be more flexible. @@ -1411,6 +1470,20 @@ function EMCO:adjustTabBackgrounds() end end +--- Sets the inactiveTabCSS +-- @tparam string stylesheet the stylesheet to use for inactive tabs. +function EMCO:setInactiveTabCSS(stylesheet) + self.inactiveTabCSS = stylesheet + self:adjustTabBackgrounds() +end + +--- Sets the activeTabCSS +-- @tparam string stylesheet the stylesheet to use for active tab. +function EMCO:setActiveTabCSS(stylesheet) + self.activeTabCSS = stylesheet + self:adjustTabBackgrounds() +end + --- Sets the FG color for the active tab -- @param color Color string suitable for decho or hecho, or color name eg "purple", or table of colors {r,g,b} function EMCO:setActiveTabFGColor(color) @@ -2142,6 +2215,7 @@ function EMCO:save() gags = self.gags, notifyTabs = self.notifyTabs, notifyWithFocus = self.notifyWithFocus, + cmdLineStyleSheet = self.cmdLineStyleSheet, } local dirname = getMudletHomeDir() .. "/EMCO/" local filename = dirname .. self.name:gsub("[<>:'\"/\\|?*]", "_") .. ".lua" @@ -2211,6 +2285,7 @@ function EMCO:load() self.gags = configTable.gags self.notifyTabs = configTable.notifyTabs self.notifyWithFocus = configTable.notifyWithFocus + self.cmdLineStyleSheet = configTable.cmdLineStyleSheet self:move(configTable.x, configTable.y) self:resize(configTable.width, configTable.height) self:reset() diff --git a/MDK/loggingconsole.lua b/MDK/loggingconsole.lua index ec7849f..cbc812a 100644 --- a/MDK/loggingconsole.lua +++ b/MDK/loggingconsole.lua @@ -22,24 +22,24 @@ local LoggingConsole = {log = true, logFormat = "h", path = "|h/log/consoleLogs/ -- -- -- --- log --- Should the miniconsole be logging? --- true +-- log +-- Should the miniconsole be logging? +-- true -- -- --- logFormat --- "h" for html, "t" for plaintext, "l" for log (with ansi) --- h +-- logFormat +-- "h" for html, "t" for plaintext, "l" for log (with ansi) +-- h -- -- --- path --- The path the file lives in. It is templated.
|h is replaced by the profile homedir.
|y by 4 digit year.
|m by 2 digit month
|d by 2 digit day
|n by the name constraint
|e by the file extension (html for h logType, log for others) --- "|h/log/consoleLogs/|y/|m/|d/" +-- path +-- The path the file lives in. It is templated.
|h is replaced by the profile homedir.
|y by 4 digit year.
|m by 2 digit month
|d by 2 digit day
|n by the name constraint
|e by the file extension (html for h logType, log for others) +-- "|h/log/consoleLogs/|y/|m/|d/" -- -- --- fileName --- The name of the log file. It is templated, same as path above --- "|n.|e" +-- fileName +-- The name of the log file. It is templated, same as path above +-- "|n.|e" -- -- -- @@ -188,7 +188,7 @@ function LoggingConsole:xEcho(str, etype, log) local logType = self.logFormat if logType:find("h") then logType = "h" - else + elseif logType ~= "t" then logType = "l" end if etype == "d" then -- decho diff --git a/MDK/sug.lua b/MDK/sug.lua index 3db8a73..ea99c90 100644 --- a/MDK/sug.lua +++ b/MDK/sug.lua @@ -15,33 +15,11 @@ local SUG = { strict = true, } --- ========== Copied from demontools.lua in order to cut the dependency for just this small functionality ========== --- internal function, recursively digs for a value within subtables if possible -local function digForValue(dataFrom, tableTo) - if dataFrom == nil or table.size(tableTo) == 0 then - return dataFrom - else - local newData = dataFrom[tableTo[1]] - table.remove(tableTo, 1) - return digForValue(newData, tableTo) - end -end - -- Internal function, used to turn a string variable name into a value local function getValueAt(accessString) - if accessString == "" then - return nil - end - local tempTable = accessString:split("%.") - local accessTable = {} - for i, v in ipairs(tempTable) do - if tonumber(v) then - accessTable[i] = tonumber(v) - else - accessTable[i] = v - end - end - return digForValue(_G, accessTable) + local ok, err = pcall(loadstring("return " .. tostring(accessString))) + if ok then return err end + return nil, err end -- ========== End section copied from demontools.lua @@ -56,44 +34,49 @@ end -- default -- -- --- active --- boolean, if true starts the timer updating --- true +-- active +-- boolean, if true starts the timer updating +-- true -- -- --- updateTime --- How often should the gauge autoupdate? Milliseconds. 0 to disable the timer but still allow event updates --- 333 +-- updateTime +-- How often should the gauge autoupdate? Milliseconds. 0 to disable the timer but still allow event updates +-- 333 -- -- --- currentVariable --- What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "currentHP" or "gmcp.Char.Vitals.hp" --- "" +-- currentVariable +-- What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "currentHP" or "gmcp.Char.Vitals.hp" +-- "" -- -- --- maxVariable --- What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "maxHP" or "gmcp.Char.Vitals.maxhp" --- "" +-- maxVariable +-- What variable will hold the 'current' value of the gauge? Pass the name as a string, IE "maxHP" or "gmcp.Char.Vitals.maxhp" +-- "" -- -- --- textTemplate --- Template to use for the text on the gauge. "|c" replaced with current value, "|m" replaced with max value, "|p" replaced with the % full the gauge should be --- " |c/|m |p%" +-- textTemplate +-- Template to use for the text on the gauge. "|c" replaced with current value, "|m" replaced with max value, "|p" replaced with the % full the gauge should be +-- " |c/|m |p%" -- -- --- defaultCurrent --- What value to use if the currentVariable points to nil or something which cannot be made a number? --- 50 +-- defaultCurrent +-- What value to use if the currentVariable points to nil or something which cannot be made a number? +-- 50 -- -- --- defaultMax --- What value to use if the maxVariable points to nil or something which cannot be made a number? --- 100 +-- defaultMax +-- What value to use if the maxVariable points to nil or something which cannot be made a number? +-- 100 -- -- --- updateEvent --- The name of an event to listen for to perform an update. Can be run alongside or instead of the timer updates. Empty string to turn off --- "" +-- updateEvent +-- The name of an event to listen for to perform an update. Can be run alongside or instead of the timer updates. Empty string to turn off +-- "" +-- +-- +-- updateHook +-- A function which is run each time the gauge updates. Should take 3 arguments, the gauge itself, current value, and max value. You can return new current and max values to be used, for example `return 34, 120` would cause the gauge to use 34 for current and 120 for max regardless of what the variables it reads say. +-- -- -- -- @param container The Geyser container for this gauge @@ -194,6 +177,16 @@ function SUG:setTextTemplate(template) self:update() end +--- Set the updateHook function which is run just prior to the gauge updating +-- @tparam function func The function which will be called when the gauge updates. It should take 3 arguments, the gauge itself, the current value, and the max value. If you wish to override the current or max values used for the gauge, you can return new current and max values, like `return newCurrent newMax` +function SUG:setUpdateHook(func) + local funcType = type(func) + if funcType ~= "function" then + return nil, "setUpdateHook only takes functions, no strings or anything like that. You passed in: " .. funcType + end + self.updateHook = func +end + --- Stops the Self Updating Gauge from updating function SUG:stop() self.active = false @@ -241,6 +234,13 @@ function SUG:update() self.name, self.currentVariable, self.maxVariable)) end end + if self.updateHook and type(self.updateHook) == "function" then + local ok, newcur, newmax = pcall(self.updateHook, self, current, max) + if ok and newcur then + current = newcur + max = newmax and newmax or self.defaultMax + end + end local text = self.textTemplate local percent = math.floor((current / max * 100) + 0.5) text = text:gsub("|c", current) diff --git a/PRS.lua b/PRS.lua index 3cf200d..2d2fbff 100644 --- a/PRS.lua +++ b/PRS.lua @@ -1,5 +1,5 @@ -- Procedural Realms Script (PRS) by Stack -local version = "0.12.0" +local version = "1.3.0" -- check if the generic_mapper package is installed and, if so, uninstall it if table.contains(getPackages(),"generic_mapper") then @@ -12,3 +12,5 @@ registerAnonymousEventHandler("gmcp.Char.player", function() PRSstats.stats() end, true) +-- Announce PR on Discord +setDiscordGame("Procedural Realms") \ No newline at end of file diff --git a/prs-mapper.lua b/prs-mapper.lua index 348551c..9209ee7 100644 --- a/prs-mapper.lua +++ b/prs-mapper.lua @@ -96,7 +96,11 @@ local terrain_types = { ["Temple Entrance"] = {id = 85, r = 128, g = 0, b = 128}, ["Frozen River"] = {id = 86, r = 0, g = 255, b = 255}, ["Clearing"] = {id = 87, r = 0, g = 128, b = 0}, - ["Frozen Peak"] = {id = 88, r = 0, g = 0, b = 255}, + ["Frozen Peak"] = {id = 88, r = 0, g = 0, b = 255}, + ["Obsidian Floor"] = {id = 89, r = 192, g = 192, b = 192}, + ["Obelisk Exit"] = {id = 90, r = 128, g = 0, b = 128}, + ["Permafrost"] = {id = 91, r = 0, g = 255, b = 255}, + ["Gold Mine Tailings"] = {id = 92, r = 255, g = 255, b = 255}, } -- list of possible movement directions and appropriate coordinate changes @@ -196,7 +200,7 @@ local function make_room() local exit_coords_delta = move_vectors[dir] local exit_room_id = get_room_id_by_coordinates(info.area, coords[1] + exit_coords_delta[1], coords[2] + exit_coords_delta[2], coords[3] + exit_coords_delta[3]) if exit_room_id ~= nill then - connectExitStub(room_id, dir) + connectExitStub(room_id, exit_room_id, dir) end end end @@ -235,7 +239,7 @@ local function handle_move() local exit_coords_delta = move_vectors[stubmap[v]] local exit_room_id = get_room_id_by_coordinates(info.area, coords[1] + exit_coords_delta[1], coords[2] + exit_coords_delta[2], coords[3] + exit_coords_delta[3]) if exit_room_id ~= nill then - connectExitStub(room_id, v) + connectExitStub(room_id, exit_room_id, v) end end end