@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
117 lines (116 loc) • 6.65 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypesInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const ContentIndex_1 = require("../core/ContentIndex");
const EntityTypeDefinition_1 = __importDefault(require("../minecraft/EntityTypeDefinition"));
const BlockTypeDefinition_1 = __importDefault(require("../minecraft/BlockTypeDefinition"));
const ItemTypeDefinition_1 = __importDefault(require("../minecraft/ItemTypeDefinition"));
const BlocksCatalogDefinition_1 = __importDefault(require("../minecraft/BlocksCatalogDefinition"));
const FeatureDefinition_1 = __importDefault(require("../minecraft/FeatureDefinition"));
var TypesInfoGeneratorTest;
(function (TypesInfoGeneratorTest) {
TypesInfoGeneratorTest[TypesInfoGeneratorTest["types"] = 101] = "types";
})(TypesInfoGeneratorTest || (exports.TypesInfoGeneratorTest = TypesInfoGeneratorTest = {}));
/**
* Aggregates content type information (entities, blocks, items) from the project.
*
* @see {@link ../../public/data/forms/mctoolsval/types.form.json} for topic definitions
*/
class TypesInfoGenerator {
id = "TYPES";
title = "Types Info Aggregation";
performAddOnValidations = false;
summarize(info, infoSet) {
info.textureCount = infoSet.getSummedDataValue(this.id, TypesInfoGeneratorTest.types);
}
async generate(project, contentIndex) {
const items = [];
const typesCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, TypesInfoGeneratorTest.types, "Types");
items.push(typesCountPi);
const itemsCopy = project.getItemsCopy();
for (const projectItem of itemsCopy) {
if (projectItem.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const etd = await EntityTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (etd && etd.id && projectItem.projectPath) {
contentIndex.insert(etd.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.entityTypeSource);
}
}
}
else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blockTypeBehavior) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const blockTypeDef = await BlockTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (blockTypeDef && blockTypeDef.id && projectItem.projectPath) {
contentIndex.insert(blockTypeDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
let colon = blockTypeDef.id.indexOf(":");
if (colon >= 0) {
contentIndex.insert(blockTypeDef.id.substring(colon + 1), projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
}
}
}
}
else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blocksCatalogResourceJson) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const blockCatalog = await BlocksCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (blockCatalog && projectItem.projectPath && blockCatalog.blocksCatalog) {
for (const name in blockCatalog.blocksCatalog) {
let adjustedName = name;
let colon = adjustedName.indexOf(":");
if (colon < 0 && project.isVanillaSourceProject) {
adjustedName = "minecraft:" + adjustedName;
contentIndex.insert(adjustedName, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
}
contentIndex.insert(name, projectItem.projectPath, ContentIndex_1.AnnotationCategory.blockTypeSource);
}
}
}
}
else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.itemTypeBehavior) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const itemTypeDef = await ItemTypeDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (itemTypeDef && itemTypeDef.id && projectItem.projectPath) {
contentIndex.insert(itemTypeDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.itemTypeSource);
}
}
}
else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.featureBehavior) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const featureDef = await FeatureDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (featureDef && featureDef.id && projectItem.projectPath) {
contentIndex.insert(featureDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.featureSource);
// Also index without namespace prefix for easier lookup
let colon = featureDef.id.indexOf(":");
if (colon >= 0) {
contentIndex.insert(featureDef.id.substring(colon + 1), projectItem.projectPath, ContentIndex_1.AnnotationCategory.featureSource);
}
}
}
}
}
return items;
}
}
exports.default = TypesInfoGenerator;