Модуль:Prototypes/Механика/Частоты: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Новая страница: «local p = {} local keysData = mw.loadData("Module:IanComradeBot/prototypes/encryption keys.json/data") local radioData = mw.loadData("Module:IanComradeBot/prototypes/radio channels.json/data") local fillsData = mw.loadData("Module:IanComradeBot/prototypes/fills/Item.json/data") local function trimQuotes(str) if not str then return "" end return (str:gsub("^['\"](.-)['\"]$", "%1")) end function p.render(frame) local args = frame.args local...» |
Pok (обсуждение | вклад) мНет описания правки |
||
(не показаны 3 промежуточные версии этого же участника) | |||
Строка 10: | Строка 10: | ||
end | end | ||
function p. | function p.main(frame) | ||
local args = frame.args | local args = frame.args | ||
local | local itemId = args[1] | ||
if not itemId or itemId == "" then | if not itemId or itemId == "" then | ||
Строка 20: | Строка 19: | ||
local keySlots = {} | local keySlots = {} | ||
local itemFound = nil | |||
for _, data in pairs(fillsData) do | |||
if data.id == itemId then | |||
itemFound = data | |||
break | |||
end | end | ||
end | |||
if | if itemFound then | ||
if itemFound.ContainerFill | |||
and itemFound.ContainerFill.containers | |||
and itemFound.ContainerFill.containers.key_slots then | |||
keySlots = itemFound.ContainerFill.containers.key_slots | |||
else | |||
keySlots = { itemId } | |||
end | end | ||
else | |||
keySlots = { itemId } | keySlots = { itemId } | ||
end | end | ||
Строка 57: | Строка 48: | ||
end | end | ||
end | end | ||
if keyRecord and keyRecord.EncryptionKey and keyRecord.EncryptionKey.channels then | if keyRecord and keyRecord.EncryptionKey and keyRecord.EncryptionKey.channels then | ||
for _, channel in ipairs(keyRecord.EncryptionKey.channels) do | for _, channel in ipairs(keyRecord.EncryptionKey.channels) do | ||
Строка 63: | Строка 53: | ||
end | end | ||
else | else | ||
return "" | |||
end | end | ||
end | end | ||
local resultSpans = {} | local resultSpans = {} | ||
local seenKeycodes = {} | |||
for _, channelName in ipairs(channels) do | for _, channelName in ipairs(channels) do | ||
local radioRecord | local radioRecord | ||
Строка 76: | Строка 67: | ||
end | end | ||
end | end | ||
if radioRecord then | if radioRecord then | ||
local keycode = trimQuotes(radioRecord.keycode) or "" | local keycode = trimQuotes(radioRecord.keycode) or "" | ||
local color = trimQuotes(radioRecord.color) or "" | local color = trimQuotes(radioRecord.color) or "" | ||
local span = string.format('<span style="color: %s">%s</span>', color, keycode) | if not seenKeycodes[keycode] then | ||
seenKeycodes[keycode] = true | |||
local span = string.format('<span style="color: %s">%s</span>', color, keycode) | |||
table.insert(resultSpans, span) | |||
end | |||
else | else | ||
return "Предупреждение: для канала '" .. channelName .. "' не найдены данные в radioData." | |||
end | end | ||
end | end | ||
local output = '<span | local output = '<span>' .. table.concat(resultSpans, " ") .. '</span>' | ||
return output | return output | ||
end | end | ||
return p | return p |
Текущая версия от 21:23, 17 февраля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Частоты/doc
local p = {}
local keysData = mw.loadData("Module:IanComradeBot/prototypes/encryption keys.json/data")
local radioData = mw.loadData("Module:IanComradeBot/prototypes/radio channels.json/data")
local fillsData = mw.loadData("Module:IanComradeBot/prototypes/fills/Item.json/data")
local function trimQuotes(str)
if not str then return "" end
return (str:gsub("^['\"](.-)['\"]$", "%1"))
end
function p.main(frame)
local args = frame.args
local itemId = args[1]
if not itemId or itemId == "" then
return "Ошибка: не указан id предмета/ключа."
end
local keySlots = {}
local itemFound = nil
for _, data in pairs(fillsData) do
if data.id == itemId then
itemFound = data
break
end
end
if itemFound then
if itemFound.ContainerFill
and itemFound.ContainerFill.containers
and itemFound.ContainerFill.containers.key_slots then
keySlots = itemFound.ContainerFill.containers.key_slots
else
keySlots = { itemId }
end
else
keySlots = { itemId }
end
local channels = {}
for _, keyId in ipairs(keySlots) do
local keyRecord
for _, data in pairs(keysData) do
if data.id == keyId then
keyRecord = data
break
end
end
if keyRecord and keyRecord.EncryptionKey and keyRecord.EncryptionKey.channels then
for _, channel in ipairs(keyRecord.EncryptionKey.channels) do
table.insert(channels, channel)
end
else
return ""
end
end
local resultSpans = {}
local seenKeycodes = {}
for _, channelName in ipairs(channels) do
local radioRecord
for _, data in pairs(radioData) do
if data.id == channelName then
radioRecord = data
break
end
end
if radioRecord then
local keycode = trimQuotes(radioRecord.keycode) or ""
local color = trimQuotes(radioRecord.color) or ""
if not seenKeycodes[keycode] then
seenKeycodes[keycode] = true
local span = string.format('<span style="color: %s">%s</span>', color, keycode)
table.insert(resultSpans, span)
end
else
return "Предупреждение: для канала '" .. channelName .. "' не найдены данные в radioData."
end
end
local output = '<span>' .. table.concat(resultSpans, " ") .. '</span>'
return output
end
return p