diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/ForeverScale/ForeverScale.lua b/ForeverScale/ForeverScale.lua index c95cebd..76a7573 100644 --- a/ForeverScale/ForeverScale.lua +++ b/ForeverScale/ForeverScale.lua @@ -1,14 +1,28 @@ -- ForeverScale: re-applies a fixed UIParent scale on every login/reload, -- so values below Blizzard's 0.64 slider floor stick. -- /fscale 0.5333 set a scale (0.30 - 1.50), saved account-wide --- /fscale pixel pixel-perfect: 768 / your vertical resolution +-- /fscale pixel pixel-perfect: 768 / your vertical resolution, worked out +-- again whenever the resolution changes. Not limited to +-- 0.30 - 1.50, so on 5K/6K screens it goes below 0.30. -- /fscale reset stop overriding (then /reload) local ADDON = ... local f = CreateFrame("Frame") +-- the scale to enforce, or nil if there is no override +local function target() + local db = ForeverScaleDB + if not db then return end + if db.pixel then + local _, h = GetPhysicalScreenSize() + if h and h > 0 then return 768 / h end + return + end + return db.scale +end + local function apply() - local s = ForeverScaleDB and ForeverScaleDB.scale + local s = target() if not s then return end if InCombatLockdown() then -- UIParent has protected children; wait until combat ends @@ -46,12 +60,11 @@ SlashCmdList.FOREVERSCALE = function(msg) msg = strtrim(msg or ""):lower() if msg == "reset" then - ForeverScaleDB.scale = nil + ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, nil print("ForeverScale: override cleared. /reload to return to Blizzard's scale.") return elseif msg == "pixel" then - local _, h = GetPhysicalScreenSize() - ForeverScaleDB.scale = 768 / h + ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, true else local v = tonumber(msg) if not v or v < 0.3 or v > 1.5 then @@ -60,10 +73,11 @@ SlashCmdList.FOREVERSCALE = function(msg) UIParent:GetScale())) return end - ForeverScaleDB.scale = v + ForeverScaleDB.scale, ForeverScaleDB.pixel = v, nil end apply() - print(string.format("ForeverScale: scale set to %.4f%s", ForeverScaleDB.scale, + print(string.format("ForeverScale: scale set to %.4f%s%s", target() or UIParent:GetScale(), + ForeverScaleDB.pixel and " (pixel, follows your resolution)" or "", InCombatLockdown() and " (applies after combat)" or "")) end diff --git a/Goldbeutel/Goldbeutel.lua b/Goldbeutel/Goldbeutel.lua index 875e03e..1e7dec4 100644 --- a/Goldbeutel/Goldbeutel.lua +++ b/Goldbeutel/Goldbeutel.lua @@ -48,9 +48,22 @@ local function classColored(name, class) return name end +-- string.lower kennt nur A-Z. Fuer Namen wie "Ärger" auch À-Þ (UTF-8 C3 80-9E, +-- ausser ×) in Kleinbuchstaben umwandeln. +local function lower(s) + return (s:lower():gsub("\195([\128-\158])", function(c) + if c ~= "\151" then return "\195" .. string.char(c:byte() + 32) end + end)) +end + +-- Felder aktualisieren statt den Eintrag zu ersetzen, damit der +-- Sitzungsstart (session) erhalten bleibt local function record() + local chars = db.chars[realm] + local me = chars[player] or {} + chars[player] = me local _, class = UnitClass("player") - db.chars[realm][player] = { money = GetMoney(), class = class } + me.money, me.class = GetMoney(), class end local function update() @@ -171,7 +184,8 @@ ev:RegisterEvent("ADDON_LOADED") ev:RegisterEvent("PLAYER_LOGIN") ev:RegisterEvent("PLAYER_MONEY") ev:RegisterEvent("PLAYER_LOGOUT") -ev:SetScript("OnEvent", function(self, event, arg1) +ev:RegisterEvent("PLAYER_ENTERING_WORLD") +ev:SetScript("OnEvent", function(self, event, arg1, arg2) if event == "ADDON_LOADED" then if arg1 ~= ADDON then return end GoldbeutelDB = GoldbeutelDB or {} @@ -184,6 +198,16 @@ ev:SetScript("OnEvent", function(self, event, arg1) sessionStart = GetMoney() createFrame() update() + elseif event == "PLAYER_ENTERING_WORLD" then + -- PLAYER_LOGIN kommt auch bei /reload. Erst hier steht fest, ob es nur ein + -- Reload war (arg2 = isReloadingUi); dann zaehlt die Sitzung weiter. + self:UnregisterEvent("PLAYER_ENTERING_WORLD") + local me = db.chars[realm][player] + if arg2 and me.session then + sessionStart = me.session + else + me.session = sessionStart + end elseif event == "PLAYER_MONEY" then if frame then update() end elseif event == "PLAYER_LOGOUT" then @@ -209,9 +233,9 @@ SlashCmdList.GOLDBEUTEL = function(input) frame:Show() say("Position zurückgesetzt.") elseif cmd == "forget" and arg ~= "" then - local chars = db.chars[realm] + local chars, want = db.chars[realm], lower(arg) for name in pairs(chars) do - if name:lower() == arg:lower() and name ~= player then + if lower(name) == want and name ~= player then chars[name] = nil say(name .. " entfernt.") return diff --git a/Leistenabstand/Leistenabstand.lua b/Leistenabstand/Leistenabstand.lua index 5a46a69..bd66b96 100644 --- a/Leistenabstand/Leistenabstand.lua +++ b/Leistenabstand/Leistenabstand.lua @@ -22,7 +22,8 @@ local BARS = { { key = "6", name = "Aktionsleiste 6", frames = { "MultiBar5" }, prefix = "MultiBar5Button", n = 12 }, { key = "7", name = "Aktionsleiste 7", frames = { "MultiBar6" }, prefix = "MultiBar6Button", n = 12 }, { key = "8", name = "Aktionsleiste 8", frames = { "MultiBar7" }, prefix = "MultiBar7Button", n = 12 }, - { key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10 }, + -- Haltungsbuttons sind nie "leer": ausgeblendet heisst, die Haltung gibt es nicht + { key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10, onlyShown = true }, { key = "pet", name = "Begleiterleiste", frames = { "PetActionBar" }, prefix = "PetActionButton", n = 10 }, } local BY_KEY = {} @@ -58,6 +59,33 @@ local function getButtons(def) return list end +-- Die Buttons, die Blizzard ins Raster legt. Dazu gehoeren auch leere Slots, die +-- bei ausgeschaltetem "Immer Buttons anzeigen" ausgeblendet sind: Blizzard laesst +-- ihre Luecke stehen, und wenn sie wieder erscheinen (Zauber hineingezogen, Raster +-- beim Ziehen, Leistenwechsel), muessen sie schon am richtigen Platz sein. Buttons +-- jenseits von "Anzahl Symbole" gehoeren nicht dazu. +local function gridButtons(def) + local all = getButtons(def) + local n + if not def.onlyShown then + n = def.bar.numShowingButtons + if type(n) ~= "number" then + -- Feld fehlt: bis zum letzten sichtbaren Button, Luecken dazwischen zaehlen mit + n = 0 + for i, b in ipairs(all) do + if b:IsShown() then n = i end + end + end + end + local list = {} + for i, b in ipairs(all) do + local inGrid + if n then inGrid = i <= n else inGrid = b:IsShown() end + if inGrid and b:GetCenter() then list[#list + 1] = b end + end + return list +end + -- sortiert die Werte und fasst nahe beieinanderliegende zu einer Spalte/Reihe zusammen local function clusters(values, tol) table.sort(values) @@ -87,9 +115,9 @@ end -- auf der Seite des ersten Buttons gemessen (den verschiebt das Addon nie) und -- auf der anderen Seite gespiegelt. So bleibt das Ergebnis stabil, egal ob der -- Rahmen vorher Blizzards Groesse hatte oder schon verkleinert war. -local function fitBar(bar, anchor, shown) +local function fitBar(bar, anchor, grid) local l, r, t, b - for _, btn in ipairs(shown) do + for _, btn in ipairs(grid) do local L, R, T, B = rectIn(btn, bar) if L then l = l and math.min(l, L) or L @@ -109,19 +137,16 @@ end local function compress(def, pad) local bar = def.bar - local shown = {} - for _, b in ipairs(getButtons(def)) do - if b:IsShown() and b:GetCenter() then shown[#shown + 1] = b end - end - if #shown < 2 then return end + local grid = gridButtons(def) + if #grid < 2 then return end -- Der erste Button bleibt, wo Blizzard ihn hingesetzt hat; alle anderen -- werden relativ zu ihm angeordnet. Falls er selbst an einem anderen -- Button haengt, lieber nichts anfassen (sonst Ankerschleife). - local anchor = shown[1] + local anchor = grid[1] for i = 1, anchor:GetNumPoints() do local _, rel = anchor:GetPoint(i) - for _, b in ipairs(shown) do + for _, b in ipairs(grid) do if rel == b then return end end end @@ -131,7 +156,7 @@ local function compress(def, pad) local s = anchor:GetEffectiveScale() local tolX, tolY = w * s / 2, h * s / 2 local px, py, xs, ys = {}, {}, {}, {} - for i, b in ipairs(shown) do + for i, b in ipairs(grid) do local x, y = b:GetCenter() local es = b:GetEffectiveScale() px[i], py[i] = x * es, -y * es -- y negiert: Reihe 1 = oben @@ -140,15 +165,15 @@ local function compress(def, pad) local cols, rows = clusters(xs, tolX), clusters(ys, tolY) local c0, r0 = rank(cols, px[1], tolX), rank(rows, py[1], tolY) - for i = 2, #shown do - local b = shown[i] + for i = 2, #grid do + local b = grid[i] local dc = rank(cols, px[i], tolX) - c0 local dr = rank(rows, py[i], tolY) - r0 b:ClearAllPoints() b:SetPoint("CENTER", anchor, "CENTER", dc * (w + pad), -dr * (h + pad)) end - if db.resize then fitBar(bar, anchor, shown) end + if db.resize then fitBar(bar, anchor, grid) end end local function apply(def) diff --git a/README.md b/README.md index ce1e09e..5e35136 100644 --- a/README.md +++ b/README.md @@ -138,14 +138,28 @@ ForeverScale.lua -- ForeverScale: re-applies a fixed UIParent scale on every login/reload, -- so values below Blizzard's 0.64 slider floor stick. -- /fscale 0.5333 set a scale (0.30 - 1.50), saved account-wide --- /fscale pixel pixel-perfect: 768 / your vertical resolution +-- /fscale pixel pixel-perfect: 768 / your vertical resolution, worked out +-- again whenever the resolution changes. Not limited to +-- 0.30 - 1.50, so on 5K/6K screens it goes below 0.30. -- /fscale reset stop overriding (then /reload) local ADDON = ... local f = CreateFrame("Frame") +-- the scale to enforce, or nil if there is no override +local function target() + local db = ForeverScaleDB + if not db then return end + if db.pixel then + local _, h = GetPhysicalScreenSize() + if h and h > 0 then return 768 / h end + return + end + return db.scale +end + local function apply() - local s = ForeverScaleDB and ForeverScaleDB.scale + local s = target() if not s then return end if InCombatLockdown() then -- UIParent has protected children; wait until combat ends @@ -183,12 +197,11 @@ SlashCmdList.FOREVERSCALE = function(msg) msg = strtrim(msg or ""):lower() if msg == "reset" then - ForeverScaleDB.scale = nil + ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, nil print("ForeverScale: override cleared. /reload to return to Blizzard's scale.") return elseif msg == "pixel" then - local _, h = GetPhysicalScreenSize() - ForeverScaleDB.scale = 768 / h + ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, true else local v = tonumber(msg) if not v or v < 0.3 or v > 1.5 then @@ -197,11 +210,12 @@ SlashCmdList.FOREVERSCALE = function(msg) UIParent:GetScale())) return end - ForeverScaleDB.scale = v + ForeverScaleDB.scale, ForeverScaleDB.pixel = v, nil end apply() - print(string.format("ForeverScale: scale set to %.4f%s", ForeverScaleDB.scale, + print(string.format("ForeverScale: scale set to %.4f%s%s", target() or UIParent:GetScale(), + ForeverScaleDB.pixel and " (pixel, follows your resolution)" or "", InCombatLockdown() and " (applies after combat)" or "")) end ``` @@ -271,9 +285,22 @@ local function classColored(name, class) return name end +-- string.lower kennt nur A-Z. Fuer Namen wie "Ärger" auch À-Þ (UTF-8 C3 80-9E, +-- ausser ×) in Kleinbuchstaben umwandeln. +local function lower(s) + return (s:lower():gsub("\195([\128-\158])", function(c) + if c ~= "\151" then return "\195" .. string.char(c:byte() + 32) end + end)) +end + +-- Felder aktualisieren statt den Eintrag zu ersetzen, damit der +-- Sitzungsstart (session) erhalten bleibt local function record() + local chars = db.chars[realm] + local me = chars[player] or {} + chars[player] = me local _, class = UnitClass("player") - db.chars[realm][player] = { money = GetMoney(), class = class } + me.money, me.class = GetMoney(), class end local function update() @@ -394,7 +421,8 @@ ev:RegisterEvent("ADDON_LOADED") ev:RegisterEvent("PLAYER_LOGIN") ev:RegisterEvent("PLAYER_MONEY") ev:RegisterEvent("PLAYER_LOGOUT") -ev:SetScript("OnEvent", function(self, event, arg1) +ev:RegisterEvent("PLAYER_ENTERING_WORLD") +ev:SetScript("OnEvent", function(self, event, arg1, arg2) if event == "ADDON_LOADED" then if arg1 ~= ADDON then return end GoldbeutelDB = GoldbeutelDB or {} @@ -407,6 +435,16 @@ ev:SetScript("OnEvent", function(self, event, arg1) sessionStart = GetMoney() createFrame() update() + elseif event == "PLAYER_ENTERING_WORLD" then + -- PLAYER_LOGIN kommt auch bei /reload. Erst hier steht fest, ob es nur ein + -- Reload war (arg2 = isReloadingUi); dann zaehlt die Sitzung weiter. + self:UnregisterEvent("PLAYER_ENTERING_WORLD") + local me = db.chars[realm][player] + if arg2 and me.session then + sessionStart = me.session + else + me.session = sessionStart + end elseif event == "PLAYER_MONEY" then if frame then update() end elseif event == "PLAYER_LOGOUT" then @@ -432,9 +470,9 @@ SlashCmdList.GOLDBEUTEL = function(input) frame:Show() say("Position zurückgesetzt.") elseif cmd == "forget" and arg ~= "" then - local chars = db.chars[realm] + local chars, want = db.chars[realm], lower(arg) for name in pairs(chars) do - if name:lower() == arg:lower() and name ~= player then + if lower(name) == want and name ~= player then chars[name] = nil say(name .. " entfernt.") return @@ -486,7 +524,8 @@ local BARS = { { key = "6", name = "Aktionsleiste 6", frames = { "MultiBar5" }, prefix = "MultiBar5Button", n = 12 }, { key = "7", name = "Aktionsleiste 7", frames = { "MultiBar6" }, prefix = "MultiBar6Button", n = 12 }, { key = "8", name = "Aktionsleiste 8", frames = { "MultiBar7" }, prefix = "MultiBar7Button", n = 12 }, - { key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10 }, + -- Haltungsbuttons sind nie "leer": ausgeblendet heisst, die Haltung gibt es nicht + { key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10, onlyShown = true }, { key = "pet", name = "Begleiterleiste", frames = { "PetActionBar" }, prefix = "PetActionButton", n = 10 }, } local BY_KEY = {} @@ -522,6 +561,33 @@ local function getButtons(def) return list end +-- Die Buttons, die Blizzard ins Raster legt. Dazu gehoeren auch leere Slots, die +-- bei ausgeschaltetem "Immer Buttons anzeigen" ausgeblendet sind: Blizzard laesst +-- ihre Luecke stehen, und wenn sie wieder erscheinen (Zauber hineingezogen, Raster +-- beim Ziehen, Leistenwechsel), muessen sie schon am richtigen Platz sein. Buttons +-- jenseits von "Anzahl Symbole" gehoeren nicht dazu. +local function gridButtons(def) + local all = getButtons(def) + local n + if not def.onlyShown then + n = def.bar.numShowingButtons + if type(n) ~= "number" then + -- Feld fehlt: bis zum letzten sichtbaren Button, Luecken dazwischen zaehlen mit + n = 0 + for i, b in ipairs(all) do + if b:IsShown() then n = i end + end + end + end + local list = {} + for i, b in ipairs(all) do + local inGrid + if n then inGrid = i <= n else inGrid = b:IsShown() end + if inGrid and b:GetCenter() then list[#list + 1] = b end + end + return list +end + -- sortiert die Werte und fasst nahe beieinanderliegende zu einer Spalte/Reihe zusammen local function clusters(values, tol) table.sort(values) @@ -551,9 +617,9 @@ end -- auf der Seite des ersten Buttons gemessen (den verschiebt das Addon nie) und -- auf der anderen Seite gespiegelt. So bleibt das Ergebnis stabil, egal ob der -- Rahmen vorher Blizzards Groesse hatte oder schon verkleinert war. -local function fitBar(bar, anchor, shown) +local function fitBar(bar, anchor, grid) local l, r, t, b - for _, btn in ipairs(shown) do + for _, btn in ipairs(grid) do local L, R, T, B = rectIn(btn, bar) if L then l = l and math.min(l, L) or L @@ -573,19 +639,16 @@ end local function compress(def, pad) local bar = def.bar - local shown = {} - for _, b in ipairs(getButtons(def)) do - if b:IsShown() and b:GetCenter() then shown[#shown + 1] = b end - end - if #shown < 2 then return end + local grid = gridButtons(def) + if #grid < 2 then return end -- Der erste Button bleibt, wo Blizzard ihn hingesetzt hat; alle anderen -- werden relativ zu ihm angeordnet. Falls er selbst an einem anderen -- Button haengt, lieber nichts anfassen (sonst Ankerschleife). - local anchor = shown[1] + local anchor = grid[1] for i = 1, anchor:GetNumPoints() do local _, rel = anchor:GetPoint(i) - for _, b in ipairs(shown) do + for _, b in ipairs(grid) do if rel == b then return end end end @@ -595,7 +658,7 @@ local function compress(def, pad) local s = anchor:GetEffectiveScale() local tolX, tolY = w * s / 2, h * s / 2 local px, py, xs, ys = {}, {}, {}, {} - for i, b in ipairs(shown) do + for i, b in ipairs(grid) do local x, y = b:GetCenter() local es = b:GetEffectiveScale() px[i], py[i] = x * es, -y * es -- y negiert: Reihe 1 = oben @@ -604,15 +667,15 @@ local function compress(def, pad) local cols, rows = clusters(xs, tolX), clusters(ys, tolY) local c0, r0 = rank(cols, px[1], tolX), rank(rows, py[1], tolY) - for i = 2, #shown do - local b = shown[i] + for i = 2, #grid do + local b = grid[i] local dc = rank(cols, px[i], tolX) - c0 local dr = rank(rows, py[i], tolY) - r0 b:ClearAllPoints() b:SetPoint("CENTER", anchor, "CENTER", dc * (w + pad), -dr * (h + pad)) end - if db.resize then fitBar(bar, anchor, shown) end + if db.resize then fitBar(bar, anchor, grid) end end local function apply(def) diff --git a/tests/test_goldbeutel_foreverscale.lua b/tests/test_goldbeutel_foreverscale.lua new file mode 100644 index 0000000..4bcdb6e --- /dev/null +++ b/tests/test_goldbeutel_foreverscale.lua @@ -0,0 +1,114 @@ +-- Aufruf aus dem Repo-Wurzelverzeichnis oder von ueberall: luajit tests/test_goldbeutel_foreverscale.lua +-- Testet das Addon in einer nachgebauten WoW-Umgebung (Mock), nicht im echten Client. +local ROOT = ((arg and arg[0] or ""):match("^(.*/)") or "./") .. "../" +local out = print +local fails = 0 +local function check(name, cond) out((cond and " OK " or " FEHLER ") .. name); if not cond then fails = fails + 1 end end +local noop = function() end +local function obj(t) return setmetatable(t or {}, {__index = function() return noop end}) end + +---------------------------------------------------------------- Goldbeutel +local money, ev, lines +local function startGold(name, db) + GoldbeutelDB = db + print = noop + SlashCmdList = {} + strtrim = function(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end + GetRealmName = function() return "Blackmoore" end + UnitName = function() return name end + UnitClass = function() return "Magier", "MAGE" end + GetMoney = function() return money end + UIParent = obj{ GetHeight = function() return 800 end } + lines = {} + GameTooltip = obj{ AddDoubleLine = function(_, l, r) lines[l] = r end, IsOwned = function() return false end } + local frames = {} + CreateFrame = function() + local f; f = obj{ scripts = {}, shown = true, + SetScript = function(self, n, fn) self.scripts[n] = fn end, + GetCenter = function() return 500, 300 end, + SetShown = function(self, v) self.shown = v end, + IsShown = function(self) return self.shown end, + CreateFontString = function() return obj{ GetStringWidth = function() return 80 end, GetStringHeight = function() return 12 end } end } + frames[#frames + 1] = f + return f + end + assert(loadfile(ROOT .. "Goldbeutel/Goldbeutel.lua"))("Goldbeutel") + ev = frames[1] + ev.scripts.OnEvent(ev, "ADDON_LOADED", "Goldbeutel") + ev.scripts.OnEvent(ev, "PLAYER_LOGIN") + return frames[2] -- GoldbeutelFrame +end +local function sessionLine(frame) lines = {}; frame.scripts.OnEnter(frame); return lines["Diese Sitzung:"] end + +out("Goldbeutel: Sitzung ueber /reload") +money = 1000000 -- 100 g +local fr = startGold("Testmagier", nil) +ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD", true, false) -- echter Login +money = 1500000; ev.scripts.OnEvent(ev, "PLAYER_MONEY") +check("+50 g nach Login", sessionLine(fr):match("^%+50|TInterface\\MoneyFrame\\UI%-GoldIcon") ~= nil) +local saved = GoldbeutelDB +ev.scripts.OnEvent(ev, "PLAYER_LOGOUT") +fr = startGold("Testmagier", saved) -- /reload +ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD", false, true) +check("+50 g bleibt nach /reload", sessionLine(fr):match("^%+50|T") ~= nil) +money = 1400000; ev.scripts.OnEvent(ev, "PLAYER_MONEY") +check("+40 g nach Ausgabe", sessionLine(fr):match("^%+40|T") ~= nil) +ev.scripts.OnEvent(ev, "PLAYER_LOGOUT") +fr = startGold("Testmagier", GoldbeutelDB) -- neuer Login +ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD", true, false) +check("Neuer Login beginnt bei 0", sessionLine(fr):match("^0|T") ~= nil) +check("Gold und Klasse weiter gespeichert", + GoldbeutelDB.chars.Blackmoore.Testmagier.money == 1400000 and GoldbeutelDB.chars.Blackmoore.Testmagier.class == "MAGE") + +out("Goldbeutel: /gold forget mit Umlauten und Akzenten") +local chars = GoldbeutelDB.chars.Blackmoore +chars["Ärger"] = { money = 1 }; chars["Élodie"] = { money = 2 }; chars["Öx×y"] = { money = 3 } +SlashCmdList.GOLDBEUTEL("forget ärger"); check("ärger -> Ärger entfernt", chars["Ärger"] == nil) +SlashCmdList.GOLDBEUTEL("forget ÉLODIE"); check("ÉLODIE -> Élodie entfernt", chars["Élodie"] == nil) +SlashCmdList.GOLDBEUTEL("forget öx×y"); check("öx×y -> Öx×y entfernt (× unveraendert)", chars["Öx×y"] == nil) +SlashCmdList.GOLDBEUTEL("forget testmagier"); check("Eigener Charakter bleibt", chars.Testmagier ~= nil) + +---------------------------------------------------------------- ForeverScale +local scale, h, combat, timers, f +local function startScale(db) + ForeverScaleDB = db + print = noop; SlashCmdList = {} + strtrim = function(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end + scale, timers, combat = 1, {}, false + UIParent = obj{ GetScale = function() return scale end, SetScale = function(_, s) scale = s end } + GetPhysicalScreenSize = function() return h * 16 / 9, h end + InCombatLockdown = function() return combat end + C_Timer = { After = function(_, fn) timers[#timers + 1] = fn end } + CreateFrame = function() + f = obj{ scripts = {}, SetScript = function(self, n, fn) self.scripts[n] = fn end } + return f + end + assert(loadfile(ROOT .. "ForeverScale/ForeverScale.lua"))("ForeverScale") + f.scripts.OnEvent(f, "ADDON_LOADED", "ForeverScale") +end +local function fire(e) f.scripts.OnEvent(f, e); while #timers > 0 do table.remove(timers, 1)() end end +local function near(a, b) return math.abs(a - b) < 0.0001 end + +out("ForeverScale") +h = 1440; startScale(nil); fire("PLAYER_LOGIN") +SlashCmdList.FOREVERSCALE("pixel") +check("pixel bei 1440p = 0,5333", near(scale, 768/1440)) +h = 2160; fire("DISPLAY_SIZE_CHANGED") +check("Aufloesung 4K -> neu berechnet 0,3556", near(scale, 768/2160)) +local saved = ForeverScaleDB +h = 2880; startScale(saved); fire("PLAYER_LOGIN") +check("pixel-Modus ueberlebt Relog (5K -> 0,2667)", near(scale, 768/2880)) +SlashCmdList.FOREVERSCALE("0.7"); h = 1440; fire("DISPLAY_SIZE_CHANGED") +check("Fester Wert 0,7 bleibt bei Aufloesungswechsel", near(scale, 0.7)) +combat = true; SlashCmdList.FOREVERSCALE("pixel") +check("Im Kampf nichts geaendert", near(scale, 0.7)) +combat = false; fire("PLAYER_REGEN_ENABLED") +check("Nach dem Kampf angewendet", near(scale, 768/1440)) +SlashCmdList.FOREVERSCALE("reset"); scale = 1; fire("UI_SCALE_CHANGED") +check("reset: kein Override mehr", near(scale, 1)) +startScale({ scale = 0.5333 }); fire("PLAYER_LOGIN") +check("Alter gespeicherter Wert (ohne pixel-Flag) gilt weiter", near(scale, 0.5333)) + +out(fails == 0 and "\nAlle Tests bestanden." or ("\n" .. fails .. " Test(s) fehlgeschlagen.")) + +os.exit(fails == 0 and 0 or 1) diff --git a/tests/test_leistenabstand.lua b/tests/test_leistenabstand.lua new file mode 100644 index 0000000..804f02c --- /dev/null +++ b/tests/test_leistenabstand.lua @@ -0,0 +1,134 @@ +-- Aufruf aus dem Repo-Wurzelverzeichnis oder von ueberall: luajit tests/test_leistenabstand.lua +-- Testet das Addon in einer nachgebauten WoW-Umgebung (Mock), nicht im echten Client. +local ROOT = ((arg and arg[0] or ""):match("^(.*/)") or "./") .. "../" +-- Mock: TOPLEFT/CENTER-Anker, Skalierung 1, y nach oben positiv +local out = print +local Frame = {}; Frame.__index = Frame +local function new(w, h) return setmetatable({w=w or 0,h=h or 0,pts={},shown=true,scripts={}}, Frame) end +function Frame:SetSize(w,h) self.w,self.h=w,h end +function Frame:GetSize() return self.w,self.h end +function Frame:GetEffectiveScale() return 1 end +function Frame:IsShown() return self.shown end +function Frame:Show() self.shown=true end +function Frame:Hide() self.shown=false end +function Frame:ClearAllPoints() self.pts={} end +function Frame:SetPoint(p, rel, rp, x, y) + local r = rel; while r do assert(r ~= self, "Ankerschleife!"); r = r.pts[1] and r.pts[1][2] end + self.pts={{p,rel,rp,x or 0,y or 0}} +end +function Frame:GetNumPoints() return #self.pts end +function Frame:GetPoint(i) local q=self.pts[i]; return q[1],q[2],q[3],q[4],q[5] end +local function off(p,w,h) if p=="CENTER" then return w/2,-h/2 end return 0,0 end +function Frame:TopLeft() + if not self.pts[1] then return self.x or 0, self.y or 0 end + local p,rel,rp,x,y = unpack(self.pts[1]) + local rx,ry = rel:TopLeft(); local ax,ay = off(rp,rel.w,rel.h); local sx,sy = off(p,self.w,self.h) + return rx+ax+x-sx, ry+ay+y-sy +end +function Frame:GetLeft() local x=self:TopLeft(); return x end +function Frame:GetRight() local x=self:TopLeft(); return x+self.w end +function Frame:GetTop() local _,y=self:TopLeft(); return y end +function Frame:GetBottom() local _,y=self:TopLeft(); return y-self.h end +function Frame:GetCenter() local x,y=self:TopLeft(); return x+self.w/2, y-self.h/2 end +function Frame:RegisterEvent() end +function Frame:UnregisterEvent() end +function Frame:SetScript(n,f) self.scripts[n]=f end +function Frame:HookScript() end +unpack = unpack or table.unpack + +local W, BPAD = 45, 2 +local timers, ev, btn, bar +local function setup(opts) + timers = {} + for _, n in ipairs({"MainActionBar","MainMenuBar","MultiBarBottomLeft","MultiBarBottomRight","MultiBarRight", + "MultiBarLeft","MultiBar5","MultiBar6","MultiBar7","StanceBar","PetActionBar"}) do _G[n] = nil end + LeistenabstandDB = opts.db + CreateFrame = function() ev = new(); return ev end + C_Timer = {After=function(_,f) timers[#timers+1]=f end} + InCombatLockdown = function() return false end + hooksecurefunc = function() end + strtrim = function(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end + SlashCmdList = {} + print = function() end + UIParent = new(1000,800); UIParent.x, UIParent.y = 0, 800 + local cols = opts.cols or 12 + bar = new(cols*W+(cols-1)*BPAD, W); bar:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 100, -600) + bar.actionButtons = {}; bar.numShowingButtons = opts.numShowing + _G[opts.barName or "MultiBarBottomRight"] = bar + btn = bar.actionButtons + local count = opts.count or 12 + for i=1,count do + local b = new(W,W); local c, r = (i-1)%cols, math.floor((i-1)/cols) + b:SetPoint("TOPLEFT", bar, "TOPLEFT", c*(W+BPAD), -r*(W+BPAD)) + btn[i] = b + end + for _, i in ipairs(opts.hidden or {}) do btn[i]:Hide() end + assert(loadfile(ROOT .. "Leistenabstand/Leistenabstand.lua"))("Leistenabstand") + ev.scripts.OnEvent(ev, "ADDON_LOADED", "Leistenabstand") + ev.scripts.OnEvent(ev, "PLAYER_LOGIN") + while #timers > 0 do table.remove(timers,1)() end +end +local function run() while #timers > 0 do table.remove(timers,1)() end end +local function pos(i) return btn[i]:GetLeft() - bar:GetLeft(), bar:GetTop() - btn[i]:GetTop() end +local fails = 0 +local function check(name, cond) out((cond and " OK " or " FEHLER ") .. name); if not cond then fails = fails + 1 end end +local function near(a, b) return math.abs(a - b) < 0.01 end +local function rowOK(from, to, pad, row) + for i = from, to do + local x, y = pos(i) + if not near(x, (i-from)*(W+pad)) or not near(y, (row or 0)*(W+pad)) then return false end + end + return true +end +local function overlaps() + for i = 1, #btn do for j = i+1, #btn do + if btn[i]:IsShown() and btn[j]:IsShown() then + local xi, yi = pos(i); local xj, yj = pos(j) + if math.abs(xi-xj) < W - 0.01 and math.abs(yi-yj) < W - 0.01 then return true end + end + end end + return false +end + +out("A: Slot 3 leer und ausgeblendet, numShowingButtons = 12") +setup{numShowing = 12, hidden = {3}} +check("Luecke bleibt: Button 1-12 im Raster mit Abstand 0", rowOK(1, 12, 0)) +btn[3]:Show() +check("Button 3 erscheint ohne Ueberlappung", not overlaps()) + +out("B: Anzahl Symbole = 8, Buttons 9-12 ausgeblendet") +setup{numShowing = 8, hidden = {9,10,11,12}} +local x9 = pos(9) +check("Button 1-8 zusammengeschoben", rowOK(1, 8, 0)) +check("Button 9-12 nicht angefasst (Blizzard-Position)", near(x9, 8*(W+BPAD)) and btn[9].pts[1][2] == bar) + +out("C: Feld numShowingButtons fehlt, Slot 3 und 12 leer") +setup{numShowing = nil, hidden = {3, 12}} +check("Button 1-11 im Raster (Luecke 3 bleibt)", rowOK(1, 11, 0)) +check("Button 12 (nach dem letzten sichtbaren) nicht angefasst", btn[12].pts[1][2] == bar) + +out("D: Haltungsleiste, 3 Haltungen, Rest ausgeblendet") +setup{barName = "StanceBar", count = 10, cols = 10, numShowing = 10, hidden = {4,5,6,7,8,9,10}} +check("Haltung 1-3 zusammengeschoben", rowOK(1, 3, 0)) +check("Haltung 4-10 nicht angefasst", btn[4].pts[1][2] == bar) + +out("E: Zweimal anwenden, dann /abstand 1,5") +setup{numShowing = 12, hidden = {3, 7}} +ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD"); run() +check("Zweiter Durchlauf verrutscht nichts", rowOK(1, 12, 0)) +SlashCmdList.LEISTENABSTAND("1,5"); run() +check("Neuer Abstand 1,5 ohne Reload", rowOK(1, 12, 1.5)) + +out("F: Zwei Reihen à 6, Slot 8 leer") +setup{numShowing = 12, cols = 6, hidden = {8}} +check("Reihe 1 korrekt", rowOK(1, 6, 0, 0)) +check("Reihe 2 korrekt, Luecke 8 bleibt", rowOK(7, 12, 0, 1)) + +out("G: /abstand rahmen mit leerem letzten Slot (numShowingButtons = 12)") +setup{numShowing = 12, hidden = {12}} +SlashCmdList.LEISTENABSTAND("rahmen"); run() +check("Rahmen umfasst alle 12 Slots", near(bar.w, 12*W)) + +out(fails == 0 and "\nAlle Tests bestanden." or ("\n" .. fails .. " Test(s) fehlgeschlagen.")) + +os.exit(fails == 0 and 0 or 1)