From 4eb48c24d20b6cd690bc4891aeee7ec004fb8b06 Mon Sep 17 00:00:00 2001 From: Buurazu Date: Fri, 28 Jan 2022 16:47:28 -0500 Subject: [PATCH] add Coroutine manager --- eid_api.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/eid_api.lua b/eid_api.lua index d0fbe402..e7691001 100644 --- a/eid_api.lua +++ b/eid_api.lua @@ -1228,3 +1228,20 @@ function EID:setModIndicatorIcon(iconMarkup, override) if EID.ModIndicator[EID._currentMod].Icon ~= nil and override == false then return end EID.ModIndicator[EID._currentMod].Icon = iconMarkup end + +EID.Coroutines = {} +-- Add a coroutine to be ran 60 times a second +function EID:addCoroutine(name, func, overwrite) + if overwrite or EID.Coroutines[name] == nil then EID.Coroutines[name] = coroutine.create(func) end +end + +function EID:removeCoroutine(name) + EID.Coroutines[name] = nil +end + +-- ran 60 times a second in main game render +function EID:resumeCoroutines() + for k,v in pairs(EID.Coroutines) do + if coroutine.resume(v) == false then EID:removeCoroutine(k) end + end +end