Skip to content

Commit 8073220

Browse files
committed
fix: 修复用户配置项逻辑问题
1 parent b4ab9d7 commit 8073220

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Boilerplate_!Base/src/lib/Storage.UserSettings.lua

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,33 @@ end
503503
-- @param {string} szKey 配置项全局唯一键
504504
-- @param {string} szDataSetKey 配置项组(如用户多套自定义偏好)唯一键,当且仅当 szKey 对应注册项携带 bDataSet 标记位时有效
505505
-- @return
506-
function X.GetUserSettings(szKey, szDataSetKey)
506+
function X.GetUserSettings(szKey, ...)
507+
-- 参数检查
507508
local res, bData, bCache = nil, false, false
508509
local info = USER_SETTINGS_INFO[szKey]
509510
if not info then
510511
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): `Key` has not been registered.')
511512
end
513+
local nParameter = select('#', ...) + 1
514+
local szDataSetKey
515+
if info.bDataSet then
516+
if nParameter ~= 2 then
517+
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): 2 parameters expected, got ' .. nParameter)
518+
end
519+
szDataSetKey = ...
520+
if not X.IsString(szDataSetKey) and not X.IsNumber(szDataSetKey) then
521+
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): `DataSetKey` should be a string or number value.')
522+
end
523+
else
524+
if nParameter ~= 1 then
525+
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): 1 parameter expected, got ' .. nParameter)
526+
end
527+
end
512528
-- 缓存加速
513529
local cache = DATA_CACHE[szKey]
514-
if szDataSetKey then
530+
if info.bDataSet and ... then
515531
cache = X.IsTable(cache) and cache.bDataSet
516-
and cache.tDataSet[szDataSetKey]
532+
and cache.tDataSet[...]
517533
or nil
518534
end
519535
if X.IsTable(cache) and cache.bValue then
@@ -522,25 +538,10 @@ function X.GetUserSettings(szKey, szDataSetKey)
522538
-- 未命中缓存,从数据库读取
523539
if not bCache then
524540
-- 参数检查
525-
local nParameter = select('#', ...) + 1
526541
local inst = DATABASE_INSTANCE[info.ePathType]
527542
if not inst then
528543
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): Database not connected.')
529544
end
530-
local szDataSetKey
531-
if info.bDataSet then
532-
if nParameter ~= 2 then
533-
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): 2 parameters expected, got ' .. nParameter)
534-
end
535-
szDataSetKey = ...
536-
if not X.IsString(szDataSetKey) and not X.IsNumber(szDataSetKey) then
537-
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): `DataSetKey` should be a string or number value.')
538-
end
539-
else
540-
if nParameter ~= 1 then
541-
assert(false, 'GetUserSettings KEY(' .. X.EncodeLUAData(szKey) .. '): 1 parameter expected, got ' .. nParameter)
542-
end
543-
end
544545
-- 读数据库
545546
res, bData = GetInstanceInfoData(inst, info), false
546547
if X.IsTable(res) and res.v == info.szVersion then

0 commit comments

Comments
 (0)