- Statt Blizzards durchschnittlicher Gegenstandsstufe zeigt der Rahmen jetzt den GearScore, berechnet wie im Addon GearScore Forever (GearScoreLite- Formel), samt dessen Farbskala. Der Tooltip zeigt GearScore und Gegenstandsstufe wie dessen Charakteransicht. GearScore Forever muss nicht installiert sein. - Fehlen Gegenstandsdaten noch, wird bei GET_ITEM_INFO_RECEIVED neu gerechnet. - Trenner zwischen den Werten repariert: "||r" zeigte ein sichtbares "r", richtig ist "|||r". - Die Beschriftung "Taschen" im Rahmen entfällt, die Zahl steht allein. - Tests lesen Escape-Sequenzen jetzt wie der Client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
226 lines
13 KiB
Lua
226 lines
13 KiB
Lua
-- 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, shownText, gtimers
|
||
-- Ausgangszustand fuer Taschen, Ruestung und Ausruestung (in Tests veraenderbar)
|
||
-- bags[i] = { Plaetze, frei, Taschentyp }; Index 0 = Rucksack, 5 = Reagenzientasche
|
||
-- gear[Platz] = { Qualitaet, Gegenstandsstufe, Ausruestungsplatz }
|
||
local bags, dura, gear, gclass, uncached
|
||
local function defaultGear()
|
||
bags = { [0] = {16, 5, 0}, {20, 10, 0}, {16, 16, 1}, {0, 0, 0}, {20, 8, 0}, {36, 30, 0} }
|
||
dura = { [1] = {45, 100}, [5] = {100, 100}, [7] = {80, 80} } -- Kopf, Brust, Beine
|
||
gear = {
|
||
[1] = {4, 66, "INVTYPE_HEAD"}, [2] = {3, 60, "INVTYPE_NECK"}, [3] = {4, 66, "INVTYPE_SHOULDER"},
|
||
[4] = {1, 1, "INVTYPE_BODY"}, [5] = {4, 66, "INVTYPE_ROBE"}, [6] = {3, 58, "INVTYPE_WAIST"},
|
||
[7] = {4, 66, "INVTYPE_LEGS"}, [8] = {3, 58, "INVTYPE_FEET"}, [9] = {3, 58, "INVTYPE_WRIST"},
|
||
[10] = {4, 66, "INVTYPE_HAND"}, [11] = {3, 60, "INVTYPE_FINGER"}, [12] = {3, 60, "INVTYPE_FINGER"},
|
||
[13] = {3, 60, "INVTYPE_TRINKET"}, [14] = {3, 60, "INVTYPE_TRINKET"}, [15] = {3, 60, "INVTYPE_CLOAK"},
|
||
[16] = {4, 77, "INVTYPE_2HWEAPON"}, [18] = {3, 60, "INVTYPE_RANGEDRIGHT"}, [19] = {1, 1, "INVTYPE_TABARD"},
|
||
}
|
||
gclass, uncached = "MAGE", {}
|
||
end
|
||
defaultGear()
|
||
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 "Klasse", gclass end
|
||
GetMoney = function() return money end
|
||
NUM_BAG_SLOTS, NUM_TOTAL_EQUIPPED_BAG_SLOTS, INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED = 4, 5, 1, 19
|
||
C_Container = {
|
||
GetContainerNumSlots = function(b) return bags[b] and bags[b][1] or 0 end,
|
||
GetContainerNumFreeSlots = function(b) if bags[b] then return bags[b][2], bags[b][3] end return 0, 0 end,
|
||
}
|
||
GetInventoryItemDurability = function(s) if dura[s] then return dura[s][1], dura[s][2] end end
|
||
GetInventoryItemLink = function(_, s) if gear[s] then return "[Item" .. s .. "]" end end
|
||
GetInventoryItemID = function(_, s) if gear[s] then return 1000 + s end end
|
||
C_Item = { GetItemInfo = function(link)
|
||
local s = tonumber(link:match("%d+")); local g = gear[s]
|
||
if g and not uncached[s] then return "Name", link, g[1], g[2], 1, "Ruestung", "Stoff", 1, g[3] end
|
||
end }
|
||
GearscoreForeverDB = nil
|
||
gtimers = {}
|
||
C_Timer = { After = function(_, fn) gtimers[#gtimers + 1] = fn 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{ SetText = function(_, t) shownText = t end,
|
||
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)
|
||
|
||
out("Goldbeutel: Taschen, Ruestung, GearScore")
|
||
local function flush() while #gtimers > 0 do table.remove(gtimers, 1)() end end
|
||
-- Liest Escape-Sequenzen wie der Client von links nach rechts: "||" ist ein |,
|
||
-- |cAARRGGBB und |r sind Farben, |T...|t eine Textur. Liefert den sichtbaren Text
|
||
-- und die Zahl der am Ende noch offenen Farben (muss 0 sein).
|
||
local function render(s)
|
||
local res, open, i = {}, 0, 1
|
||
while i <= #s do
|
||
local c, n = s:sub(i, i), s:sub(i + 1, i + 1)
|
||
if c ~= "|" then res[#res + 1] = c; i = i + 1
|
||
elseif n == "|" then res[#res + 1] = "|"; i = i + 2
|
||
elseif n == "c" and s:sub(i + 2, i + 9):match("^%x+$") and i + 9 <= #s then open = open + 1; i = i + 10
|
||
elseif n == "r" then open = open - 1; i = i + 2
|
||
elseif n == "T" then i = (s:find("|t", i, true) or #s) + 2
|
||
else res[#res + 1] = c; i = i + 1 end
|
||
end
|
||
return table.concat(res), open
|
||
end
|
||
local function plain(s) return (render(s)) end
|
||
local function tooltip() lines = {}; fr.scripts.OnEnter(fr); return lines end
|
||
-- Sollwerte (Punkte, iLvl, Farbe) stammen aus dem Originalcode von GearScore Forever 1.3.0
|
||
defaultGear(); money = 1234567
|
||
fr = startGold("Testmagier", nil); ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD", true, false); flush()
|
||
check("Rahmen: eine Zeile mit allen vier Werten",
|
||
plain(shownText) == "123 45 67 | 23 | 45% | GS 856")
|
||
check("Jede Farbe wird wieder geschlossen (grauer Trenner ohne sichtbares 'r')",
|
||
select(2, render(shownText)) == 0 and shownText:find("|cff666666|||r", 1, true) ~= nil)
|
||
check("Spezialtaschen (Koecher, Reagenzientasche) nicht im Rahmen mitgezaehlt", plain(shownText):find("| 23 |", 1, true))
|
||
check("45% gelb (unter 50)", shownText:find("|cffffd10045%|r", 1, true) ~= nil)
|
||
check("23 freie Plaetze ohne Warnfarbe", shownText:find("|||r 23 ", 1, true) ~= nil)
|
||
check("GS 856 lila wie in GearScore Forever", shownText:find("|cffb44aea856|r", 1, true) ~= nil)
|
||
tooltip()
|
||
check("Tooltip: Taschen frei 23 / 56", lines["Taschen frei:"] == "23 / 56")
|
||
check("Tooltip: Spezialtaschen frei 46 / 52", lines["Spezialtaschen frei:"] == "46 / 52")
|
||
check("Tooltip: Ruestung gesamt 80% (225/280)", lines["Rüstung gesamt:"] == "80%")
|
||
check("Tooltip: am staerksten beschaedigtes Teil (Kopf) mit 45%", plain(lines[" [Item1]"] or "") == "45%")
|
||
check("Tooltip: GearScore 856", plain(lines["GearScore:"] or "") == "856")
|
||
check("Tooltip: Gegenstandsstufe 62 (ohne Hemd und Wappenrock)", lines["Gegenstandsstufe:"] == 62)
|
||
|
||
bags[0][2], bags[1][2], bags[4][2] = 0, 3, 0; dura[1][1] = 10
|
||
for _ = 1, 3 do ev.scripts.OnEvent(ev, "BAG_UPDATE_DELAYED") end
|
||
ev.scripts.OnEvent(ev, "UPDATE_INVENTORY_DURABILITY")
|
||
check("Mehrere Ereignisse -> nur eine Aktualisierung", #gtimers == 1)
|
||
flush()
|
||
check("3 freie Plaetze gelb", shownText:find("|cffffd1003|r", 1, true) ~= nil)
|
||
check("10% rot", shownText:find("|cffff333310%|r", 1, true) ~= nil)
|
||
bags[1][2] = 0; ev.scripts.OnEvent(ev, "BAG_UPDATE_DELAYED"); flush()
|
||
check("0 freie Plaetze rot", shownText:find("|cffff33330|r", 1, true) ~= nil)
|
||
|
||
out("Goldbeutel: GearScore wie in GearScore Forever")
|
||
ev.scripts.OnEvent(ev, "GET_ITEM_INFO_RECEIVED"); check("Alles geladen: GET_ITEM_INFO_RECEIVED loest nichts aus", #gtimers == 0)
|
||
GearscoreForeverDB = { maxScoreSeen = 1800 }; ev.scripts.OnEvent(ev, "PLAYER_MONEY"); flush()
|
||
check("Groessere Skala aus GearScore Forever (1800 gesehen): 856 gruen", shownText:find("|cff18e535856|r", 1, true) ~= nil)
|
||
GearscoreForeverDB = nil
|
||
gclass = "HUNTER"; ev.scripts.OnEvent(ev, "PLAYER_EQUIPMENT_CHANGED"); flush()
|
||
check("Jaeger: Nahkampfwaffe zaehlt wenig, Zauberstab viel -> 818", plain(tooltip()["GearScore:"] or "") == "818")
|
||
gclass = "MAGE"; gear[17] = {4, 77, "INVTYPE_2HWEAPON"}
|
||
ev.scripts.OnEvent(ev, "PLAYER_EQUIPMENT_CHANGED"); flush()
|
||
check("Titanengriff: zwei Zweihaender je zur Haelfte -> 856, iLvl 63",
|
||
plain(tooltip()["GearScore:"] or "") == "856" and lines["Gegenstandsstufe:"] == 63)
|
||
gear[17] = nil; uncached[1] = true
|
||
ev.scripts.OnEvent(ev, "PLAYER_EQUIPMENT_CHANGED"); flush()
|
||
check("Kopf noch nicht geladen: vorlaeufig 781", plain(shownText):find("GS 781", 1, true) ~= nil)
|
||
uncached[1] = nil; ev.scripts.OnEvent(ev, "GET_ITEM_INFO_RECEIVED")
|
||
check("GET_ITEM_INFO_RECEIVED rechnet neu, solange Daten fehlen", #gtimers == 1)
|
||
flush()
|
||
check("Danach vollstaendig: 856", plain(shownText):find("GS 856", 1, true) ~= nil)
|
||
|
||
gear, dura = {}, {}; ev.scripts.OnEvent(ev, "PLAYER_EQUIPMENT_CHANGED"); flush()
|
||
check("Ohne Ausruestung nur Gold und Taschen", plain(shownText) == "123 45 67 | 0")
|
||
tooltip()
|
||
check("Tooltip ohne Ruestungs- und GearScore-Zeilen",
|
||
lines["Rüstung gesamt:"] == nil and lines["GearScore:"] == nil and lines["Gegenstandsstufe:"] == nil)
|
||
defaultGear(); dura = { [1] = {50, 50} }; ev.scripts.OnEvent(ev, "UPDATE_INVENTORY_DURABILITY"); flush()
|
||
tooltip()
|
||
check("Alles heil: keine Zeile fuer beschaedigtes Teil", lines[" [Item1]"] == nil and lines["Rüstung gesamt:"] == "100%")
|
||
|
||
---------------------------------------------------------------- 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)
|