From c7f11ce368041747f16ce082f0f039d7f5895c8c Mon Sep 17 00:00:00 2001 From: grrtt49 <81640993+grrtt49@users.noreply.github.com> Date: Thu, 17 Aug 2023 16:03:59 -0600 Subject: [PATCH] feat(ascii-map): add ascii-map tab (#137) It works like a charm! I'll be working on adjustable font size, but for now it's working great! --- prs-ascii-map.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++ prs-gui.lua | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 prs-ascii-map.lua diff --git a/prs-ascii-map.lua b/prs-ascii-map.lua new file mode 100644 index 0000000..4ff2988 --- /dev/null +++ b/prs-ascii-map.lua @@ -0,0 +1,52 @@ + +asciiMap = asciiMap or {} +asciiMap.mapContainer = asciiMap.mapContainer or Geyser.ScrollBox:new({ + x = 0, + y = 0, + width = "100%", + height = "100%", +}, GUI.tabwindow3.AsciiMapcenter) + +asciiMap.mapLabel = asciiMap.mapLabel or Geyser.Label:new({ + x = 0, + y = 0, + width = "100%", + height = "100%", +}, asciiMap.mapContainer) + +MAP_CMD_ID = 1 +GETTING_TOO_BIG_NUMBER = 1000000 +currentId = 0 + +function sendMapCommand() + currentId = currentId + 1 + if currentId > GETTING_TOO_BIG_NUMBER then + currentId = 1 + end + send("gmcp cmd " .. MAP_CMD_ID .. currentId .. " map", false) +end + +function mapEventHandler(event, args) + if (gmcp.Char.Output.id ~= MAP_CMD_ID .. currentId) then + return + end + + asciiMap.mapLabel:decho("
" .. ansi2decho(gmcp.Char.Output.output) .. "
") + asciiMap.mapLabel:setStyleSheet([[ + font-family: Bitstream Vera Sans Mono; + background-color: #111; + font-size: 10px; + ]]) + asciiMap.mapLabel:enableAutoAdjustSize(true, true) +end + +if map_handler_id then + killAnonymousEventHandler(map_handler_id) +end +map_handler_id = registerAnonymousEventHandler("gmcp.Char.Output", mapEventHandler) + +if send_command_handler_id then + killAnonymousEventHandler(send_command_handler_id) +end +send_command_handler_id = registerAnonymousEventHandler("gmcp.Char.room", sendMapCommand) + diff --git a/prs-gui.lua b/prs-gui.lua index bff7414..04a0be1 100644 --- a/prs-gui.lua +++ b/prs-gui.lua @@ -141,7 +141,7 @@ GUI.tabwindow3 = GUI.tabwindow3 or Adjustable.TabWindow:new({ inactiveTabFGColor = "#555555", color1 = "rgb(24,24,28)", color2 = "rgb(16,16,20)", - tabs = {"Map"} + tabs = {"Map", "AsciiMap"} }, GUI.right_top) GUI.tabwindow4 = GUI.tabwindow4 or Adjustable.TabWindow:new({