26 lines
776 B
Lua
26 lines
776 B
Lua
|
CSVLoader = CSVLoader or {}
|
||
|
|
||
|
---@return table<int, struct>
|
||
|
---@param TablePath string
|
||
|
---@param KeyName string @如果KeyName不为空则以此查结构体的变量名作为索引值
|
||
|
function CSVLoader.LoadTable(TablePath, KeyName)
|
||
|
local TmpTable = TableHelper.DeepCopyTable(Gameplay.GetTable(TablePath))
|
||
|
local IndexTable = {}
|
||
|
if KeyName == nil then
|
||
|
for k, v in pairs(TmpTable) do
|
||
|
-- 将行标识转换为ID
|
||
|
local i = tonumber(k)
|
||
|
IndexTable[i] = v
|
||
|
end
|
||
|
else
|
||
|
for k, v in pairs(TmpTable) do
|
||
|
-- 采用结构体变量作为索引 IndexTable[v.KeyName] = v
|
||
|
local i = v[KeyName]
|
||
|
IndexTable[i] = v
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return IndexTable
|
||
|
end
|
||
|
|
||
|
return CSVLoader
|