Модуль:Песочница/Pok: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки Метка: ручная отмена |
||
| Строка 17: | Строка 17: | ||
title = "Prototypes/Механика/Случайный события", | title = "Prototypes/Механика/Случайный события", | ||
args = { | args = { | ||
weight = | weight = stationEvent.weight or "", | ||
minimumPlayers = | minimumPlayers = stationEvent.minimumPlayers or "", | ||
earliestStart = | earliestStart = stationEvent.earliestStart and (stationEvent.earliestStart) or "", | ||
duration = | duration = stationEvent.duration and (stationEvent.duration) or "" | ||
} | } | ||
} | } | ||
Версия от 23:44, 29 марта 2025
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data")
local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
local function buildCellEvent(name, image, id)
local cell = '<div style="text-align:center;">'
cell = cell .. name .. "<br>"
cell = cell .. "<span style='color:#adadad'>" .. id .. "</span><br>"
cell = cell .. '[[File:' .. image .. '|64px]]'
cell = cell .. '</div>'
return cell
end
local function buildCharacteristicsList(frame, stationEvent)
return frame:expandTemplate{
title = "Prototypes/Механика/Случайный события",
args = {
weight = stationEvent.weight or "",
minimumPlayers = stationEvent.minimumPlayers or "",
earliestStart = stationEvent.earliestStart and (stationEvent.earliestStart) or "",
duration = stationEvent.duration and (stationEvent.duration) or ""
}
}
end
function p.eventStation(frame)
local args = frame.args
local searchId = args.id or ""
local name = args.name or ""
local image = args.image or ""
local description = args.description or "Нет описания"
local out = ""
for _, event in ipairs(eventData) do
if event.id == searchId then
local cellEvent = buildCellEvent(name, image, searchId)
local advert = (event.StationEvent and event.StationEvent.startAnnouncement) or ""
local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
out = out .. "|-\n"
out = out .. "! " .. cellEvent .. "\n"
if advert ~= "" then
out = out .. "| {{#invoke:Ftl|main|translation|" .. advert .. "}}\n"
else
out = out .. "| Происходит без объявления\n"
end
out = out .. "| " .. description .. "\n"
out = out .. "| " .. characteristicsList
break
end
end
return frame:preprocess(out)
end
function p.eventCargo(frame)
local args = frame.args
local searchId = args.id or ""
local name = args.name or ""
local image = args.image or ""
local out = ""
for _, event in ipairs(eventData) do
if event.id == searchId then
local cellEvent = buildCellEvent(name, image, searchId)
local cargo = event.CargoGiftsRule or {}
local sender = cargo.sender or "Нет отправителя"
local cargoDescription = cargo.description or "Нет описания"
local dest = cargo.dest or "Нет получателя"
local advert = "Поздравляем! {{#invoke:Ftl|main|translation|" .. sender .. "}} решили отправить {{#invoke:Ftl|main|translation|" .. cargoDescription .. "}} {{#invoke:Ftl|main|translation|" .. dest .. "}} станции. Всё прибудет со следующей партией груза."
local giftsCell = ""
if cargo.gifts then
for giftId, giftValue in pairs(cargo.gifts) do
local productFound = nil
for _, cargoItem in ipairs(cargoData) do
if cargoItem.id == giftId then
productFound = cargoItem.product
break
end
end
if productFound then
giftsCell = giftsCell .. "- [[Таблица грузов#{{#invoke:Entity Lookup|getname|" .. productFound .. "}}|{{#invoke:Entity Lookup|getname|" .. productFound .. "}}]] x" .. giftValue .. "<br>"
else
giftsCell = giftsCell .. "Ошибка: id продукта не найден."
end
end
else
giftsCell = "Нет подарков"
end
local characteristicsList = buildCharacteristicsList(frame, event.StationEvent or {})
out = out .. "|-\n"
out = out .. "! " .. cellEvent .. "\n"
out = out .. "| " .. advert .. "\n"
out = out .. "| " .. giftsCell .. "\n"
out = out .. "| " .. characteristicsList
break
end
end
return frame:preprocess(out)
end
return p