More bug fixes for destroyed combats; TimeData code modernizations
This commit is contained in:
+95
-80
@@ -7,16 +7,30 @@
|
||||
--create a namespace
|
||||
Details222.TimeCapture = {}
|
||||
|
||||
--mantain the enabled time captures
|
||||
Details.timeContainer = {}
|
||||
Details.timeContainer.Exec = {}
|
||||
---@class timedataexec : table
|
||||
---@field func function
|
||||
---@field data table
|
||||
---@field attributes table
|
||||
---@field is_user boolean
|
||||
|
||||
---mantain the enabled time captures
|
||||
---@class timedatacontainer : table
|
||||
---@field Exec timedataexec[]
|
||||
|
||||
---@class timedatasaved : {key1: string, key2: function, key3: table, key4: string, key5: string, key6: string, key7: boolean}
|
||||
---@field do_not_save boolean
|
||||
|
||||
do
|
||||
---@type timedatacontainer
|
||||
local timeContainer = {}
|
||||
Details.timeContainer = timeContainer
|
||||
Details.timeContainer.Exec = {}
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--local pointers
|
||||
local ipairs = ipairs
|
||||
local _math_floor = math.floor
|
||||
local _pcall = pcall
|
||||
local time = time
|
||||
local pcall = pcall
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--constants
|
||||
@@ -29,44 +43,47 @@
|
||||
local INDEX_ICON = 6
|
||||
local INDEX_ENABLED = 7
|
||||
|
||||
local DEFAULT_USER_MATRIX = {max_value = 0, last_value = 0}
|
||||
local DEFAULT_USER_MATRIX = {
|
||||
max_value = 0,
|
||||
last_value = 0
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
--register and unregister captures
|
||||
|
||||
|
||||
function Details:TimeDataUpdate (index_or_name, name, func, matrix, author, version, icon, is_enabled)
|
||||
|
||||
local this_capture
|
||||
local thisCapture
|
||||
if (type(index_or_name) == "number") then
|
||||
this_capture = Details.savedTimeCaptures [index_or_name]
|
||||
thisCapture = Details.savedTimeCaptures[index_or_name]
|
||||
else
|
||||
for index, t in ipairs(Details.savedTimeCaptures) do
|
||||
if (t [INDEX_NAME] == index_or_name) then
|
||||
this_capture = t
|
||||
for index, timeDataSaved in ipairs(Details.savedTimeCaptures) do
|
||||
---@cast timeDataSaved timedatasaved
|
||||
if (timeDataSaved [INDEX_NAME] == index_or_name) then
|
||||
thisCapture = timeDataSaved
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (not this_capture) then
|
||||
if (not thisCapture) then
|
||||
return false
|
||||
end
|
||||
|
||||
if (this_capture.do_not_save) then
|
||||
if (thisCapture.do_not_save) then
|
||||
return Details:Msg("This capture belongs to a plugin and cannot be edited.")
|
||||
end
|
||||
|
||||
this_capture [INDEX_NAME] = name or this_capture [INDEX_NAME]
|
||||
this_capture [INDEX_FUNCTION] = func or this_capture [INDEX_FUNCTION]
|
||||
this_capture [INDEX_MATRIX] = matrix or this_capture [INDEX_MATRIX]
|
||||
this_capture [INDEX_AUTHOR] = author or this_capture [INDEX_AUTHOR]
|
||||
this_capture [INDEX_VERSION] = version or this_capture [INDEX_VERSION]
|
||||
this_capture [INDEX_ICON] = icon or this_capture [INDEX_ICON]
|
||||
thisCapture[INDEX_NAME] = name or thisCapture[INDEX_NAME]
|
||||
thisCapture[INDEX_FUNCTION] = func or thisCapture[INDEX_FUNCTION]
|
||||
thisCapture[INDEX_MATRIX] = matrix or thisCapture[INDEX_MATRIX]
|
||||
thisCapture[INDEX_AUTHOR] = author or thisCapture[INDEX_AUTHOR]
|
||||
thisCapture[INDEX_VERSION] = version or thisCapture[INDEX_VERSION]
|
||||
thisCapture[INDEX_ICON] = icon or thisCapture[INDEX_ICON]
|
||||
|
||||
if (is_enabled ~= nil) then
|
||||
this_capture [INDEX_ENABLED] = is_enabled
|
||||
thisCapture[INDEX_ENABLED] = is_enabled
|
||||
else
|
||||
this_capture [INDEX_ENABLED] = this_capture [INDEX_ENABLED]
|
||||
thisCapture[INDEX_ENABLED] = thisCapture[INDEX_ENABLED]
|
||||
end
|
||||
|
||||
if (_G.DetailsOptionsWindow and _G.DetailsOptionsWindow:IsShown()) then
|
||||
@@ -74,41 +91,40 @@
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
--matrix = table containing {max_value = 0, last_value = 0}
|
||||
function Details:TimeDataRegister(name, func, matrix, author, version, icon, is_enabled, force_no_save)
|
||||
function Details:TimeDataRegister(timeDataName, callbackFunc, matrix, author, version, icon, bIsEnabled, bForceNoSave)
|
||||
--check name
|
||||
if (not name) then
|
||||
if (not timeDataName) then
|
||||
return "Couldn't register the time capture, name was nil."
|
||||
end
|
||||
|
||||
--check if the name already exists
|
||||
for index, t in ipairs(Details.savedTimeCaptures) do
|
||||
if (t [INDEX_NAME] == name) then
|
||||
if (t [INDEX_NAME] == timeDataName) then
|
||||
return "Couldn't register the time capture, name already registred."
|
||||
end
|
||||
end
|
||||
|
||||
--check function
|
||||
if (not func) then
|
||||
if (not callbackFunc) then
|
||||
return "Couldn't register the time capture, invalid function."
|
||||
end
|
||||
|
||||
local no_save = nil
|
||||
--passed a function means that this isn't came from a user
|
||||
--so the plugin register the capture every time it loads.
|
||||
if (type(func) == "function") then
|
||||
if (type(callbackFunc) == "function") then
|
||||
no_save = true
|
||||
|
||||
--this a custom capture from a user, so we register a default user table for matrix
|
||||
elseif (type(func) == "string") then
|
||||
elseif (type(callbackFunc) == "string") then
|
||||
matrix = DEFAULT_USER_MATRIX
|
||||
|
||||
end
|
||||
|
||||
if (not no_save and force_no_save) then
|
||||
if (not no_save and bForceNoSave) then
|
||||
no_save = true
|
||||
end
|
||||
|
||||
@@ -121,27 +137,26 @@
|
||||
version = version or "v1.0"
|
||||
icon = icon or [[Interface\InventoryItems\WoWUnknownItem01]]
|
||||
|
||||
tinsert(Details.savedTimeCaptures, {name, func, matrix, author, version, icon, is_enabled, do_not_save = no_save})
|
||||
table.insert(Details.savedTimeCaptures, {timeDataName, callbackFunc, matrix, author, version, icon, bIsEnabled, do_not_save = no_save})
|
||||
|
||||
if (_G.DetailsOptionsWindow and _G.DetailsOptionsWindow:IsShown()) then
|
||||
DetailsOptionsWindowTab17UserTimeCapturesFillPanel.MyObject:Refresh()
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
--unregister
|
||||
function Details:TimeDataUnregister (name)
|
||||
if (type(name) == "number") then
|
||||
tremove(Details.savedTimeCaptures, name)
|
||||
table.remove(Details.savedTimeCaptures, name)
|
||||
if (_G.DetailsOptionsWindow and _G.DetailsOptionsWindow:IsShown()) then
|
||||
DetailsOptionsWindowTab17UserTimeCapturesFillPanel.MyObject:Refresh()
|
||||
end
|
||||
else
|
||||
for index, t in ipairs(Details.savedTimeCaptures) do
|
||||
if (t [INDEX_NAME] == name) then
|
||||
tremove(Details.savedTimeCaptures, index)
|
||||
table.remove(Details.savedTimeCaptures, index)
|
||||
if (_G.DetailsOptionsWindow and _G.DetailsOptionsWindow:IsShown()) then
|
||||
DetailsOptionsWindowTab17UserTimeCapturesFillPanel.MyObject:Refresh()
|
||||
end
|
||||
@@ -154,16 +169,19 @@
|
||||
|
||||
--cleanup when logout
|
||||
function Details:TimeDataCleanUpTemporary()
|
||||
---@type timedatasaved[]
|
||||
local newData = {}
|
||||
for index, t in ipairs(Details.savedTimeCaptures) do
|
||||
if (not t.do_not_save) then
|
||||
tinsert(newData, t)
|
||||
|
||||
for index, timeDataSaved in ipairs(Details.savedTimeCaptures) do
|
||||
if (not timeDataSaved.do_not_save) then
|
||||
table.insert(newData, timeDataSaved)
|
||||
end
|
||||
end
|
||||
|
||||
Details.savedTimeCaptures = newData
|
||||
end
|
||||
|
||||
local tick_time = 0
|
||||
local tickTime = 0
|
||||
|
||||
--starting a combat
|
||||
function Details:TimeDataCreateChartTables()
|
||||
@@ -171,54 +189,58 @@
|
||||
local chartTables = {}
|
||||
|
||||
--drop the last capture exec table without wiping
|
||||
---@type timedataexec
|
||||
local exec = {}
|
||||
|
||||
Details.timeContainer.Exec = exec
|
||||
|
||||
Details:SendEvent("COMBAT_CHARTTABLES_CREATING")
|
||||
|
||||
--build the exec table
|
||||
for index, t in ipairs(Details.savedTimeCaptures) do
|
||||
if (t[INDEX_ENABLED]) then
|
||||
for index, chartData in ipairs(Details.savedTimeCaptures) do
|
||||
if (chartData[INDEX_ENABLED]) then
|
||||
local data = {}
|
||||
chartTables[t[INDEX_NAME]] = data
|
||||
chartTables[chartData[INDEX_NAME]] = data
|
||||
|
||||
if (type(t[INDEX_FUNCTION]) == "string") then
|
||||
if (type(chartData[INDEX_FUNCTION]) == "string") then
|
||||
--user
|
||||
local func, errortext = loadstring(t[INDEX_FUNCTION])
|
||||
local func, errortext = loadstring(chartData[INDEX_FUNCTION])
|
||||
if (func) then
|
||||
DetailsFramework:SetEnvironment(func)
|
||||
tinsert(exec, {func = func, data = data, attributes = Details.CopyTable(t[INDEX_MATRIX]), is_user = true})
|
||||
---@type timedataexec
|
||||
local timeDataTable = {func = func, data = data, attributes = Details.CopyTable(chartData[INDEX_MATRIX]), is_user = true}
|
||||
table.insert(exec, timeDataTable)
|
||||
else
|
||||
Details:Msg("|cFFFF9900error compiling script for time data (charts)|r: ", errortext)
|
||||
end
|
||||
else
|
||||
--plugin
|
||||
local func = t[INDEX_FUNCTION]
|
||||
local func = chartData[INDEX_FUNCTION]
|
||||
DetailsFramework:SetEnvironment(func)
|
||||
tinsert(exec, {func = func, data = data, attributes = Details.CopyTable(t[INDEX_MATRIX])})
|
||||
---@type timedataexec
|
||||
local timeDataTable = {func = func, data = data, attributes = Details.CopyTable(chartData[INDEX_MATRIX])}
|
||||
table.insert(exec, timeDataTable)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Details:SendEvent("COMBAT_CHARTTABLES_CREATED")
|
||||
|
||||
tick_time = 0
|
||||
tickTime = 0
|
||||
|
||||
--return the capture table the to combat object
|
||||
return chartTables
|
||||
end
|
||||
|
||||
local exec_user_func = function(func, attributes, data, this_second)
|
||||
|
||||
local okey, result = _pcall (func, attributes)
|
||||
local execUserFunc = function(func, attributes, data, thisSecond)
|
||||
local okey, result = pcall(func, attributes)
|
||||
if (not okey) then
|
||||
Details:Msg("|cFFFF9900error on chart script function|r:", result)
|
||||
result = 0
|
||||
end
|
||||
|
||||
local current = result - attributes.last_value
|
||||
data [this_second] = current
|
||||
data[thisSecond] = current
|
||||
|
||||
if (current > attributes.max_value) then
|
||||
attributes.max_value = current
|
||||
@@ -226,27 +248,20 @@
|
||||
end
|
||||
|
||||
attributes.last_value = result
|
||||
|
||||
end
|
||||
|
||||
function Details:TimeDataTick()
|
||||
|
||||
tick_time = tick_time + 1
|
||||
|
||||
for index, t in ipairs(Details.timeContainer.Exec) do
|
||||
|
||||
if (t.is_user) then
|
||||
tickTime = tickTime + 1
|
||||
for index, timeDataTable in ipairs(Details.timeContainer.Exec) do
|
||||
---@cast timeDataTable timedataexec
|
||||
if (timeDataTable.is_user) then
|
||||
--by a user
|
||||
exec_user_func (t.func, t.attributes, t.data, tick_time)
|
||||
|
||||
execUserFunc(timeDataTable.func, timeDataTable.attributes, timeDataTable.data, tickTime)
|
||||
else
|
||||
--by a plugin
|
||||
t.func (t.attributes, t.data, tick_time)
|
||||
|
||||
timeDataTable.func(timeDataTable.attributes, timeDataTable.data, tickTime)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -262,7 +277,7 @@
|
||||
if (not combatTime or combatTime == 0) then
|
||||
return 0
|
||||
else
|
||||
return ToKFunctions [Details.minimap.text_format] (_, combat.totals_grupo[1] / combatTime)
|
||||
return ToKFunctions[Details.minimap.text_format](_, combat.totals_grupo[1] / combatTime)
|
||||
end
|
||||
end,
|
||||
-- raid hps [2]
|
||||
@@ -272,7 +287,7 @@
|
||||
if (not combatTime or combatTime == 0) then
|
||||
return 0
|
||||
else
|
||||
return ToKFunctions [Details.minimap.text_format] (_, combat.totals_grupo[2] / combatTime)
|
||||
return ToKFunctions[Details.minimap.text_format](_, combat.totals_grupo[2] / combatTime)
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -280,7 +295,7 @@
|
||||
|
||||
local get_combat_time = function()
|
||||
local combat_time = Details.tabela_vigente:GetCombatTime()
|
||||
local minutos, segundos = _math_floor(combat_time / 60), _math_floor(combat_time % 60)
|
||||
local minutos, segundos = math.floor(combat_time / 60), math.floor(combat_time % 60)
|
||||
if (segundos < 10) then
|
||||
segundos = "0" .. segundos
|
||||
end
|
||||
@@ -288,8 +303,8 @@
|
||||
end
|
||||
|
||||
local get_damage_position = function()
|
||||
local damage_container = Details.tabela_vigente [1]
|
||||
damage_container:SortByKey ("total")
|
||||
local damage_container = Details.tabela_vigente[1]
|
||||
damage_container:SortByKey("total")
|
||||
|
||||
local pos = 1
|
||||
for index, actor in ipairs(damage_container._ActorTable) do
|
||||
@@ -305,8 +320,8 @@
|
||||
end
|
||||
|
||||
local get_heal_position = function()
|
||||
local heal_container = Details.tabela_vigente [2]
|
||||
heal_container:SortByKey ("total")
|
||||
local heal_container = Details.tabela_vigente[2]
|
||||
heal_container:SortByKey("total")
|
||||
|
||||
local pos = 1
|
||||
for index, actor in ipairs(heal_container._ActorTable) do
|
||||
@@ -322,8 +337,8 @@
|
||||
end
|
||||
|
||||
local get_damage_diff = function()
|
||||
local damage_container = Details.tabela_vigente [1]
|
||||
damage_container:SortByKey ("total")
|
||||
local damage_container = Details.tabela_vigente[1]
|
||||
damage_container:SortByKey("total")
|
||||
|
||||
local first
|
||||
local first_index
|
||||
@@ -348,18 +363,18 @@
|
||||
|
||||
if (second) then
|
||||
local diff = first.total - second.total
|
||||
return "+" .. ToKFunctions [Details.minimap.text_format] (_, diff)
|
||||
return "+" .. ToKFunctions[Details.minimap.text_format] (_, diff)
|
||||
else
|
||||
return "0"
|
||||
end
|
||||
else
|
||||
local player = damage_container._NameIndexTable [Details.playername]
|
||||
local player = damage_container._NameIndexTable[Details.playername]
|
||||
if (player) then
|
||||
player = damage_container._ActorTable [player]
|
||||
player = damage_container._ActorTable[player]
|
||||
local diff = first.total - player.total
|
||||
return "-" .. ToKFunctions [Details.minimap.text_format] (_, diff)
|
||||
return "-" .. ToKFunctions[Details.minimap.text_format](_, diff)
|
||||
else
|
||||
return ToKFunctions [Details.minimap.text_format] (_, first.total)
|
||||
return ToKFunctions[Details.minimap.text_format](_, first.total)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user