Модуль:Сущность/data: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 2: | Строка 2: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local JsonPaths = require('Module:JsonPaths') | local JsonPaths = require('Module:JsonPaths') | ||
local dp = require( "Module:GetField") | |||
local | local function load_data_page(page) | ||
local moduleName = JsonPaths.get(page) | |||
local ok, data = pcall(mw.loadData, moduleName) | |||
if not ok or type(data) ~= "table" then | |||
return nil | |||
end | |||
return data | |||
end | |||
local switchModeRegistry = {} | local switchModeRegistry = {} | ||
| Строка 24: | Строка 31: | ||
end | end | ||
end | end | ||
end | end | ||
| Строка 50: | Строка 45: | ||
end | end | ||
function p.loadEntityComponents(entityId) | |||
if not entityId or entityId == "" then | if not entityId or entityId == "" then | ||
return {} | return {} | ||
end | end | ||
local entity = dp.loadEntityData(entityId) | |||
if entity then | |||
return dp.collectEntityComponents(entity) | |||
end | end | ||
return {} | |||
end | end | ||
function p.entityHasComponent(entityOrId, compName) | |||
p.entityHasComponent | |||
if not compName or compName == "" then | if not compName or compName == "" then | ||
return false | return false | ||
end | end | ||
local entity | local entity | ||
if type(entityOrId) == "string" then | if type(entityOrId) == "string" then | ||
entity = dp and dp.loadEntityData(entityOrId) | entity = dp and dp.loadEntityData(entityOrId) or load_data_page("prototype/Entity/" .. entityOrId .. ".json") | ||
if not entity then | if not entity then | ||
return false | return false | ||
| Строка 103: | Строка 70: | ||
entity = entityOrId | entity = entityOrId | ||
end | end | ||
return dp.entityHasComponent(entity, compName) | |||
end | end | ||
| Строка 663: | Строка 623: | ||
local foundComponents, foundPrototypes = {}, {} | local foundComponents, foundPrototypes = {}, {} | ||
local compList = | local compList = p.loadEntityComponents(id) | ||
if type(compList) == "table" then | if type(compList) == "table" then | ||
for _, v in ipairs(compList) do | for _, v in ipairs(compList) do | ||
| Строка 809: | Строка 769: | ||
local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or "" | local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or "" | ||
local prototypeStoreDefs = | local prototypeStoreDefs = dp.loadCachedData("prototype_store.json") | ||
if not prototypeStoreDefs then | if not prototypeStoreDefs then | ||
return false | return false | ||
| Строка 829: | Строка 789: | ||
local function processEntity(kind, name, isStore) | local function processEntity(kind, name, isStore) | ||
local tplPath = kind .. "/" .. name | local tplPath = kind .. "/" .. dp.ucfirst(name) | ||
if isStore then | if isStore then | ||
tplPath = tplPath .. "/store" | tplPath = tplPath .. "/store" | ||
| Строка 854: | Строка 814: | ||
local paramNames = get_template_params(tplPath, content) | local paramNames = get_template_params(tplPath, content) | ||
if dp then | if dp then | ||
local dataPage = | local dataPage = kind .. "/" .. dp.ucfirst(name) .. ".json" | ||
extra = get_selective_extra(id, dataPage, paramNames) | extra = get_selective_extra(id, dataPage, paramNames) | ||
end | end | ||
| Строка 878: | Строка 838: | ||
end | end | ||
local componentStoreDefs = | local componentStoreDefs = dp.loadCachedData("component_store.json") | ||
if type(componentStoreDefs) == "table" and (not anyEntityWhitelist or compHasWhitelist) then | if type(componentStoreDefs) == "table" and (not anyEntityWhitelist or compHasWhitelist) then | ||
local compStore = componentStoreDefs[id] | local compStore = componentStoreDefs[id] | ||