Files
ShaguTweaks-ClassicAPI/tests/test_standalone_player.lua
T

157 lines
10 KiB
Lua

local root=(arg[1] or '.') .. '/'
local function Check(big,timer,hidden,hideName,maskAvailable)
local modules,frames,pending={},{},{}
local methods={}
local function noop() end
local function new(kind,name,parent)
local object=setmetatable({kind=kind or 'Frame',name=name,parent=parent,scripts={},width=119,height=12,left=106,top=550,scale=1,alpha=1,visible=true},{__index=function(t,k) if methods[k] then return methods[k] elseif string.find(k,'^[A-Z]') then return noop end end})
if kind=='Texture' and maskAvailable==false then object.SetMask=false end
table.insert(frames,object); if name then _G[name]=object end; return object
end
function methods:GetName() return self.name end
function methods:GetObjectType() return self.kind end
function methods:SetParent(parent) self.parent=parent end
function methods:GetParent() return self.parent end
function methods:SetWidth(w) self.width=w end
function methods:SetHeight(h) self.height=h end
function methods:GetWidth() return self.width end
function methods:GetHeight() return self.height end
function methods:GetLeft() return self.left end
function methods:GetTop() return self.top end
function methods:GetCenter() return self.centerX,self.centerY end
function methods:ClearAllPoints() self.points={} end
function methods:SetPoint(p,relative,rp,x,y) self.points={p,relative,rp,x,y}; if rp=='BOTTOMLEFT' then self.left=x;self.top=y end end
function methods:SetAllPoints(relative) self.allPoints=relative end
function methods:SetScale(scale) self.scale=scale end
function methods:GetEffectiveScale() return self.scale end
function methods:SetFrameLevel(level) self.level=level end
function methods:GetFrameLevel() return self.level or 1 end
function methods:GetFrameStrata() return 'BACKGROUND' end
function methods:SetScript(script,callback) self.scripts[script]=callback end
function methods:GetScript(script) return self.scripts[script] end
function methods:CreateTexture() return new('Texture',nil,self) end
function methods:SetMask(path) self.mask=path end
function methods:SetTexture(path) self.path=path end
function methods:SetBackdrop(backdrop) self.backdrop=backdrop end
function methods:GetTexture() return self.path end
function methods:GetStatusBarTexture() return {GetTexture=function() return 'NativeHealthTexture' end} end
function methods:GetStatusBarColor() return .53,.53,.93,1 end
function methods:SetText(text) self.text=text end
function methods:SetTexCoord(a,b,c,d) self.uv={a,b,c,d} end
function methods:GetTexCoord() return 1,0,1,.78125,.09375,0,.09375,.78125 end
function methods:SetVertexColor(r,g,b,a) self.color={r,g,b,a} end
function methods:GetVertexColor() return 1,.78,.4,1 end
function methods:SetDrawLayer(layer) self.layer=layer end
function methods:SetAlpha(alpha) self.alpha=alpha end
function methods:EnableMouse(enabled) self.mouse=enabled end
function methods:StartMoving() self.moving=true end
function methods:StopMovingOrSizing() self.moving=false end
function methods:Hide() self.visible=false end
function methods:Show() self.visible=true end
CreateFrame=new
local keys=false
ShaguTweaks={T=setmetatable({},{__index=function(t,k) return k end}),API={timer=timer}}
function ShaguTweaks.GetGlobalEnv() return _G end
function ShaguTweaks:register(module) modules[module.title]=module;return module end
ShaguTweaks.API.IsShiftKeyDown=function() return keys end
ShaguTweaks.API.IsControlKeyDown=ShaguTweaks.API.IsShiftKeyDown
ShaguTweaks.API.IsAltKeyDown=ShaguTweaks.API.IsShiftKeyDown
function ShaguTweaks.API.Defer(callback) table.insert(pending,callback) end
function ShaguTweaks.hooksecurefunc(object,name,callback)
if type(object)=='string' then callback=name;name=object;object=_G end
local original=object[name] or noop
object[name]=function(a,b,c,d) original(a,b,c,d);callback(a,b,c,d) end
end
local oldThis,oldArg
local function fire(frame,script,button)
oldThis,oldArg=this,arg1;this,arg1=frame,button; local callback=frame:GetScript(script); if callback then callback() end; this,arg1=oldThis,oldArg
end
UIParent=new('Frame','UIParent');PlayerFrame=new('Button','PlayerFrame',UIParent)
PlayerFrame.width=232;PlayerFrame.height=100
function UnitClass() return 'Warlock','WARLOCK' end
function UnitLevel() return 60 end
ShaguTweaks.ModernClassColors={WARLOCK={r=.53,g=.53,b=.93}}
PlayerLevelText=new('FontString','PlayerLevelText',PlayerFrame)
PlayerLevelText.centerX=117;PlayerLevelText.centerY=496
PlayerFrame.name=new('FontString','PlayerName',PlayerFrame)
PlayerPortrait=new('Texture','PlayerPortrait',PlayerFrame);PlayerPortrait.alpha=hidden and 0 or 1
PlayerRestIcon=new('Texture','PlayerRestIcon',PlayerFrame);PlayerRestIcon.width=31
PlayerRestIcon.left=101;PlayerRestIcon.top=513
PlayerStatusGlow=new('Frame','PlayerStatusGlow',PlayerFrame);PlayerStatusGlow.width=32
PlayerStatusGlow.left=101;PlayerStatusGlow.top=513
PlayerFrameTexture=new('Texture','PlayerFrameTexture',PlayerFrame);PlayerFrameTexture.path=big and 'BigHealthArt' or 'StockArt'
PlayerFrameBackground=new('Texture','PlayerFrameBackground',PlayerFrame)
PlayerFrameNameBackground=new('Texture','PlayerFrameNameBackground',PlayerFrame)
PlayerFrameHealthBar=new('StatusBar','PlayerFrameHealthBar',PlayerFrame)
PlayerFrameManaBar=new('StatusBar','PlayerFrameManaBar',PlayerFrame)
PlayerFrameHealthBar.height=big and 30 or 12
PlayerFrameHealthBar.TextString=new('FontString',nil,PlayerFrame)
PlayerFrameManaBar.TextString=new('FontString',nil,PlayerFrame)
local healthEvent=function() end
PlayerFrameHealthBar:SetScript('OnEvent',healthEvent)
local numbers=new('FontString',nil,PlayerFrameHealthBar)
PlayerStatusTexture=new('Texture','PlayerStatusTexture',PlayerFrame)
PlayerFrameDropDown={}
PlayerFrame_OnReceiveDrag=noop
PlayerFrame_UpdateStatus=noop
local clicked,menu
function PlayerFrame_OnClick(button) clicked=button end
function SpellIsTargeting() return false end
function ToggleDropDownMenu(a,b,c,anchor) menu=anchor end
ShaguTweaks_config={['Standalone Player Frame']=1,['Hide Player Name']=hideName and 1 or 0,['Unit Frame Big Health for Player']=big and 1 or 0,StandalonePlayerFrame={Health={x=420,y=520}}}
local originalHealth,originalMana,originalPortrait=PlayerFrameHealthBar,PlayerFrameManaBar,PlayerPortrait
dofile(root..'mods/unitframes-hide-player-name.lua')
modules['Hide Player Name']:enable()
dofile(root..'mods/unitframes-standalone-player.lua')
assert(not ShaguTweaks.StandalonePlayerFrame)
modules['Standalone Player Frame']:enable()
local ready=frames[table.getn(frames)]
fire(ready,'OnEvent');fire(ready,'OnUpdate')
if timer then assert(table.getn(pending)==1);pending[1]() else fire(ready,'OnUpdate') end
local layout=ShaguTweaks.StandalonePlayerFrame
assert(layout.name.visible==(not hideName))
assert(layout.health.backdrop.edgeFile=='Interface\\Tooltips\\UI-Tooltip-Border')
assert(not layout.health.art and not layout.power.art)
assert(layout.portrait.art.width==40 and layout.portrait.art.height==(maskAvailable==false and 72 or 36) and layout.portrait.artRight.height==36)
assert(layout.portrait.artBottomRight.height==36)
if maskAvailable==false then
assert(not layout.portrait.badge.visible and not layout.portrait.artBottomLeft)
else
assert(layout.portrait.artBottomLeft.height==36)
assert(layout.portrait.badge.mask=='Interface\\CharacterFrame\\TempPortraitAlphaMask')
assert(layout.portrait.badge:GetParent()==layout.portrait.badgeOverlay)
assert(layout.portrait.badgeOverlay:GetFrameLevel()>layout.portrait:GetFrameLevel())
assert(layout.portrait.levelOverlay:GetFrameLevel()>layout.portrait.badgeOverlay:GetFrameLevel())
end
assert(PlayerLevelText:GetParent()==layout.portrait.levelOverlay and PlayerLevelText.text==60)
assert(PlayerLevelText.points[4]==19 and PlayerLevelText.points[5]==-58)
assert(PlayerRestIcon.points[4]==3 and PlayerStatusGlow.points[4]==3)
assert(PlayerLevelText.layer=='BACKGROUND' and PlayerRestIcon:GetParent()==layout.portrait.levelOverlay)
assert(layout.portrait.levelOverlay:GetFrameLevel()>layout.portrait:GetFrameLevel())
PlayerLevelText:SetText(61);assert(PlayerLevelText.text==61)
assert(layout.name.classBackground.path=='NativeHealthTexture')
assert(layout.name.classBackground.color[1]==.53 and layout.name.classBackground.color[3]==.93)
assert(PlayerFrameNameBackground.alpha==0 and layout.name.classBackground.visible)
assert(layout and originalHealth==PlayerFrameHealthBar and originalMana==PlayerFrameManaBar and originalPortrait==PlayerPortrait)
assert(PlayerFrameHealthBar:GetParent()==layout.health and PlayerFrameManaBar:GetParent()==layout.power)
assert(layout.power.unit=="player" and layout.power.manabar==PlayerFrameManaBar)
assert(PlayerPortrait:GetParent()==layout.portrait and PlayerPortrait.alpha==(hidden and 0 or 1))
assert(numbers:GetParent()==PlayerFrameHealthBar and PlayerFrameHealthBar:GetScript('OnEvent')==healthEvent)
assert(PlayerFrame.visible and PlayerFrame.mouse==false and PlayerFrameTexture.alpha==0)
assert(layout.health.left==420 and layout.health.top==520)
assert(PlayerFrameManaBar.height==(big and 30 or 12))
assert(not ready:GetScript('OnUpdate'))
fire(layout.name,'OnClick','LeftButton');assert(clicked=='LeftButton')
fire(PlayerFrameHealthBar,'OnMouseUp','RightButton');assert(menu==layout.health:GetName())
keys=true
fire(PlayerFrameManaBar,'OnDragStart');assert(layout.power.moving)
layout.power.left=300;layout.power.top=400
fire(PlayerFrameManaBar,'OnDragStop');assert(not layout.power.moving and ShaguTweaks_config.StandalonePlayerFrame.Power.x==300)
fire(layout.power,'OnMouseDown','RightButton');assert(not ShaguTweaks_config.StandalonePlayerFrame.Power)
assert(layout.power.left==layout.power.defaultPosition.x)
PlayerFrameTexture:SetAlpha(1);assert(PlayerFrameTexture.alpha==0)
PlayerFrame_UpdateStatus();assert(PlayerStatusTexture.width==72)
end
Check(false,true,false,false);Check(true,true,true,true);Check(false,false,false,true);Check(true,false,false,false);Check(false,true,false,false,false)
print('Standalone player: native object/event/text retention, big power sizing, portrait hiding, saved positions, drag/reset, click handling and idle initialization passed')