forked from jeffi/Bastion
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
929 B
44 lines
929 B
---@type Tinkr
|
|
local Tinkr,
|
|
---@class Bastion
|
|
Bastion = ...
|
|
|
|
-- Create an APL trait for the APL class
|
|
---@class Bastion.APLTrait
|
|
---@field cb fun(actor?: Bastion.APLActor.Table):boolean
|
|
---@field lastcall number
|
|
local APLTrait = {}
|
|
APLTrait.__index = APLTrait
|
|
|
|
-- Constructor
|
|
---@param cb fun(actor?: Bastion.APLActor.Table):boolean
|
|
---@return Bastion.APLTrait
|
|
function APLTrait:New(cb)
|
|
local self = setmetatable({}, APLTrait)
|
|
|
|
self.cb = cb
|
|
self.lastcall = 0
|
|
|
|
return self
|
|
end
|
|
|
|
-- Evaulate the APL trait
|
|
---@param actor? Bastion.APLActor.Table
|
|
---@return boolean
|
|
function APLTrait:Evaluate(actor)
|
|
if GetTime() - self.lastcall > 0.1 then
|
|
self.lastresult = self.cb(actor)
|
|
self.lastcall = GetTime()
|
|
return self.lastresult
|
|
end
|
|
|
|
return self.lastresult
|
|
end
|
|
|
|
-- tostring
|
|
---@return string
|
|
function APLTrait:__tostring()
|
|
return "Bastion.__APLTrait"
|
|
end
|
|
|
|
Bastion.APLTrait = APLTrait
|
|
|