Модуль:Prototypes/Объект/Торгомат: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 23: | Строка 23: | ||
local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | ||
local inventories = loadData("User:IanComradeBot/prototypes/vending machines/inventories.json") | local inventories = loadData("User:IanComradeBot/prototypes/vending machines/inventories.json") | ||
-- Поиск автомата по ID | |||
local vendingMachine = findDataById(vendingMachines, id) | local vendingMachine = findDataById(vendingMachines, id) | ||
if not vendingMachine then return "" end | if not vendingMachine then return "" end | ||
-- Получение инвентаря автомата | |||
local inventoryId = vendingMachine.VendingMachine and vendingMachine.VendingMachine.pack | local inventoryId = vendingMachine.VendingMachine and vendingMachine.VendingMachine.pack | ||
if not inventoryId then return "" end | if not inventoryId then return "" end | ||
| Строка 32: | Строка 35: | ||
if not inventory then return "" end | if not inventory then return "" end | ||
-- Формирование вывода | |||
local result = "" | local result = "" | ||
-- Основной инвентарь | -- Основной инвентарь | ||
if mode == "inventory" and inventory.startingInventory then | if mode == "inventory" and inventory.startingInventory then | ||
| Строка 38: | Строка 43: | ||
result = result .. mw.getCurrentFrame():preprocess("{{LinkСard|SideStyle=1|image=" .. itemId .. ".png|name={{#invoke:Entity Lookup|getname|" .. itemId .. "}} [" .. count .. "]}}") | result = result .. mw.getCurrentFrame():preprocess("{{LinkСard|SideStyle=1|image=" .. itemId .. ".png|name={{#invoke:Entity Lookup|getname|" .. itemId .. "}} [" .. count .. "]}}") | ||
end | end | ||
-- Содержания после провода | -- Содержания после провода | ||
elseif mode == "contraband" and inventory.contrabandInventory then | elseif mode == "contraband" and inventory.contrabandInventory then | ||
| Строка 43: | Строка 49: | ||
result = result .. mw.getCurrentFrame():preprocess("{{LinkСard|SideStyle=1|image=" .. itemId .. ".png|name={{#invoke:Entity Lookup|getname|" .. itemId .. "}} [" .. count .. "]}}") | result = result .. mw.getCurrentFrame():preprocess("{{LinkСard|SideStyle=1|image=" .. itemId .. ".png|name={{#invoke:Entity Lookup|getname|" .. itemId .. "}} [" .. count .. "]}}") | ||
end | end | ||
-- Содержания после EMAG | -- Содержания после EMAG | ||
elseif mode == "emag" and inventory.emaggedInventory then | elseif mode == "emag" and inventory.emaggedInventory then | ||
| Строка 49: | Строка 56: | ||
end | end | ||
end | end | ||
return result | return result | ||
end | end | ||
| Строка 56: | Строка 64: | ||
local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | ||
local restockData = loadData("User:IanComradeBot/prototypes/vending machines/restock.json") | local restockData = loadData("User:IanComradeBot/prototypes/vending machines/restock.json") | ||
-- Поиск автомата по ID | |||
local vendingMachine = findDataById(vendingMachines, id) | local vendingMachine = findDataById(vendingMachines, id) | ||
if not vendingMachine then return "" end | if not vendingMachine then return "" end | ||
-- Получение ID пополнителя | |||
local packId = vendingMachine.VendingMachine and vendingMachine.VendingMachine.pack | local packId = vendingMachine.VendingMachine and vendingMachine.VendingMachine.pack | ||
if not packId then return "" end | if not packId then return "" end | ||
| Строка 74: | Строка 85: | ||
local function getAccessOutput(id) | local function getAccessOutput(id) | ||
local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | local vendingMachines = loadData("User:IanComradeBot/prototypes/vending machines.json") | ||
-- Поиск автомата по ID | |||
local vendingMachine = findDataById(vendingMachines, id) | local vendingMachine = findDataById(vendingMachines, id) | ||
-- Получение доступа из данных автомата | |||
local access = vendingMachine.AccessReader and vendingMachine.AccessReader.access | local access = vendingMachine.AccessReader and vendingMachine.AccessReader.access | ||
| Строка 81: | Строка 96: | ||
end | end | ||
-- Формируем строку для вызова шаблона | |||
local templateCall = "{{#invoke:Prototypes/Механика/Доступ|parse|" .. access .. "}}" | local templateCall = "{{#invoke:Prototypes/Механика/Доступ|parse|" .. access .. "}}" | ||
-- Обрабатываем шаблон и возвращаем результат | |||
return mw.getCurrentFrame():preprocess(templateCall) | return mw.getCurrentFrame():preprocess(templateCall) | ||
end | end | ||
| Строка 92: | Строка 110: | ||
if not id then return "" end | if not id then return "" end | ||
-- Определение действия на основе ID и выбранного режима | |||
if mode == "inventory" or mode == "contraband" or mode == "emag" then | if mode == "inventory" or mode == "contraband" or mode == "emag" then | ||
return getInventoryOutput(id, mode) | return getInventoryOutput(id, mode) | ||