diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3274ec3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file diff --git a/.github/workflows/deploy-packager.yml b/.github/workflows/deploy-packager.yml new file mode 100644 index 0000000..a690f28 --- /dev/null +++ b/.github/workflows/deploy-packager.yml @@ -0,0 +1,21 @@ +name: Deploy via BigWigs Packager + +on: + push: + branches: + - main + tags: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + env: + CF_API_KEY: ${{ secrets.CF_API_KEY }} + WAGO_API_TOKEN: ${{ secrets.WAGO_API_TOKEN }} + GITHUB_OAUTH: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Package and Release + uses: BigWigsMods/packager@master diff --git a/.pkgmeta b/.pkgmeta new file mode 100644 index 0000000..f31f29c --- /dev/null +++ b/.pkgmeta @@ -0,0 +1 @@ +package-as: PerformanceMonitor diff --git a/PerformanceMonitor.lua b/PerformanceMonitor.lua new file mode 100644 index 0000000..77cae34 --- /dev/null +++ b/PerformanceMonitor.lua @@ -0,0 +1,174 @@ +local addonName, addon = ... +local L = addon.L +local ldb = LibStub:GetLibrary("LibDataBroker-1.1") +local ldbi = LibStub:GetLibrary('LibDBIcon-1.0') +local AceTimer = LibStub("AceTimer-3.0") +local timer = nil; + +local function showConfig() + InterfaceOptionsFrame_OpenToCategory(addonName) + InterfaceOptionsFrame_OpenToCategory(addonName) +end + +local function normal(text) + if not text then return "" end + return NORMAL_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + +local function red(text) + if not text then return "" end + return RED_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + +local function yellow(text) + if not text then return "" end + return YELLOW_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + +local function green(text) + if not text then return "" end + return GREEN_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + +local function highlight(text) + if not text then return "" end + return HIGHLIGHT_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + +local function muted(text) + if not text then return "" end + return DISABLED_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE; +end + + +-- Init & config panel +do + local eventFrame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) + eventFrame:SetScript("OnEvent", function(self, event, loadedAddon) + if loadedAddon ~= addonName then return end + self:UnregisterEvent("ADDON_LOADED") + + if type(PerformanceMonitorSettings) ~= "table" then PerformanceMonitorSettings = {currencies={},minimap={hide=false}} end + local sv = PerformanceMonitorSettings + if type(sv.minimap) ~= "table" then sv.minimap = {hide=false} end + if type(sv.showFPS) ~= "boolean" then sv.showFPS = true end + if type(sv.showLatency) ~= "boolean" then sv.showLatency = true end + if type(sv.showLatencyWorld) ~= "boolean" then sv.showLatencyWorld = false end + if type(sv.showMem) ~= "boolean" then sv.showMem = true end + addon.db = sv + + ldbi:Register(addonName, addon.dataobj, addon.db.minimap) + self:SetScript("OnEvent", nil) + end) + eventFrame:RegisterEvent("ADDON_LOADED") + addon.frame = eventFrame +end + +-- data text +do + local f = CreateFrame("frame") + local text = "..loading.." + local tooltip = "" + local dataobj = ldb:NewDataObject("PerformanceMonitor", { + type = "data source", + icon = "Interface\\AddOns\\PerformanceMonitor\\PerformanceMonitor", + text = text, + OnEnter = function(frame) + GameTooltip:SetOwner(frame, "ANCHOR_NONE") + GameTooltip:SetPoint("TOPLEFT", frame, "BOTTOMLEFT") + GameTooltip:ClearLines() + addon:updateTooltip(frame) + GameTooltip:Show() + end, + OnLeave = function() + GameTooltip:Hide() + end, + OnClick = function(self, button) + showConfig() + end, + }) + + addon.dataobj = dataobj + + local function fmtLabel(text) + if not text then return "" end + text = normal(text); + return " "..normal(text)..": "; + end + + local function updateText() + local fps = GetFramerate(); + local _, _, latencyHome, latencyWorld = GetNetStats(); + local memory, gcThreshold = gcinfo(); + + local function getFPS() + local function color(v) + if (v >= 60) then + return green(format('%2.1f', v)) + elseif (v >= 30) then + return yellow(format('%2.1f', v)) + end + return red(format('%2.1f', v)) + end + return fmtLabel(L.labelFPS)..color(fps) + end + + local function getLatency() + local t = fmtLabel(L.labelLatency) + local function color(v) + if (v <= 300) then + return green(format('%d', v)..'ms') + elseif (v <= 600) then + return yellow(format('%d', v)..'ms') + end + return red(format('%d', v)..'ms') + end + if (addon.db.showLatency) then + t = t..color(latencyHome) + end + if (addon.db.showLatency and addon.db.showLatencyWorld) then + t = t.." " + end + if (addon.db.showLatencyWorld) then + t = t..color(latencyWorld) + end + return t + end + local function getMemoryUsage() + local function color(v) + -- @todo thresholds? + return highlight(format('%.3f', v / 1024).." MB") + end + return fmtLabel(L.labelMem)..color(memory) + end + + + local text = ""; + if (addon.db.showFPS) then text = text..getFPS() end + if (addon.db.showLatency or addon.db.showLatencyWorld) then + text = text..getLatency() + end + if (addon.db.showMem) then text = text..getMemoryUsage() end + + dataobj.text = text; + end + + function addon:updateTooltip() + + GameTooltip:AddLine(L["PerformanceMonitor"].."\n") + + end + + function addon:setDB(key, value) + addon.db[key] = value + updateText() + end + + f:RegisterEvent("PLAYER_ENTERING_WORLD"); + f:SetScript("OnEvent", function(self, event) + if not timer then + -- @todo should this only run when the datatext is displayed? + timer = AceTimer.ScheduleRepeatingTimer("PerformanceMonitor", updateText, 1.5 ) + end + end) +end diff --git a/PerformanceMonitor.png b/PerformanceMonitor.png new file mode 100644 index 0000000..08dc5d1 Binary files /dev/null and b/PerformanceMonitor.png differ diff --git a/PerformanceMonitor.tga b/PerformanceMonitor.tga new file mode 100644 index 0000000..215408d Binary files /dev/null and b/PerformanceMonitor.tga differ diff --git a/PerformanceMonitor.toc b/PerformanceMonitor.toc new file mode 100644 index 0000000..cf2677e --- /dev/null +++ b/PerformanceMonitor.toc @@ -0,0 +1,17 @@ +## Interface: 90200 +## Title: PerformanceMonitor +## Notes: A customizable data broker for displaying player currencies +## Author: solocommand +## SavedVariables: PerformanceMonitorSettings +## Version: @project-version@ +## X-ReleaseDate: @project-date-iso@ +## X-License: MIT +## X-Wago-ID: RqGZzoGd +## OptionalDeps: Ace3 + +embeds.xml + +i18n\enUS.lua + +PerformanceMonitor.lua +config.lua diff --git a/README.md b/README.md index a9ab553..f238941 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ -# PerformanceMonitor +PerformanceMonitor +=========== +![Project logo, red/green gauge](PerformanceMonitor.png) + A World of Warcraft LDB addon to display your current FPS, latency, and memory utilization diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..e5cb6e2 --- /dev/null +++ b/config.lua @@ -0,0 +1,64 @@ +local addonName, addon = ... +local L = addon.L +local ldbi = LibStub('LibDBIcon-1.0', true) + +local function build() + local t = { + name = "PerformanceMonitor", + handler = PerformanceMonitor, + type = 'group', + args = { + showFPS = { + type = 'toggle', + order = 1, + get = function(info) return addon.db[info[#info]] end, + set = function(info, value) return addon:setDB(info[#info], value) end, + name = L.showFPS, + desc = L.showFPSDescription, + }, + showLatency = { + type = 'toggle', + order = 1, + get = function(info) return addon.db[info[#info]] end, + set = function(info, value) return addon:setDB(info[#info], value) end, + name = L.showLatency, + desc = L.showLatencyDescription, + }, + showLatencyWorld = { + type = 'toggle', + order = 1, + get = function(info) return addon.db[info[#info]] end, + set = function(info, value) return addon:setDB(info[#info], value) end, + name = L.showLatencyWorld, + desc = L.showLatencyWorldDescription, + }, + showMem = { + type = 'toggle', + order = 1, + get = function(info) return addon.db[info[#info]] end, + set = function(info, value) return addon:setDB(info[#info], value) end, + name = L.showMem, + desc = L.showMemDescription, + }, + showMinimapIcon = { + type = 'toggle', + name = L.showMinimapIcon, + desc = L.showMinimapIconDescription, + order = 0, + get = function(info) return not addon.db.minimap.hide end, + set = function(info, value) + local config = addon.db.minimap + config.hide = not value + addon:setDB("minimap", config) + ldbi:Refresh(addonName) + end, + }, + } + } + + -- return our new table + return t +end + +LibStub("AceConfig-3.0"):RegisterOptionsTable("PerformanceMonitor", build, nil) +addon.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(addonName, "PerformanceMonitor") diff --git a/embeds.xml b/embeds.xml new file mode 100644 index 0000000..37c8d4c --- /dev/null +++ b/embeds.xml @@ -0,0 +1,13 @@ + +