Модуль:Prototypes/Хранилище/Предмет: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 52: | Строка 52: | ||
end | end | ||
local function getContentsOutput(contents) | local function getContentsOutput(contents) | ||
local result = '' | local result = '' | ||
| Строка 59: | Строка 58: | ||
end | end | ||
return result | return result | ||
end | end | ||
| Строка 91: | Строка 70: | ||
result = result .. processAllSelectors(child.children) | result = result .. processAllSelectors(child.children) | ||
elseif child["!type"] == "NestedSelector" and child.tableId then | elseif child["!type"] == "NestedSelector" and child.tableId then | ||
local nestedRolls = child.rolls and (child.rolls.value or | local nestedRolls = child.rolls and (child.rolls.value or math.random(tonumber(child.rolls.range:match("(%d+),%s*(%d+)")))) or 1 | ||
result = result .. getTableOutput(child.tableId, nestedRolls) | result = result .. getTableOutput(child.tableId, nestedRolls) | ||
end | end | ||
| Строка 98: | Строка 77: | ||
end | end | ||
local function getTableOutput(tableId, rolls) | local function getTableOutput(tableId, rolls) | ||
local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json', 'selectors') | local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json', 'selectors') | ||
| Строка 134: | Строка 91: | ||
end | end | ||
local function processNestedSelectors(children, rolls) | |||
local function | |||
local result = '' | local result = '' | ||
if | for i = 1, rolls do | ||
local selectedChild = pickByWeight(children) | |||
if selectedChild then | |||
if selectedChild.id then | |||
result = result .. formatContent(selectedChild) | |||
elseif selectedChild["!type"] == "GroupSelector" and selectedChild.children then | |||
result = result .. processNestedSelectors(selectedChild.children, 1) | |||
elseif selectedChild["!type"] == "AllSelector" and selectedChild.children then | |||
result = result .. processAllSelectors(selectedChild.children) | |||
elseif selectedChild["!type"] == "NestedSelector" and selectedChild.tableId then | |||
local nestedRolls = selectedChild.rolls and (selectedChild.rolls.value or math.random(tonumber(selectedChild.rolls.range:match("(%d+),%s*(%d+)")))) or 1 | |||
result = result .. getTableOutput(selectedChild.tableId, nestedRolls) | |||
end | |||
end | end | ||
end | end | ||
| Строка 160: | Строка 115: | ||
local mode = frame.args[1] | local mode = frame.args[1] | ||
local id = frame.args[2] | local id = frame.args[2] | ||
if not id then return 'Не указан ID.' end | if not id then return 'Не указан ID.' end | ||
local data = loadData('User:IanComradeBot/prototypes/fills/Item.json', 'items') | local data = loadData('User:IanComradeBot/prototypes/fills/Item.json', 'items') | ||
if not data then return 'Не удалось загрузить данные.' end | if not data then return 'Не удалось загрузить данные.' end | ||
if mode == 'contained' then | |||
-- При режиме framing | |||
if mode == 'framing' then | |||
local subMode = frame.args[2] | |||
local id = frame.args[3] | |||
if not id then | |||
return 'Не указан ID для режима framing.' | |||
end | |||
if subMode == 'chem' then | |||
return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(data, id) .. '}}') | |||
elseif subMode == 'contained' then | |||
return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(data, id, false) .. '}}') | |||
else | |||
return 'Неизвестный подрежим для framing: ' .. subMode | |||
end | |||
end | |||
-- При нормальном режиме | |||
if mode == 'chem' then | |||
return frame:preprocess(getChemOutput(data, id)) | |||
elseif mode == 'contained' then | |||
return frame:preprocess(getContainedOutput(data, id, false)) | return frame:preprocess(getContainedOutput(data, id, false)) | ||
else | else | ||