Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
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 | -- If the prototype.json contains a list for this id, use it (entity -> prototypes) | ||
local protoList = prototypeDefs[id] | |||
foundPrototypes[ | if type(protoList) == "table" then | ||
for _, v in ipairs(protoList) do | |||
if type(v) == "string" then | |||
foundPrototypes[v] = true | |||
end | |||
end | |||
end | end | ||
-- | -- 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] | 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 compPathName = lcfirst(compName) | |||
local compPathName = lcfirst( | |||
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 | 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 protoPathName = lcfirst(protoName) | |||
local protoPathName = lcfirst( | |||
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 | table.insert(errors, "Ошибка: не найден шаблон prototype/" .. protoPathName) | ||
else | else | ||
local keys = parse_keys_from_template(content) | local keys = parse_keys_from_template(content) | ||