174 lines
7.9 KiB
Lua
174 lines
7.9 KiB
Lua
-- Lua 5.1. Pass the extracted 70334 interface/addons directory to also run its navigation and binding code.
|
|
local stock = arg[1]
|
|
local g = setmetatable({}, {__index = _G})
|
|
g._G = g
|
|
local function noop() end
|
|
local function loadIn(path)
|
|
local source = assert(loadfile(path))
|
|
setfenv(source, g)
|
|
return source()
|
|
end
|
|
local widget, scriptReads = {}, {}
|
|
function widget:GetObjectType() return self.kind end
|
|
function widget:IsObjectType(kind) return self.kind == kind end
|
|
function widget:GetScript(name)
|
|
scriptReads[self] = (scriptReads[self] or 0) + 1
|
|
return self.scripts[name]
|
|
end
|
|
function widget:SetScript(name, fn) self.scripts[name] = fn end
|
|
function widget:HookScript(name, fn)
|
|
local hooks = self.hooks[name] or {}
|
|
self.hooks[name] = hooks
|
|
table.insert(hooks, fn)
|
|
end
|
|
function widget:GetParent() return self.parent end
|
|
function widget:GetChildren() return unpack(self.children) end
|
|
function widget:GetSize() return 100, 100 end
|
|
function widget:GetFrameLevel() return self.level or 0 end
|
|
function widget:SetFrameLevel(level) self.level = level end
|
|
function widget:GetMapID() return self.mapID end
|
|
function widget:IsShown() return self.shown end
|
|
function widget:Hide() self.shown = false end
|
|
function widget:HasScript() return true end
|
|
widget.SetAllPoints, widget.UnregisterAllEvents, widget.RegisterEvent = noop, noop, noop
|
|
function g.CreateFrame(kind, name, parent)
|
|
local frame = setmetatable({kind=kind, parent=parent, children={}, scripts={}, hooks={}, shown=true}, {__index=widget})
|
|
if parent then table.insert(parent.children, frame) end
|
|
return frame
|
|
end
|
|
g.GetBuildInfo = function() return '1.60.1','70334','date',16001 end
|
|
g.GetCVar = function() return '0' end
|
|
g.GetPlayerFacing = function() return 0 end
|
|
g.StaticPopupDialogs, g.QUIT_NOW, g.CANCEL = {}, 'Quit', 'Cancel'
|
|
g.geterrorhandler = function() return error end
|
|
g.hooksecurefunc = noop
|
|
g.C_QuestLog = {}
|
|
g.C_Map = {GetBestMapForUnit=function() return 1453 end}
|
|
g.Enum = {UIMapType={Zone=3}}
|
|
g.WorldMapFrame = g.CreateFrame('Frame')
|
|
local map = g.WorldMapFrame
|
|
map.ScrollContainer = g.CreateFrame('Frame', nil, map)
|
|
map.ScrollContainer.Child = g.CreateFrame('Frame', nil, map.ScrollContainer)
|
|
map:Hide()
|
|
local navigation = {}
|
|
g.OpenWorldMap = function(id)
|
|
navigation[#navigation+1] = 'world'
|
|
map.mapID, map.shown = id or 1453, true
|
|
end
|
|
g.OpenQuestLog = function() navigation[#navigation+1] = 'quest'; map.shown = true end
|
|
g.C_QuestLog.SetSelectedQuest = function(id) navigation[#navigation+1] = id end
|
|
g.InCombatLockdown = function() return false end
|
|
|
|
loadIn('compat/forever.lua')
|
|
local e = g.pfQuestEnv
|
|
local canvas = e.WorldMapButton
|
|
local filter = e.CreateFrame('Frame', nil, e.WorldMapFrame)
|
|
local pin = e.CreateFrame('Button', nil, canvas)
|
|
assert(canvas:GetParent() == map.ScrollContainer.Child)
|
|
assert(filter:GetParent() == map)
|
|
-- Exercise the companion's actual pin-wrapper code against either core when its checkout is supplied.
|
|
if arg[3] then
|
|
local handle = assert(io.open(arg[3]..'/patchtable.lua'))
|
|
local text = handle:read('*a')
|
|
handle:close()
|
|
local function slice(startText, endText)
|
|
local first = assert(text:find(startText, 1, true))
|
|
local last = assert(text:find(endText, first, true))
|
|
return text:sub(first,last-1)
|
|
end
|
|
local fallback = slice('if not pfQuestGetFrameScript then', 'local loc = GetLocale()')
|
|
local bind = slice('local originalUpdateNode = pfMap.UpdateNode', 'local function RebindUnitResultTooltips()')
|
|
local source = assert(loadstring('local MinimapLootNodeClick = ...\n'..fallback..bind))
|
|
setfenv(source, e)
|
|
e.pfMap = {UpdateNode=noop}
|
|
local function click() end
|
|
local function original() end
|
|
pin.spawnid = 5523
|
|
pin:SetScript('OnClick', original)
|
|
source(click)
|
|
e.pfMap:UpdateNode(pin)
|
|
e.pfMap:UpdateNode(pin)
|
|
assert(e.pfQuestGetFrameScript(pin, 'OnClick') == click and pin.lootPanelOriginalClick == original)
|
|
print('Companion pin can wrap its original click handler twice without self-chaining')
|
|
end
|
|
if arg[2] == 'baseline' then
|
|
local nav = loadIn(assert(stock)..'/blizzard_gamepadsmartnavigation/utility.lua')
|
|
local oldGetter, calls = assert(rawget(canvas, 'GetScript')), 0
|
|
debug.sethook(function()
|
|
if debug.getinfo(2, 'f').func == oldGetter then calls = calls + 1 end
|
|
end, 'c')
|
|
nav.FindButtonGroups(map)
|
|
debug.sethook()
|
|
assert(calls > 0)
|
|
print('Unmodified core: stock map discovery invoked the pfQuest canvas GetScript '..calls..' times')
|
|
return
|
|
end
|
|
assert(rawget(canvas, 'GetScript') == nil and rawget(filter, 'GetScript') == nil,
|
|
'stock navigation would resolve an addon function instead of the widget GetScript')
|
|
assert(canvas.GetScript == widget.GetScript and pin.GetScript == widget.GetScript)
|
|
local mouseHandler = function() end
|
|
filter:SetScript('OnMouseDown', mouseHandler)
|
|
assert(e.pfQuestGetFrameScript(filter, 'OnMouseDown') == mouseHandler)
|
|
assert(filter:GetScript('OnMouseDown') ~= mouseHandler)
|
|
assert(e.pfQuestGetFrameScript(filter, 'OnMouseUp') == nil)
|
|
local nativeSelf
|
|
widget.SetScript(pin, 'OnEnter', function(self) nativeSelf = self end)
|
|
e.pfQuestGetFrameScript(pin, 'OnEnter')()
|
|
assert(nativeSelf == pin)
|
|
filter:SetScript('OnMouseDown', nil)
|
|
assert(filter:GetScript('OnMouseDown') == nil and e.pfQuestGetFrameScript(filter, 'OnMouseDown') == nil)
|
|
filter:SetScript('OnMouseDown', mouseHandler)
|
|
local nativeOnHide = function() end
|
|
widget.SetScript(map, 'OnHide', nativeOnHide)
|
|
local proxy = e.WorldMapFrame
|
|
local hookCount = #(map.hooks.OnHide or {})
|
|
proxy:SetScript('OnHide', function() end)
|
|
assert(map:GetScript('OnHide') == nativeOnHide and #map.hooks.OnHide == hookCount+1)
|
|
local nativeScale = map.SetScale
|
|
proxy.SetScale = function() end
|
|
assert(map.SetScale == nativeScale)
|
|
e.SetMapToCurrentZone()
|
|
assert(not map:IsShown() and #navigation == 0)
|
|
e.pfQuestOpenWorldMap()
|
|
e.SetMapZoom(0)
|
|
assert(map:GetMapID() == 947 and #navigation == 2)
|
|
e.SetMapZoom(0)
|
|
assert(#navigation == 2)
|
|
e.pfQuestOpenQuest(7441)
|
|
assert(navigation[3] == 'quest' and navigation[4] == 7441)
|
|
map:Hide()
|
|
g.InCombatLockdown = function() return true end
|
|
e.pfQuestOpenWorldMap(1453)
|
|
e.pfQuestOpenQuest(7441)
|
|
assert(not map:IsShown() and #navigation == 4)
|
|
if stock then
|
|
local util = loadIn(stock..'/blizzard_gamepadsmartnavigation/utility.lua')
|
|
g.IsEmptyTable = function(t) return next(t) == nil end
|
|
g.SmartNavigation_MarkFrameSubSection(map.ScrollContainer, 'map')
|
|
local groups = util.FindButtonGroups(map)
|
|
assert(groups.mainGroup.buttons[1] == filter and groups.subGroups.map.buttons[1] == pin)
|
|
assert(scriptReads[canvas] >= 2 and scriptReads[filter] >= 1)
|
|
g.GamepadSharedUtility = {BindingStack={}}
|
|
g.InputUtil = {RegisterForInterfaceTransitions=noop, RegisterGamepadInit=noop, RegisterGamepadUninit=noop}
|
|
g.InGlue = function() return false end
|
|
loadIn(stock..'/blizzard_gamepadsharedutility/inputbindingstack/inputbindingmanager.lua')
|
|
loadIn(stock..'/blizzard_gamepadactionbars/mainactionbarframe.lua')
|
|
local manager = g.GamepadSharedUtility.InputBindingManager
|
|
local bars = {topBar={Right={ActionButton1={SpecialActionIcon={SetTexture=noop}}}}}
|
|
local bar = {GetActionBars=function() return bars end}
|
|
g.UnitExists = function(unit) return unit == 'target' end
|
|
g.UnitIsGameObject, g.UnitHasLootInteraction, g.UnitIsInInteractRange = noop, noop, noop
|
|
g.UnitIsInteractable = function() return true end
|
|
g.SetUnitCursorTexture = function() return true end
|
|
g.EventRegistry = {TriggerEvent=noop}
|
|
local calls = {}
|
|
g.SetPreferredGamepadInteractTarget = function(unit) calls[#calls+1] = unit or false end
|
|
manager:BindToCoreBindingActive(function() g.GamepadMainActionBarFrameMixin.UpdateInteractIcons(bar) end)
|
|
local set = {type='InputBindingSet', BindAll=noop, Iterator=function() return pairs({}) end}
|
|
manager:AddBindingSet(set)
|
|
manager:RemoveSet(set)
|
|
assert(#calls == 2 and calls[1] == false and calls[2] == 'target')
|
|
print('70334 native button discovery and core-binding add/remove with original interact-icon routine PASS')
|
|
end
|
|
print('WorldMap script ownership, handler chaining, navigation, quest selection and combat guards PASS')
|