Модуль:Сущность/data: различия между версиями
Pok (обсуждение | вклад) Отмена версии 315901, сделанной Pok (обсуждение) Метка: отмена |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показано 7 промежуточных версий этого же участника) | |||
| Строка 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 | ||
| Строка 47: | Строка 45: | ||
end | end | ||
function p.loadEntityComponents(entityId) | |||
if not | if not entityId or entityId == "" then | ||
return | return {} | ||
end | |||
local entity = dp.loadEntityData(entityId) | |||
if entity then | |||
return dp.collectEntityComponents(entity) | |||
end | |||
return {} | |||
end | |||
function p.entityHasComponent(entityOrId, compName) | |||
if not compName or compName == "" then | |||
return false | |||
end | |||
local entity | |||
if type(entityOrId) == "string" then | |||
entity = dp and dp.loadEntityData(entityOrId) or load_data_page("prototype/Entity/" .. entityOrId .. ".json") | |||
if not entity then | |||
return false | |||
end | |||
else | |||
entity = entityOrId | |||
end | |||
return dp.entityHasComponent(entity, compName) | |||
end | end | ||
| Строка 100: | Строка 122: | ||
end | end | ||
local function make_source(kind, name | local function make_source(kind, name, tplPath) | ||
return { kind = kind, name = name | return { kind = kind, name = name, tplPath = tplPath } | ||
end | end | ||
| Строка 598: | Строка 620: | ||
end | end | ||
local function collect_entity_sets(id | local function collect_entity_sets(id, prototypeStoreDefs, componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist) | ||
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 | ||
if type(v) == "string" then | if type(v) == "string" and v ~= "" then | ||
foundComponents[v] = true | foundComponents[v] = true | ||
end | end | ||
| Строка 611: | Строка 632: | ||
end | end | ||
local protoStore = prototypeStoreDefs and prototypeStoreDefs[id] | |||
if type(protoStore) == "table" then | |||
if | for protoName in pairs(protoStore) do | ||
if type(protoName) == "string" and protoName ~= "" then | |||
foundPrototypes[protoName] = true | |||
foundPrototypes[ | |||
end | end | ||
end | end | ||
end | end | ||
apply_entity_set_filters(foundComponents, parse_csv_set(componentWhitelist), parse_csv_set(componentBlacklist)) | apply_entity_set_filters(foundComponents, parse_csv_set(componentWhitelist), parse_csv_set(componentBlacklist)) | ||
| Строка 749: | Строка 769: | ||
local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or "" | local prototypeBlacklist = frame.args.prototypeBlacklist or frame.args.prototypeblacklist or "" | ||
local | local prototypeStoreDefs = dp.loadCachedData("prototype_store.json") | ||
if not prototypeStoreDefs then | |||
if | |||
return false | return false | ||
end | end | ||
local foundComponents, foundPrototypes = collect_entity_sets(id | local foundComponents, foundPrototypes = collect_entity_sets(id, prototypeStoreDefs, | ||
componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist) | componentWhitelist, componentBlacklist, prototypeWhitelist, prototypeBlacklist) | ||
| Строка 769: | Строка 788: | ||
local whitelistSearchStrings = extract_whitelist_search_strings(keyFilter) | local whitelistSearchStrings = extract_whitelist_search_strings(keyFilter) | ||
local function processEntity(kind, name, isStore) | |||
local tplPath = kind .. "/" .. dp.ucfirst(name) | |||
if isStore then | |||
tplPath = tplPath .. "/store" | |||
end | |||
local content = load_template_content(tplPath) | local content = load_template_content(tplPath) | ||
| Строка 796: | Строка 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 | ||
| Строка 804: | Строка 822: | ||
id = id, | id = id, | ||
extra = extra, | extra = extra, | ||
source = make_source(kind, name | source = make_source(kind, name, tplPath), | ||
priority = resolve_priority(parsed) | priority = resolve_priority(parsed) | ||
}) | }) | ||
| Строка 820: | Строка 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] | ||
| Строка 1010: | Строка 1028: | ||
id = "", | id = "", | ||
extra = "", | extra = "", | ||
source = make_source("" | source = make_source("", tplPath, tplPath), | ||
priority = 1 | priority = 1 | ||
}, nil, true) | }, nil, true) | ||