Skip to content

Commit

Permalink
Framework update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Sep 29, 2024
1 parent 5527897 commit b196e15
Show file tree
Hide file tree
Showing 3 changed files with 432 additions and 42 deletions.
62 changes: 52 additions & 10 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 569
local dversion = 571
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down Expand Up @@ -5456,6 +5456,7 @@ do
--need to create the new object
local newObject = self.newObjectFunc(self, unpack(self.payload))
if (newObject) then
self.objectsCreated = self.objectsCreated + 0
table.insert(self.inUse, newObject)
if (self.onAcquire) then
DF:QuickDispatch(self.onAcquire, newObject)
Expand Down Expand Up @@ -5513,6 +5514,32 @@ do
return #self.notUse + #self.inUse, #self.notUse, #self.inUse
end

---@class df_pool : table
---@field objectsCreated number --amount of objects created
---@field inUse table[] --objects in use
---@field notUse table[] --objects not in use
---@field payload table --payload to be sent to the newObjectFunc
---@field onRelease fun(object:table) --function to be called when an object is released
---@field onReset fun(object:table) --function to be called when the pool is reset
---@field onAcquire fun(object:table) --function to be called when an object is acquired
---@field newObjectFunc fun(self:df_pool, ...):table --function to create a new object, it passes the pool and the payload
---@field PoolConstructor fun(self:df_pool, func:fun(object:table), ...:any) --constructor, in case to use an existing object to behave like a pool
---@field Get fun(self:df_pool):table --return an object from the pool
---@field Acquire fun(self:df_pool):table --alias for :Get()
---@field GetAllInUse fun(self:df_pool):table[] --return all objects in use
---@field Release fun(self:df_pool, object:table) --release a single object
---@field Reset fun(self:df_pool) --release all objects and calls OnReset function if any
---@field ReleaseAll fun(self:df_pool) --alias for :Reset()
---@field Hide fun(self:df_pool) --hide all objects in use by calling object:Hide()
---@field Show fun(self:df_pool) --show all objects in use by calling object:Show()
---@field GetAmount fun(self:df_pool):number, number, number --return the amount of objects in the pool in use + not in use, not in use, in use
---@field SetOnRelease fun(self:df_pool, func:fun(object:table)) --set a function to be called when an object is released
---@field SetCallbackOnRelease fun(self:df_pool, func:fun(object:table)) --set a function to be called when an object is released
---@field SetOnReset fun(self:df_pool, func:fun(object:table)) --set a function to be called when the pool is reset
---@field SetCallbackOnReleaseAll fun(self:df_pool, func:fun(object:table)) --alias for :SetOnReset()
---@field SetOnAcquire fun(self:df_pool, func:fun(object:table)) --set a function to be called when an object is acquired
---@field SetCallbackOnGet fun(self:df_pool, func:fun(object:table)) --alias for :SetOnAcquire()
---@field RunForInUse fun(self:df_pool, func:fun(object:table)) --run a function for each object in use
local poolMixin = {
Get = get,
GetAllInUse = get_all_inuse,
Expand All @@ -5524,6 +5551,10 @@ do
Show = show,
GetAmount = getamount,

SetOnRelease = function(self, func)
self.onRelease = func
end,

SetCallbackOnRelease = function(self, func)
self.onRelease = func
end,
Expand All @@ -5541,18 +5572,29 @@ do
SetCallbackOnGet = function(self, func)
self.onAcquire = func
end,
}

function DF:CreatePool(func, ...)
local t = {}
DetailsFramework:Mixin(t, poolMixin)
RunForInUse = function(self, func)
for i = 1, #self.inUse do
func(self.inUse[i])
end
end,

t.inUse = {}
t.notUse = {}
t.newObjectFunc = func
t.payload = {...}
PoolConstructor = function(self, func, ...)
self.objectsCreated = 0
self.inUse = {}
self.notUse = {}
self.payload = {...}
self.newObjectFunc = func
end,
}

return t
DF.PoolMixin = poolMixin

function DF:CreatePool(func, ...)
local newPool = {}
DetailsFramework:Mixin(newPool, poolMixin)
newPool:PoolConstructor(func, ...)
return newPool
end

--alias
Expand Down
6 changes: 4 additions & 2 deletions Libs/DF/normal_bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,16 @@ DF:Mixin(BarMetaFunctions, DF.ScriptHookMixin)
self.timer = true

self.HasTimer = true
self.TimerScheduled = DF:ScheduleTimer("StartTimeBarAnimation", 0.1, self)
C_Timer.After(0.1, function()
DF:StartTimeBarAnimation(self)
end)
end

function DF:StartTimeBarAnimation (timebar)
timebar.TimerScheduled = nil
timebar.statusbar:SetScript("OnUpdate", OnUpdate)
end

------------------------------------------------------------------------------------------------------------
--object constructor

Expand Down
Loading

0 comments on commit b196e15

Please sign in to comment.