-- Compiled with roblox-ts v2.0.4 local TS = _G[script] local Proton = TS.import(script, script.Parent, "core").Proton --[[ * * The execution behavior of a custom lifecycle. ]] local LifecycleBehavior do local _inverse = {} LifecycleBehavior = setmetatable({}, { __index = _inverse, }) LifecycleBehavior.Series = 0 _inverse[0] = "Series" LifecycleBehavior.Concurrent = 1 _inverse[1] = "Concurrent" end --[[ * * Custom lifecycle for Proton providers. ]] local ProtonLifecycle do ProtonLifecycle = setmetatable({}, { __tostring = function() return "ProtonLifecycle" end, }) ProtonLifecycle.__index = ProtonLifecycle function ProtonLifecycle.new(...) local self = setmetatable({}, ProtonLifecycle) return self:constructor(...) or self end function ProtonLifecycle:constructor(behavior) if behavior == nil then behavior = LifecycleBehavior.Concurrent end self.callbacks = {} self.onRegisteredCallbacks = {} self.onUnregisteredCallbacks = {} repeat if behavior == (LifecycleBehavior.Series) then self.fire = self.fireSeries break end if behavior == (LifecycleBehavior.Concurrent) then self.fire = self.fireConcurrent break end until true end function ProtonLifecycle:callOnUnregisteredCallbacks(callback) for _, onUnregistered in self.onUnregisteredCallbacks do onUnregistered(callback) end end function ProtonLifecycle:fireConcurrent(...) local args = { ... } for _, callback in self.callbacks do task.spawn(function() debug.setmemorycategory(callback.memoryCategory) callback.callback(unpack(args)) end) end end function ProtonLifecycle:fireSeries(...) local args = { ... } for _, callback in self.callbacks do debug.setmemorycategory(callback.memoryCategory) callback.callback(unpack(args)) debug.resetmemorycategory() end end function ProtonLifecycle:fire(...) local args = { ... } end function ProtonLifecycle:register(callback, memoryCategory) local _callbacks = self.callbacks local _arg0 = { callback = callback, memoryCategory = memoryCategory, } table.insert(_callbacks, _arg0) for _, onRegistered in self.onRegisteredCallbacks do onRegistered(callback) end end function ProtonLifecycle:unregister(callback) local _callbacks = self.callbacks local _arg0 = function(item) return item.callback == callback end -- ▼ ReadonlyArray.findIndex ▼ local _result = -1 for _i, _v in _callbacks do if _arg0(_v, _i - 1, _callbacks) == true then _result = _i - 1 break end end -- ▲ ReadonlyArray.findIndex ▲ local index = _result if index == -1 then return nil end -- ▼ Array.unorderedRemove ▼ local _index = index + 1 local _exp = self.callbacks local _length = #_exp local _value = _exp[_index] if _value ~= nil then _exp[_index] = _exp[_length] _exp[_length] = nil end -- ▲ Array.unorderedRemove ▲ self:callOnUnregisteredCallbacks(callback) end function ProtonLifecycle:unregisterAll() for _, callback in self.callbacks do self:callOnUnregisteredCallbacks(callback.callback) end table.clear(self.callbacks) end function ProtonLifecycle:onRegistered(callback) local _onRegisteredCallbacks = self.onRegisteredCallbacks local _callback = callback table.insert(_onRegisteredCallbacks, _callback) return function() local _onRegisteredCallbacks_1 = self.onRegisteredCallbacks local _callback_1 = callback local index = (table.find(_onRegisteredCallbacks_1, _callback_1) or 0) - 1 if index == -1 then return nil end -- ▼ Array.unorderedRemove ▼ local _index = index + 1 local _exp = self.onRegisteredCallbacks local _length = #_exp local _value = _exp[_index] if _value ~= nil then _exp[_index] = _exp[_length] _exp[_length] = nil end -- ▲ Array.unorderedRemove ▲ end end function ProtonLifecycle:onUnregistered(callback) local _onUnregisteredCallbacks = self.onUnregisteredCallbacks local _callback = callback table.insert(_onUnregisteredCallbacks, _callback) return function() local _onUnregisteredCallbacks_1 = self.onUnregisteredCallbacks local _callback_1 = callback local index = (table.find(_onUnregisteredCallbacks_1, _callback_1) or 0) - 1 if index == -1 then return nil end -- ▼ Array.unorderedRemove ▼ local _index = index + 1 local _exp = self.onUnregisteredCallbacks local _length = #_exp local _value = _exp[_index] if _value ~= nil then _exp[_index] = _exp[_length] _exp[_length] = nil end -- ▲ Array.unorderedRemove ▲ end end end --[[ * * OnLifecycle decorator. * @param lifecycle Attached lifecycle ]] local function Lifecycle(lifecycle) return function(target, property, descriptor) lifecycle:register((function(...) local args = { ... } descriptor.value(Proton.get(target), unpack(args)) end), tostring(target)) end end local ProtonStart = ProtonLifecycle.new(LifecycleBehavior.Concurrent) Proton.onStart(function() return ProtonStart:fire() end) return { Lifecycle = Lifecycle, LifecycleBehavior = LifecycleBehavior, ProtonLifecycle = ProtonLifecycle, ProtonStart = ProtonStart, }