218 lines
12 KiB
Lua
218 lines
12 KiB
Lua
local root=assert(arg[1])
|
|
dofile(root.."/client_addons/WoWHybridUI/NativeCollectionSpells.lua")
|
|
local member=WoWHybridCollectionSpells
|
|
assert(#member[1005]==278 and #member[1006]==445 and #member[1008]==92)
|
|
local frames, controls, events={}, {}, nil
|
|
local panel, guard, launcher
|
|
local combat, time, cold, perFrame, slotsPerFrame=false,0,true,0,0
|
|
local secret={}
|
|
function issecretvalue(value)return rawequal(value,secret) end
|
|
function InCombatLockdown()return combat end
|
|
function GetTime()return time end
|
|
local function noop() end
|
|
local function node(kind,parent,template)
|
|
local n={kind=kind,parent=parent,template=template,shown=true,enabled=true,scripts={},attrs={}}
|
|
function n:SetPoint()end
|
|
function n:SetClampedToScreen()end
|
|
n.SetSize,n.SetFrameStrata,n.EnableMouse,n.SetWidth,n.SetJustifyH,n.SetWordWrap,n.SetAllPoints,n.SetColorTexture=noop,noop,noop,noop,noop,noop,noop,noop
|
|
function n:RegisterEvent(e)self.registered=self.registered or {};self.registered[e]=true end
|
|
function n:SetScript(k,fn)self.scripts[k]=fn end
|
|
function n:SetAttribute(k,v)assert(not combat,"protected write during combat");self.attrs[k]=v end
|
|
function n:GetAttribute(k)return self.attrs[k] end
|
|
function n:RegisterForClicks(...)self.clicks={...}end
|
|
function n:RegisterForDrag(...)self.dragButtons={...}end
|
|
function n:SetTexture(v)self.texture=v end
|
|
function n:SetText(v)self.label=v end
|
|
function n:SetEnabled(v)self.enabled=v end
|
|
function n:SetShown(v)self.shown=v end
|
|
function n:Hide()self.shown=false end
|
|
function n:Show()self.shown=true end
|
|
function n:IsVisible()return self.shown and (not self.parent or self.parent:IsVisible()) end
|
|
function n:CreateTexture()return node("Texture",self) end
|
|
function n:CreateFontString()return node("FontString",self) end
|
|
return n
|
|
end
|
|
UIParent=node("Frame")
|
|
local book=node("Stock");book:Hide()
|
|
-- Stock frames expose no writable control or hook in this fixture.
|
|
PlayerSpellsFrame={SpellBookFrame=book}
|
|
function CreateFrame(kind,name,parent,template)
|
|
local n=node(kind,parent,template);frames[#frames+1]=n
|
|
if parent==book then assert(kind=="Button" and template=="UIPanelButtonTemplate");launcher=n
|
|
elseif template=="SecureHandlerStateTemplate" then assert(parent==UIParent);guard=n
|
|
elseif guard and parent==guard then panel=n
|
|
elseif kind=="Button" then controls[#controls+1]=n
|
|
elseif not parent then events=n end
|
|
return n
|
|
end
|
|
function RegisterStateDriver(f,key,condition)
|
|
assert(f==guard and key=="visibility" and condition=="[combat] hide; show")
|
|
end
|
|
Enum={SpellBookSpellBank={Player=0},SpellBookItemType={Spell=1}}
|
|
local known={[18989]=true,[18990]=true,[18991]=true,[10673]=true,[17468]=true,[8690]=true}
|
|
local lines={{name="General",iconID=1,shouldHide=false,itemIndexOffset=0,numSpellBookItems=1},
|
|
{name="Companions",iconID=237579,shouldHide=false,itemIndexOffset=1,numSpellBookItems=2},
|
|
{name="Mounts",iconID=132261,shouldHide=true,itemIndexOffset=3,numSpellBookItems=1}}
|
|
local slots={[1]={actionID=6603,spellID=6603,itemType=1},[2]={actionID=10673,spellID=10673,itemType=1},
|
|
[3]={actionID=17468,spellID=17468,itemType=1},[4]={actionID=18991,spellID=18991,itemType=1}}
|
|
local index={[1005]=2,[1006]=3}
|
|
C_SpellBook={
|
|
GetNumSpellBookSkillLines=function()return cold and 0 or #lines end,
|
|
GetSkillLineIndexByID=function(i)return index[i]end,
|
|
GetSpellBookSkillLineInfo=function(i)return lines[i]end,
|
|
GetSpellBookItemInfo=function(i,bank)assert(bank==0);slotsPerFrame=slotsPerFrame+1;return slots[i]end,
|
|
IsSpellKnown=function(id,bank)assert(bank==0);perFrame=perFrame+1;if known[id]==secret then return secret end;return known[id]==true end,
|
|
}
|
|
local journalUsable=true
|
|
C_MountJournal={
|
|
GetMountFromSpell=function(id)if id==18989 then return 42 elseif id==18990 then return 43 end end,
|
|
GetMountInfoByID=function(id)return "Kodo",id==42 and 18989 or 18990,123,false,true,0,false,false,nil,false,id==42,id end,
|
|
GetMountUsabilityByID=function(id,indoors)assert(id==42 and indoors==true);return journalUsable end,
|
|
}
|
|
local uncached, requested={},{}
|
|
local pickups={}
|
|
GameTooltip={
|
|
IsOwned=function(self,row)return self.owner==row end,
|
|
SetOwner=function(self,row,anchor)assert(anchor=="ANCHOR_RIGHT");self.owner=row end,
|
|
SetSpellByID=function(self,id)self.spellID=id end,
|
|
Hide=function(self)self.owner,self.spellID=nil,nil end,
|
|
}
|
|
C_Spell={
|
|
GetSpellInfo=function(id)if not uncached[id] then return {spellID=id,name="Spell "..id,iconID=id+100} end end,
|
|
IsSpellPassive=function(id)return id==8690 end,
|
|
RequestLoadSpellData=function(id) requested[id]=(requested[id] or 0)+1 end,
|
|
PickupSpell=function(id)table.insert(pickups,id) end,
|
|
}
|
|
dofile(root.."/client_addons/WoWHybridUI/NativeCollectionBook.lua")
|
|
local function tick(n)
|
|
for _=1,n do time=time+.05;perFrame,slotsPerFrame=0,0;events.scripts.OnUpdate()
|
|
assert(perFrame<=24 and slotsPerFrame<=16,"frame budget exceeded")
|
|
end
|
|
end
|
|
local function event(kind,...)assert(events.registered[kind],kind);events.scripts.OnEvent(events,kind,...) end
|
|
local function click(b)assert(b:IsVisible() and b.enabled);b.scripts.OnClick(b) end
|
|
local function named(name)
|
|
for _,b in ipairs(controls) do if b.label==name and b.parent==panel then return b end end
|
|
error("control missing: "..name)
|
|
end
|
|
local function displayed()
|
|
local result={}
|
|
for _,r in ipairs(controls)do if r.template=="SecureActionButtonTemplate" and r:IsVisible() then result[r.text.label]=r end end
|
|
return result
|
|
end
|
|
local function cast(r)
|
|
assert(r.template=="SecureActionButtonTemplate" and r.clicks[1]=="LeftButtonUp" and r.attrs.useOnKeyDown==false)
|
|
return r.attrs.type1=="spell" and r.attrs.spell1 or nil
|
|
end
|
|
tick(3);assert(not launcher)
|
|
book:Show();tick(20);assert(launcher and not launcher:IsVisible())
|
|
cold=false
|
|
-- Even when skill/spell updates arrive faster than a scan, all three
|
|
-- source categories must reach the end of enumeration.
|
|
local reached=false
|
|
for i=1,180 do
|
|
if i%7==0 then event("SKILL_LINES_CHANGED") end
|
|
tick(1)
|
|
if launcher:IsVisible() then reached=true;break end
|
|
end
|
|
assert(reached,"repeated skill changes starved the collection scan")
|
|
tick(120);assert(launcher:IsVisible());click(launcher)
|
|
local first=displayed()
|
|
assert(C_MountJournal.GetMountUsabilityByID(42,true))
|
|
assert(first["Spell 18989"], "native book omitted journal-summonable learned Gray Kodo")
|
|
assert(cast(first["Spell 18989"])==18989 and cast(first["Spell 18990"])==18990 and cast(first["Spell 18991"])==18991)
|
|
local mount=first["Spell 18989"]
|
|
assert(#mount.dragButtons==1 and mount.dragButtons[1]=="LeftButton")
|
|
mount.scripts.OnEnter(mount)
|
|
assert(GameTooltip:IsOwned(mount) and GameTooltip.spellID==18989)
|
|
mount.scripts.OnDragStart(mount)
|
|
assert(pickups[1]==18989 and cast(mount)==18989)
|
|
known[18989]=secret;mount.scripts.OnDragStart(mount)
|
|
known[18989]=nil;mount.scripts.OnDragStart(mount)
|
|
known[18989]=true;combat=true;mount.scripts.OnDragStart(mount);combat=false
|
|
assert(#pickups==1)
|
|
assert(not named("Companions").enabled) -- Both learned source entries already exist in the visible category.
|
|
click(named("Toys"));local toys=displayed()
|
|
assert(cast(toys["Spell 17468"])==17468 and toys["Spell 8690 (Passive)"] and not cast(toys["Spell 8690 (Passive)"]))
|
|
assert(GameTooltip.spellID==mount.spellID and GameTooltip.spellID~=18989)
|
|
local passive=toys["Spell 8690 (Passive)"]
|
|
passive.scripts.OnEnter(passive);passive.scripts.OnDragStart(passive)
|
|
assert(GameTooltip.spellID==8690 and #pickups==1)
|
|
local toy=toys["Spell 17468"]
|
|
toy.scripts.OnEnter(toy);passive.scripts.OnLeave(passive)
|
|
assert(GameTooltip:IsOwned(toy))
|
|
toy.scripts.OnDragStart(toy);assert(pickups[2]==17468)
|
|
toy.scripts.OnHide(toy);assert(not GameTooltip.owner)
|
|
-- A visible companion tab can exist before its slot data arrives.
|
|
local readySlot=slots[2]
|
|
for _,unavailable in ipairs({false,secret,{itemType=1,spellID=secret,actionID=10673}}) do
|
|
slots[2]=unavailable or nil
|
|
event("SKILL_LINES_CHANGED");tick(90)
|
|
assert(launcher:IsVisible(),"a pending companion slot hid unrelated collections")
|
|
assert(cast(displayed()["Spell 17468"])==17468 and not named("Companions").enabled)
|
|
end
|
|
known[10679]=true;slots[2]=readySlot
|
|
tick(120)
|
|
assert(named("Companions").enabled,"slot readiness was not retried")
|
|
known[10679]=nil
|
|
-- Hide the native category and update ownership, including one unavailable secret.
|
|
lines[2].shouldHide=true;known[10673]=nil;known[10679]=true;known[10674]=secret
|
|
event("SPELLS_CHANGED");assert(not launcher:IsVisible());tick(85);click(named("Companions"))
|
|
local pets=displayed();assert(not pets["Spell 10673"] and not pets["Spell 10674"] and pets["Spell 10679"] and pets["Spell 17468"])
|
|
pets["Spell 10679"].scripts.OnDragStart(pets["Spell 10679"]);assert(pickups[3]==10679)
|
|
-- Account-journal creature 7393 cannot establish that this player knows Source spell 10687.
|
|
C_PetJournal={
|
|
GetNumPets=function()return 1 end,
|
|
GetPetInfoByIndex=function(index)assert(index==1);return "fixture-pet",900001,true end,
|
|
GetPetInfoBySpeciesID=function(species)assert(species==900001);return "Fixture chicken",nil,nil,7393 end,
|
|
}
|
|
local _,species,journalOwned=C_PetJournal.GetPetInfoByIndex(1)
|
|
assert(journalOwned and select(4,C_PetJournal.GetPetInfoBySpeciesID(species))==7393)
|
|
event("SPELLS_CHANGED");tick(90);assert(not displayed()["Spell 10687"])
|
|
known[10687]=true
|
|
event("SPELLS_CHANGED");tick(90);assert(cast(displayed()["Spell 10687"])==10687)
|
|
known[10687]=nil
|
|
event("SPELLS_CHANGED");tick(90);assert(not displayed()["Spell 10687"])
|
|
-- A matching visible mount slot contributes both its base and overriding IDs.
|
|
lines[3].shouldHide=false;slots[4].actionID=18990
|
|
event("SKILL_LINES_CHANGED");tick(90);click(named("Mounts"))
|
|
assert(cast(displayed()["Spell 18989"])==18989 and not displayed()["Spell 18990"])
|
|
-- Independently read and retain visible category slots even when ID tracking is not ready.
|
|
index[1006]=1;slots[1].spellID=18989;slots[1].actionID=18989
|
|
event("SKILL_LINES_CHANGED");tick(90);assert(cast(displayed()["Spell 18989"])==18989)
|
|
index[1006]=nil;event("SKILL_LINES_CHANGED");tick(90)
|
|
assert(cast(displayed()["Spell 18989"])==18989)
|
|
-- The original book retains its known mount indoors. Journal usability and
|
|
-- ownership alone must neither hide a learned spell nor add an unlearned one.
|
|
journalUsable=false;event("SPELLS_CHANGED");tick(90)
|
|
assert(cast(displayed()["Spell 18989"])==18989)
|
|
known[18989]=nil;journalUsable=true;event("SPELLS_CHANGED");tick(90)
|
|
assert(not named("Mounts").enabled)
|
|
known[18989]=true;lines[3].numSpellBookItems=2
|
|
slots[5]={actionID=18989,spellID=18989,itemType=1}
|
|
event("SKILL_LINES_CHANGED");tick(90);assert(not named("Mounts").enabled)
|
|
known[10674]=nil
|
|
for i=1,14 do known[member[1005][i]]=true end
|
|
uncached[member[1005][1]]=true
|
|
event("SPELLS_CHANGED");tick(90);if named("Companions").enabled then click(named("Companions")) end
|
|
local id=member[1005][1];assert(requested[id]==1 and displayed()["Spell "..id.." (Details unavailable)"])
|
|
event("SPELL_DATA_LOAD_RESULT",id,false)
|
|
assert(requested[id]==1,"load failure must not immediately request again")
|
|
click(launcher);click(launcher)
|
|
assert(requested[id]==2,"reopening should retry a failed spell detail request")
|
|
uncached[id]=nil;event("SPELL_DATA_LOAD_RESULT",id,true);assert(cast(displayed()["Spell "..id])==id)
|
|
local before=displayed();click(named("Next"));local after=displayed()
|
|
for label in pairs(after)do assert(not before[label],"same row on both pages")end
|
|
click(named("Previous"));assert(displayed()["Spell "..id])
|
|
combat=true;guard:Hide();event("PLAYER_REGEN_DISABLED");tick(8);assert(not panel:IsVisible())
|
|
combat=false;guard:Show();event("PLAYER_REGEN_ENABLED");tick(90);assert(not panel:IsVisible())
|
|
book:Hide();tick(1);assert(not launcher:IsVisible());known={}
|
|
book:Show();tick(90);assert(not launcher:IsVisible() and not panel:IsVisible())
|
|
-- A world transition must discard a half-finished scan from the last character.
|
|
known[10679]=true;event("SPELLS_CHANGED");tick(32)
|
|
event("PLAYER_LEAVING_WORLD");known={[8690]=true};event("PLAYER_ENTERING_WORLD")
|
|
tick(90);assert(launcher:IsVisible());click(launcher)
|
|
assert(not named("Mounts").enabled and not named("Companions").enabled)
|
|
assert(displayed()["Spell 8690 (Passive)"] and not displayed()["Spell 10679"])
|
|
print("PASS source membership, player knowledge, per-category deduplication, journal-independent learned mounts, secure hardware actions, paging, secret/cold spell data, combat and bounded scanning")
|