add reset(); slightly refactor actor loading
This commit is contained in:
parent
6d5b05102f
commit
c575751e93
|
@ -75,20 +75,57 @@
|
||||||
self:hidden(1)
|
self:hidden(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local actorsInitialized = false -- if true, no new actors can be created
|
||||||
|
|
||||||
local luaobj
|
local luaobj
|
||||||
|
|
||||||
local globalQueue = {} -- for resetting
|
local globalQueue = {} -- for resetting
|
||||||
|
|
||||||
|
local patchedFunctions = {}
|
||||||
local function patchFunction(f, obj)
|
local function patchFunction(f, obj)
|
||||||
return function(...)
|
if not patchedFunctions[f] then patchedFunctions[f] = {} end
|
||||||
arg[1] = obj
|
if not patchedFunctions[f][obj] then
|
||||||
return f(unpack(arg))
|
patchedFunctions[f][obj] = function(...)
|
||||||
|
arg[1] = obj
|
||||||
|
local results
|
||||||
|
local status, result = pcall(function()
|
||||||
|
-- doing it this way instead of returning because lua
|
||||||
|
-- offers no way of grabbing everything BUT the first
|
||||||
|
-- argument out of pcall
|
||||||
|
results = {f(unpack(arg))}
|
||||||
|
end)
|
||||||
|
if not status then
|
||||||
|
error(result, 2)
|
||||||
|
else
|
||||||
|
return unpack(results)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return patchedFunctions[f][obj]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCommand(self)
|
local function onCommand(self)
|
||||||
|
actorsInitialized = true
|
||||||
uranium:call('init')
|
uranium:call('init')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function reset(actor)
|
||||||
|
if not actorsInitialized then error('uranium: cannot reset an actor during initialization', 2) end
|
||||||
|
for _, q in ipairs(globalQueue) do
|
||||||
|
local queueActor = q[1]
|
||||||
|
if queueActor == actor.__raw then
|
||||||
|
local v = q[2]
|
||||||
|
|
||||||
|
local func = queueActor[v[1]]
|
||||||
|
if not func then
|
||||||
|
-- uhmmm ??? hm. what do we do??
|
||||||
|
else
|
||||||
|
patchFunction(func, queueActor)(unpack(v[2]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- runs once during ScreenReadyCommand, before the user code is loaded
|
-- runs once during ScreenReadyCommand, before the user code is loaded
|
||||||
-- hides various actors that are placed by the theme
|
-- hides various actors that are placed by the theme
|
||||||
local function hideThemeActors()
|
local function hideThemeActors()
|
||||||
|
@ -297,24 +334,28 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
function oat._actor.initFrame(self)
|
function oat._actor.initFrame(self)
|
||||||
self:SetDrawFunction(function() end)
|
local nextChild = self(2)
|
||||||
|
self:SetDrawFunction(function()
|
||||||
|
if nextChild then
|
||||||
|
nextChild:Draw()
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createProxyActor(name)
|
local function createProxyActor(name)
|
||||||
local queue = {}
|
local queue = {}
|
||||||
local initCommands = {}
|
local initCommands = {}
|
||||||
local lockedActor
|
local lockedActor
|
||||||
local patchedFunctions = {}
|
|
||||||
|
|
||||||
return setmetatable({}, {
|
return setmetatable({}, {
|
||||||
__index = function(self, key)
|
__index = function(self, key)
|
||||||
|
if key == '__raw' then
|
||||||
|
return lockedActor
|
||||||
|
end
|
||||||
if lockedActor then
|
if lockedActor then
|
||||||
local val = lockedActor[key]
|
local val = lockedActor[key]
|
||||||
if type(val) == 'function' then
|
if type(val) == 'function' then
|
||||||
if not patchedFunctions[val] then
|
return patchFunction(val, lockedActor)
|
||||||
patchedFunctions[val] = patchFunction(val, lockedActor)
|
|
||||||
end
|
|
||||||
return patchedFunctions[val]
|
|
||||||
end
|
end
|
||||||
return val
|
return val
|
||||||
end
|
end
|
||||||
|
@ -380,6 +421,7 @@
|
||||||
|
|
||||||
local function createGenericFunc(type)
|
local function createGenericFunc(type)
|
||||||
return function()
|
return function()
|
||||||
|
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||||
local actor = createProxyActor(type)
|
local actor = createProxyActor(type)
|
||||||
table.insert(actorQueue, {
|
table.insert(actorQueue, {
|
||||||
type = type,
|
type = type,
|
||||||
|
@ -397,6 +439,7 @@
|
||||||
Polygon = createGenericFunc('Polygon')
|
Polygon = createGenericFunc('Polygon')
|
||||||
|
|
||||||
function Sprite(file)
|
function Sprite(file)
|
||||||
|
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||||
if not file then error('uranium: cannot create a Sprite without a file', 2) end
|
if not file then error('uranium: cannot create a Sprite without a file', 2) end
|
||||||
local actor = createProxyActor('Sprite')
|
local actor = createProxyActor('Sprite')
|
||||||
table.insert(actorQueue, {
|
table.insert(actorQueue, {
|
||||||
|
@ -410,6 +453,7 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
function Model(file)
|
function Model(file)
|
||||||
|
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||||
if not file then error('uranium: cannot create a Model without a file', 2) end
|
if not file then error('uranium: cannot create a Model without a file', 2) end
|
||||||
local actor = createProxyActor('Model')
|
local actor = createProxyActor('Model')
|
||||||
table.insert(actorQueue, {
|
table.insert(actorQueue, {
|
||||||
|
@ -423,6 +467,7 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
function BitmapText(font, text)
|
function BitmapText(font, text)
|
||||||
|
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||||
local actor = createProxyActor('BitmapText')
|
local actor = createProxyActor('BitmapText')
|
||||||
table.insert(actorQueue, {
|
table.insert(actorQueue, {
|
||||||
type = 'BitmapText',
|
type = 'BitmapText',
|
||||||
|
@ -436,6 +481,7 @@
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActorSound(file)
|
function ActorSound(file)
|
||||||
|
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||||
if not file then error('uranium: cannot create an ActorSound without a file', 2) end
|
if not file then error('uranium: cannot create an ActorSound without a file', 2) end
|
||||||
local actor = createProxyActor('ActorSound')
|
local actor = createProxyActor('ActorSound')
|
||||||
table.insert(actorQueue, {
|
table.insert(actorQueue, {
|
||||||
|
|
|
@ -33,6 +33,10 @@ function BitmapText(font, text) end
|
||||||
--- Defines an ActorSound actor.
|
--- Defines an ActorSound actor.
|
||||||
function ActorSound(file) end
|
function ActorSound(file) end
|
||||||
|
|
||||||
|
---@param actor Actor
|
||||||
|
--- Resets an actor to its initial state
|
||||||
|
function reset(actor) end
|
||||||
|
|
||||||
---@type number
|
---@type number
|
||||||
--- A simple timer. Ticks upwards at a rate of 1/sec.
|
--- A simple timer. Ticks upwards at a rate of 1/sec.
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue