|
|
| Строка 1: |
Строка 1: |
| local p = {} | | local p = {} |
|
| |
|
| local eventData = mw.loadData("Модуль:IanComradeBot/prototypes/StationEvent.json/data") | | -- Простые правила образования множественного числа |
| local cargoData = mw.loadData("Модуль:IanComradeBot/prototypes/cargo.json/data")
| | local rules = { |
| | {"ие$", "ие", "ия"}, -- здание -> здания |
| | {"ка$", "ка", "ки"}, -- собака -> собаки |
| | {"ок$", "ок", "ки"}, -- носок -> носки |
| | {"ец$", "ец", "цы"}, -- молодец -> молодцы |
| | {"ье$", "ье", "ья"}, -- зелье -> зелья |
| | {"о$", "о", "а"}, -- окно -> окна |
| | {"е$", "е", "я"}, -- поле -> поля |
| | {"й$", "й", "и"}, -- край -> края |
| | {"ь$", "ь", "и"} -- лошадь -> лошади |
| | } |
|
| |
|
| local function buildCellEvent(name, image, id)
| | -- Функция преобразования в множественное число для каждого слова |
| local cell = '<div style="text-align:center;">'
| | function p.main(frame) |
| cell = cell .. name .. "<br>"
| | local words = {} |
| cell = cell .. "<span style='color:#adadad'>" .. id .. "</span><br>"
| | for word in frame:gmatch("%S+") do |
| cell = cell .. '[[File:' .. image .. '|64px]]'
| | local pluralized = word |
| cell = cell .. '</div>'
| | -- Применяем правила для образования множественного числа |
| return cell
| | for _, rule in ipairs(rules) do |
| end
| | if word:match(rule[1]) then |
| | | pluralized = word:gsub(rule[2].."$", rule[3]) |
| local function buildCharacteristicsList(stationEvent)
| | break |
| local lines = {} | |
| local characteristics = {
| |
| {"Вес", "Вес события в системе случайных событий (чем выше, тем чаще случается)", stationEvent.weight},
| |
| {"Мин. игроков", "Минимальное количество игроков для начала события", stationEvent.minimumPlayers},
| |
| {"Время старта", "Время с которого событие может начаться", stationEvent.earliestStart and (stationEvent.earliestStart .. " сек.")},
| |
| {"Длительность", "Длительность события в секундах", stationEvent.duration and (stationEvent.duration .. " сек.")}
| |
| }
| |
| for _, char in ipairs(characteristics) do | |
| local value = char[3] or "нет"
| |
| local tooltip = "{{AltTooltip|" .. char[1] .. "|" .. char[2] .. "}}"
| |
| table.insert(lines, "- " .. tooltip .. ": " .. value)
| |
| end
| |
| return table.concat(lines, "<br>")
| |
| 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(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 .. "\n"
| |
| out = out .. '|style="display:none;"|123'
| |
| 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 | | end |
|
| |
| local characteristicsList = buildCharacteristicsList(event.StationEvent or {})
| |
| out = out .. "|-\n"
| |
| out = out .. "! " .. cellEvent .. "\n"
| |
| out = out .. "| " .. advert .. "\n"
| |
| out = out .. "| " .. giftsCell .. "\n"
| |
| out = out .. "| " .. characteristicsList
| |
| break
| |
| end | | end |
| | table.insert(words, pluralized) |
| end | | end |
| | | return table.concat(words, " ") |
| return frame:preprocess(out) | |
| end | | end |
|
| |
|
| return p | | return p |
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
-- Простые правила образования множественного числа
local rules = {
{"ие$", "ие", "ия"}, -- здание -> здания
{"ка$", "ка", "ки"}, -- собака -> собаки
{"ок$", "ок", "ки"}, -- носок -> носки
{"ец$", "ец", "цы"}, -- молодец -> молодцы
{"ье$", "ье", "ья"}, -- зелье -> зелья
{"о$", "о", "а"}, -- окно -> окна
{"е$", "е", "я"}, -- поле -> поля
{"й$", "й", "и"}, -- край -> края
{"ь$", "ь", "и"} -- лошадь -> лошади
}
-- Функция преобразования в множественное число для каждого слова
function p.main(frame)
local words = {}
for word in frame:gmatch("%S+") do
local pluralized = word
-- Применяем правила для образования множественного числа
for _, rule in ipairs(rules) do
if word:match(rule[1]) then
pluralized = word:gsub(rule[2].."$", rule[3])
break
end
end
table.insert(words, pluralized)
end
return table.concat(words, " ")
end
return p