Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 15: | Строка 15: | ||
local result = {} | local result = {} | ||
if rolls and rolls.range then | if rolls and rolls.range then | ||
local min, max = rolls.range:match("(%d+),%s*(%d+)") | local min, max = rolls.range:match("(%d+),%s*(%d+)") | ||
min, max = tonumber(min), tonumber(max) | min, max = tonumber(min), tonumber(max) | ||
| Строка 24: | Строка 23: | ||
end | end | ||
elseif rolls and rolls.value then | elseif rolls and rolls.value then | ||
result[#result + 1] = string.format('[%d]', rolls.value) | result[#result + 1] = string.format('[%d]', rolls.value) | ||
else | else | ||
| Строка 35: | Строка 33: | ||
local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector | local findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector | ||
-- | -- Исправленная функция создания хэш-таблицы для быстрого поиска по ID (рекурсивная версия) | ||
local function buildIndex(itemData) | local function buildIndex(itemData) | ||
local index = {} | local index = {} | ||
local function recursiveIndex(tbl) | |||
index[ | if type(tbl) ~= "table" then return end | ||
if tbl.id then | |||
index[tbl.id] = tbl | |||
end | |||
for k, v in pairs(tbl) do | |||
if type(v) == "table" then | |||
recursiveIndex(v) | |||
end | |||
end | |||
end | end | ||
recursiveIndex(itemData) | |||
return index | return index | ||
end | end | ||
| Строка 58: | Строка 64: | ||
local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id) | local name = string.format('{{#invoke:Entity Lookup|getname|%s}}', content.id) | ||
local image = string.format('%s.png', content.id) | local image = string.format('%s.png', content.id) | ||
local amount = (content.amount and content.amount ~= 1) and string.format(" [%d]", content.amount) or "" | |||
local prob = "" | local prob = "" | ||
| Строка 93: | Строка 99: | ||
if child.id then | if child.id then | ||
results[#results + 1] = formatContent(child) | results[#results + 1] = formatContent(child) | ||
elseif child["!type"] == "NestedSelector" then | |||
results[#results + 1] = handleNestedSelector(child, true) | |||
elseif child["!type"] == "GroupSelector" then | elseif child["!type"] == "GroupSelector" then | ||
results[#results + 1] = handleGroupSelector(child) | results[#results + 1] = handleGroupSelector(child) | ||
end | end | ||
end | end | ||
| Строка 203: | Строка 205: | ||
if wrapped then | if wrapped then | ||
if nestedSelector.rolls and nestedSelector.rolls.range then | |||
local rollsResult = processRolls(nestedSelector.rolls) | |||
if rollsResult and #rollsResult > 0 then | |||
classesRolls = ', максимум может выпасть: ' .. rollsResult | |||
end | |||
end | |||
if nestedSelector.prob then | if nestedSelector.prob then | ||
classesProb = string.format(" <div>%s%%</div>", nestedSelector.prob * 100 >= 1 and math.floor(nestedSelector.prob * 100) or nestedSelector.prob * 100) | classesProb = string.format(" <div>%s%%</div>", nestedSelector.prob * 100 >= 1 and math.floor(nestedSelector.prob * 100) or nestedSelector.prob * 100) | ||
| Строка 214: | Строка 216: | ||
end | end | ||
if wrapped and (classesRolls or classesProb) then | |||
if (classesRolls and #classesRolls > 0) or (classesProb and #classesProb > 0) then | |||
result[#result + 1] = string.format('{{LinkСard/Сollapsible|name=Группа предметов%s%s|content=', classesRolls or "", classesProb or "") | |||
end | |||
end | |||
result[#result + 1] = getTableOutput(nestedSelector.tableId) | result[#result + 1] = getTableOutput(nestedSelector.tableId) | ||
if wrapped and (classesRolls or classesProb) then | |||
if (classesRolls and #classesRolls > 0) or (classesProb and #classesProb > 0) then | |||
result[#result + 1] = "}}" | |||
end | |||
end | |||
return table.concat(result) | return table.concat(result) | ||
| Строка 252: | Строка 254: | ||
if not id then return 'Не указан ID.' end | if not id then return 'Не указан ID.' end | ||
local itemDataIndex = buildIndex(itemData) | |||
if not itemData then return 'Не удалось загрузить данные.' end | if not itemData then return 'Не удалось загрузить данные.' end | ||