Fehler aus dem Code-Review behoben, Tests hinzugefügt
Leistenabstand: Leere, ausgeblendete Slots ("Immer Buttons anzeigen" aus)
werden mit angeordnet. Vorher wurde ihre Lücke zugeschoben, und sobald
sie wieder erschienen, lagen sie fast genau auf dem Nachbarbutton.
Buttons jenseits von "Anzahl Symbole" bleiben außen vor (numShowingButtons,
sonst bis zum letzten sichtbaren Button). Die Haltungsleiste ordnet weiter
nur sichtbare Buttons an.
Goldbeutel: "Diese Sitzung" läuft über /reload weiter (Startwert pro
Charakter gespeichert, Reset nur bei echtem Login). /gold forget findet
auch Namen mit Umlauten und Akzenten unabhängig von Groß-/Kleinschreibung.
ForeverScale: /fscale pixel ist jetzt ein Modus und wird bei jedem
Auflösungswechsel neu berechnet. Kann absichtlich unter 0,30 liegen.
README: Quellcode-Anhang auf den neuen Stand gebracht.
tests/: Mock-Tests für alle drei Addons (luajit tests/<datei>.lua).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da38820c2e
commit
f1eca2d1c5
7 files changed
+425
-50
No files matched your search
@@ -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)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user