Модуль:Prototypes/Объект/Торгомат: различия между версиями

мНет описания правки
мНет описания правки
Строка 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
Строка 35: Строка 32:
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
Строка 43: Строка 38:
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
end
-- Содержания после провода
-- Содержания после провода
if mode == "contraband" and inventory.contrabandInventory then
elseif mode == "contraband" and inventory.contrabandInventory then
for itemId, count in pairs(inventory.contrabandInventory) do
for itemId, count in pairs(inventory.contrabandInventory) do
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
end
-- Содержания после EMAG
-- Содержания после EMAG
if mode == "emag" and inventory.emaggedInventory then
elseif mode == "emag" and inventory.emaggedInventory then
for itemId, count in pairs(inventory.emaggedInventory) do
for itemId, count in pairs(inventory.emaggedInventory) do
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
end
end
return result
return result
end
end
Строка 66: Строка 56:
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
Строка 87: Строка 74:
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


Строка 98: Строка 81:
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
Строка 112: Строка 92:
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)