Skip to content

Commit 30daab7

Browse files
committed
Move HeadlessWrapper.lua dummy functions to def file
1 parent d24ba6f commit 30daab7

2 files changed

Lines changed: 165 additions & 198 deletions

File tree

src/HeadlessWrapper.lua

Lines changed: 18 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,23 @@
11
#@
2+
---@diagnostic disable: lowercase-global
23
-- This wrapper allows the program to run headless on any OS (in theory)
34
-- It can be run using a standard lua interpreter, although LuaJIT is preferable
45

6+
-- define global simplegraphic API functions. some of these have dummy function
7+
-- bodies intended for headless use.
8+
dofile("_SimpleGraphic.def.lua")
59

6-
-- Callbacks
7-
local callbackTable = { }
8-
local mainObject
9-
function runCallback(name, ...)
10-
if callbackTable[name] then
11-
return callbackTable[name](...)
12-
elseif mainObject and mainObject[name] then
13-
return mainObject[name](mainObject, ...)
14-
end
15-
end
16-
function SetCallback(name, func)
17-
callbackTable[name] = func
18-
end
19-
function GetCallback(name)
20-
return callbackTable[name]
21-
end
22-
function SetMainObject(obj)
23-
mainObject = obj
24-
end
25-
26-
-- Image Handles
27-
local imageHandleClass = { }
28-
imageHandleClass.__index = imageHandleClass
29-
function NewImageHandle()
30-
return setmetatable({ }, imageHandleClass)
31-
end
32-
function imageHandleClass:Load(fileName, ...)
33-
self.valid = true
34-
end
35-
function imageHandleClass:Unload()
36-
self.valid = false
37-
end
38-
function imageHandleClass:IsValid()
39-
return self.valid
40-
end
41-
function imageHandleClass:SetLoadingPriority(pri) end
42-
function imageHandleClass:ImageSize()
43-
return 1, 1
44-
end
45-
46-
-- Rendering
47-
function RenderInit(flag, ...) end
48-
function GetScreenSize()
49-
return 1920, 1080
50-
end
51-
function GetScreenScale()
52-
return 1
53-
end
54-
function GetVirtualScreenSize()
55-
return GetScreenSize()
56-
end
57-
function GetDPIScaleOverridePercent()
58-
return 1
59-
end
60-
function SetDPIScaleOverridePercent(scale) end
61-
function SetClearColor(r, g, b, a) end
62-
function SetDrawLayer(layer, subLayer) end
63-
function SetViewport(x, y, width, height) end
64-
function SetDrawColor(r, g, b, a) end
65-
function DrawImage(imgHandle, left, top, width, height, tcLeft, tcTop, tcRight, tcBottom) end
66-
function DrawImageQuad(imageHandle, x1, y1, x2, y2, x3, y3, x4, y4, s1, t1, s2, t2, s3, t3, s4, t4) end
67-
function DrawString(left, top, align, height, font, text) end
68-
function DrawStringWidth(height, font, text)
69-
return 1
70-
end
71-
function DrawStringCursorIndex(height, font, text, cursorX, cursorY)
72-
return 0
73-
end
74-
function StripEscapes(text)
75-
return text:gsub("%^%d",""):gsub("%^x%x%x%x%x%x%x","")
76-
end
77-
function GetAsyncCount()
78-
return 0
79-
end
8010

81-
-- Search Handles
82-
function NewFileSearch() end
11+
-- Callbacks
12+
__callbackTable__ = { }
8313

84-
-- General Functions
85-
function SetWindowTitle(title) end
86-
function GetCursorPos()
87-
return 0, 0
88-
end
89-
function SetCursorPos(x, y) end
90-
function ShowCursor(doShow) end
91-
function IsKeyDown(keyName) end
92-
function Copy(text) end
93-
function Paste() end
94-
function Deflate(data)
95-
-- TODO: Might need this
96-
return ""
97-
end
98-
function Inflate(data)
99-
-- TODO: And this
100-
return ""
101-
end
102-
function GetTime()
103-
return 0
104-
end
105-
function GetScriptPath()
106-
return ""
107-
end
108-
function GetRuntimePath()
109-
return ""
110-
end
111-
function GetUserPath()
112-
return ""
113-
end
114-
function MakeDir(path) end
115-
function RemoveDir(path) end
116-
function SetWorkDir(path) end
117-
function GetWorkDir()
118-
return ""
119-
end
120-
function LaunchSubScript(scriptText, funcList, subList, ...) end
121-
function AbortSubScript(ssID) end
122-
function IsSubScriptRunning(ssID) end
123-
function LoadModule(fileName, ...)
124-
if not fileName:match("%.lua") then
125-
fileName = fileName .. ".lua"
126-
end
127-
local func, err = loadfile(fileName)
128-
if func then
129-
return func(...)
130-
else
131-
error("LoadModule() error loading '"..fileName.."': "..err)
132-
end
133-
end
134-
function PLoadModule(fileName, ...)
135-
if not fileName:match("%.lua") then
136-
fileName = fileName .. ".lua"
137-
end
138-
local func, err = loadfile(fileName)
139-
if func then
140-
return PCall(func, ...)
141-
else
142-
error("PLoadModule() error loading '"..fileName.."': "..err)
143-
end
144-
end
145-
function PCall(func, ...)
146-
local ret = { pcall(func, ...) }
147-
if ret[1] then
148-
table.remove(ret, 1)
149-
return nil, unpack(ret)
150-
else
151-
return ret[2]
14+
function runCallback(name, ...)
15+
if __callbackTable__[name] then
16+
return __callbackTable__[name](...)
17+
elseif __mainObject__ and __mainObject__[name] then
18+
return __mainObject__[name](__mainObject__, ...)
15219
end
15320
end
154-
function ConPrintf(fmt, ...)
155-
-- Optional
156-
print(string.format(fmt, ...))
157-
end
158-
function ConPrintTable(tbl, noRecurse) end
159-
function ConExecute(cmd) end
160-
function ConClear() end
161-
function SpawnProcess(cmdName, args) end
162-
function OpenURL(url) end
163-
function SetProfiling(isEnabled) end
164-
function Restart() end
165-
function Exit() end
166-
function TakeScreenshot() end
167-
168-
---@return string? provider
169-
---@return string? version
170-
---@return number? status
171-
function GetCloudProvider(fullPath)
172-
return nil, nil, nil
173-
end
174-
17521

17622
local l_require = require
17723
function require(name)
@@ -188,32 +34,32 @@ dofile("Launch.lua")
18834
-- Prevents loading of ModCache
18935
-- Allows running mod parsing related tests without pushing ModCache
19036
-- The CI env var will be true when run from github workflows but should be false for other tools using the headless wrapper
191-
mainObject.continuousIntegrationMode = os.getenv("CI")
37+
__mainObject__.continuousIntegrationMode = os.getenv("CI")
19238

19339
runCallback("OnInit")
19440
runCallback("OnFrame") -- Need at least one frame for everything to initialise
19541

196-
if mainObject.promptMsg then
42+
if __mainObject__.promptMsg then
19743
-- Something went wrong during startup
198-
print(mainObject.promptMsg)
44+
print(__mainObject__.promptMsg)
19945
io.read("*l")
20046
return
20147
end
20248

20349
-- The build module; once a build is loaded, you can find all the good stuff in here
204-
build = mainObject.main.modes["BUILD"]
50+
build = __mainObject__.main.modes["BUILD"]
20551

20652
-- Here's some helpful helper functions to help you get started
20753
function newBuild()
208-
mainObject.main:SetMode("BUILD", false, "Help, I'm stuck in Path of Building!")
54+
__mainObject__.main:SetMode("BUILD", false, "Help, I'm stuck in Path of Building!")
20955
runCallback("OnFrame")
21056
end
21157
function loadBuildFromXML(xmlText, name)
212-
mainObject.main:SetMode("BUILD", false, name or "", xmlText)
58+
__mainObject__.main:SetMode("BUILD", false, name or "", xmlText)
21359
runCallback("OnFrame")
21460
end
21561
function loadBuildFromJSON(getItemsJSON, getPassiveSkillsJSON)
216-
mainObject.main:SetMode("BUILD", false, "")
62+
__mainObject__.main:SetMode("BUILD", false, "")
21763
runCallback("OnFrame")
21864
local charData = build.importTab:ImportItemsAndSkills(getItemsJSON)
21965
build.importTab:ImportPassiveTreeAndJewels(getPassiveSkillsJSON, charData)

0 commit comments

Comments
 (0)