Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions modules/game_battle/battle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@ BattleListInstance = nil
BattleButtonPool = nil

-- Utility functions
function table.copy(t)
function tableCopy(t)
if type(t) ~= "table" then return t end
local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
target[k] = type(v) == "table" and table.copy(v) or v
target[k] = type(v) == "table" and tableCopy(v) or v
end
setmetatable(target, meta)
return target
end

function table.size(t)
if type(t) ~= "table" then return 0 end
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end

-- Default filter settings
local BATTLE_FILTERS = {
["sortAscByDisplayTime"] = true,
Expand Down Expand Up @@ -127,7 +120,7 @@ function BattleListManager:restoreInstancesState()
if instance and instance.window then
if shouldRestoreSettings and oldSettings then
local newSettingsKey = instance:getSettingsKey()
local settingsToRestore = table.copy(oldSettings)
local settingsToRestore = tableCopy(oldSettings)
settingsToRestore.customName = data.name

g_settings.mergeNode(newSettingsKey, settingsToRestore)
Expand Down Expand Up @@ -456,7 +449,7 @@ function BattleListInstance:new(id, customName)
instance.lastAge = 0
instance.name = customName or tr('Battle List')
instance.settings = {
filters = table.copy(BATTLE_FILTERS),
filters = tableCopy(BATTLE_FILTERS),
sortType = 'name',
sortOrder = 'A',
hidingFilters = false,
Expand All @@ -473,7 +466,7 @@ end
function BattleListInstance:loadFilters()
local settings = g_settings.getNode(self:getSettingsKey())
if not settings or not settings['filters'] then
return table.copy(BATTLE_FILTERS)
return tableCopy(BATTLE_FILTERS)
end
return settings['filters']
end
Expand Down Expand Up @@ -682,7 +675,7 @@ function BattleListInstance:clearAllConfigurations()
end

self.settings = {
filters = table.copy(BATTLE_FILTERS),
filters = tableCopy(BATTLE_FILTERS),
sortType = 'name',
sortOrder = 'A',
hidingFilters = false,
Expand Down