Модуль:Песочница/Pok: различия между версиями

мНет описания правки
мНет описания правки
Строка 67: Строка 67:
local foundComponents = {}
local foundComponents = {}
local foundPrototypes = {}
local foundPrototypes = {}
-- If the component.json contains a list for this id, use it (entity -> components)
local compList = componentDefs[id]
if type(compList) == "table" then
for _, v in ipairs(compList) do
if type(v) == "string" then
foundComponents[v] = true
end
end
end


-- If id directly matches a prototype or component key, include it
-- If the prototype.json contains a list for this id, use it (entity -> prototypes)
if prototypeDefs[id] ~= nil then
local protoList = prototypeDefs[id]
foundPrototypes[id] = true
if type(protoList) == "table" then
end
for _, v in ipairs(protoList) do
if componentDefs[id] ~= nil then
if type(v) == "string" then
foundComponents[id] = true
foundPrototypes[v] = true
end
end
end
end


-- Support comma-separated list of ids (e.g. "absorbent,action")
-- Also support passing comma-separated component/prototype names directly
for name in string.gmatch(id, "[^,]+") do
for name in string.gmatch(id, "[^,]+") do
local n = trim(name)
local n = trim(name)
if n ~= "" then
if n ~= "" then
if prototypeDefs[n] ~= nil then foundPrototypes[n] = true end
-- if it's a known component/prototype name, include it
if componentDefs[n] ~= nil then foundComponents[n] = true end
if componentDefs[n] ~= nil then
foundComponents[n] = true
end
if prototypeDefs[n] ~= nil then
foundPrototypes[n] = true
end
-- also allow using the name directly even if not present in defs
-- treat it as a component name
if componentDefs[n] == nil and prototypeDefs[n] == nil then
foundComponents[n] = true
end
end
end
end
end
Строка 96: Строка 117:


for compName,_ in pairs(foundComponents) do
for compName,_ in pairs(foundComponents) do
local displayName = componentDefs[compName] and componentDefs[compName].name or compName
local compPathName = lcfirst(compName)
local compPathName = lcfirst(displayName)
local tplPath = "component/" .. compPathName
local tplPath = "component/" .. compPathName
local content = load_template_content(tplPath)
local content = load_template_content(tplPath)
if not content then
if not content then
table.insert(errors, "Ошибка: не найден шаблон component/" .. compPathName .. " (компонент: " .. mw.text.encode(compName) .. ")")
table.insert(errors, "Ошибка: не найден шаблон component/" .. compPathName)
else
else
local keys = parse_keys_from_template(content)
local keys = parse_keys_from_template(content)
Строка 115: Строка 135:


for protoName,_ in pairs(foundPrototypes) do
for protoName,_ in pairs(foundPrototypes) do
local displayName = prototypeDefs[protoName] and prototypeDefs[protoName].name or protoName
local protoPathName = lcfirst(protoName)
local protoPathName = lcfirst(displayName)
local tplPath = "prototype/" .. protoPathName
local tplPath = "prototype/" .. protoPathName
local content = load_template_content(tplPath)
local content = load_template_content(tplPath)
if not content then
if not content then
table.insert(errors, "Ошибка: не найден шаблон prototype/" .. protoPathName .. " (прототип: " .. mw.text.encode(protoName) .. ")")
table.insert(errors, "Ошибка: не найден шаблон prototype/" .. protoPathName)
else
else
local keys = parse_keys_from_template(content)
local keys = parse_keys_from_template(content)