Files
SL1900 5e0d58cfad Initial version - 1.2.0.60
EN: 1.2.0.60
CN: 1.2.0.61
JP: 1.2.0.63
KR: 1.2.0.67
2025-12-03 01:00:00 +09:00

119 lines
3.3 KiB
Lua

local RapidJson = require("rapidjson")
local GameTableDefine = require("Game.CodeGen.GAME_TABLE_DEFINE")
local ClientManager = CS.ClientManager.Instance
require("GameCore.Data.ConfigTable")
require("GameCore.Data.CacheTable")
local ConfigData = {IntFloatPrecision = 1.0E-4}
local PreProcess = function()
end
function ConfigData.Load(sLanguage)
NovaAPI.LoadAllDataTable(sLanguage)
require("GameCore.Data.LanguageTable")
LanguageTable.Init(sLanguage)
if NovaAPI.IsBinFormatEnabled() then
require("GameCore.Data.GameBinTable")
LoadGameBinTable(sLanguage)
else
require("GameCore.Data.GameJsonTable")
LoadGameJsonTable(sLanguage)
end
PreProcess()
printLog("Config data loaded.")
end
function ConfigData.Unload()
NovaAPI.UnLoadAllDataTable()
printLog("Config data unload.")
end
local GenLanguageTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" then
local jsonObject = {}
for _, v in ipairs(jsonArray) do
local id = v.Key
jsonObject[id] = v.Value
end
return jsonObject
end
return nil
end
local ConvertKeyTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
local jsonObject = {}
for i, v in ipairs(jsonArray.list) do
local id = v.Id
jsonObject[id] = v
end
return jsonObject
end
return nil
end
local ConvertNoKeyTable = function(jsonArray)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
local jsonObject = {}
for i, v in ipairs(jsonArray.list) do
jsonObject[i] = v
end
return jsonObject
end
return nil
end
local HandleLanguage = function(jsonArray, sLanguage, tableName, langDefine)
if langDefine == nil then
return
end
local languageTab = ConfigData.LoadLanguageTable(sLanguage, tableName)
if jsonArray ~= nil and type(jsonArray) == "table" and jsonArray.list ~= nil and type(jsonArray.list) == "table" then
for _, v in ipairs(jsonArray.list) do
for _, d in ipairs(langDefine) do
local lang = v[d]
if lang ~= nil then
v[d] = languageTab[lang] or ""
end
end
end
end
end
function ConfigData.LoadLanguageTable(lang, tableName)
local jsonText = NovaAPI.LoadTableData("language/" .. lang .. "/" .. tableName .. ".json") or ""
local tab = RapidJson.decode(jsonText) or {}
return tab
end
function ConfigData.LoadCommonJsonTable(tableName, define, sLanguage)
local jsonText = NovaAPI.LoadTableData("json/" .. tableName .. ".json") or ""
local tab = RapidJson.decode(jsonText)
local lang = define.Lang
if NovaAPI.IsLQA() then
lang = nil
end
HandleLanguage(tab, sLanguage, tableName, lang)
local tab1
if define.Key then
tab1 = ConvertKeyTable(tab)
else
tab1 = ConvertNoKeyTable(tab)
end
return tab1
end
function ConfigData.LoadCommonBinTable(tableName, define, sLanguage)
local tab = {}
NovaAPI.LoadCommonBinData("bin/" .. tableName .. ".bytes", tab)
local langs = define.Lang
if NovaAPI.IsLQA() then
langs = nil
end
local lang
local loaded = false
if not ClientManager:GetMemoryType() and langs ~= nil then
lang = ConfigData.LoadLanguageTable(sLanguage, tableName)
loaded = true
end
local meta = {
pbName = tableName,
langs = langs,
lang = lang,
loaded = loaded
}
local tab1 = LoadDataTable(meta, tab)
return tab1
end
return ConfigData