Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 112: | Строка 112: | ||
end | end | ||
end | end | ||
end | |||
local function resolve_entry(data, id) | |||
if type(data) ~= "table" then | |||
return nil | |||
end | |||
if id and id ~= "" then | |||
local direct = data[id] | |||
if direct ~= nil then | |||
return direct | |||
end | |||
local idsTable = data.id | |||
if type(idsTable) == "table" then | |||
local specific = idsTable[id] | |||
if type(specific) == "table" then | |||
local base = data["default"] | |||
if type(base) == "table" then | |||
local merged = deep_copy(base) | |||
deep_merge(merged, specific) | |||
return merged | |||
end | |||
return deep_copy(specific) | |||
end | |||
end | |||
end | |||
local base = data["default"] | |||
if type(base) == "table" then | |||
return deep_copy(base) | |||
end | |||
return nil | |||
end | end | ||
| Строка 175: | Строка 208: | ||
end | end | ||
local entry = | local entry = resolve_entry(data, id) or {} | ||
if type(entry) ~= "table" then return "" end | if type(entry) ~= "table" then return "" end | ||
| Строка 259: | Строка 266: | ||
local entry = entryCache[entryKey] | local entry = entryCache[entryKey] | ||
if not entry then | if not entry then | ||
entry = resolve_entry(data, id) | |||
entryCache[entryKey] = entry | entryCache[entryKey] = entry | ||
end | end | ||