@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
94 lines (92 loc) • 5.15 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypesInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const ContentIndex_1 = require("../core/ContentIndex");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
const EntityTypeDefinition_1 = require("../minecraft/EntityTypeDefinition");
const BlockTypeDefinition_1 = require("../minecraft/BlockTypeDefinition");
const ItemTypeBehaviorDefinition_1 = require("../minecraft/ItemTypeBehaviorDefinition");
const BlocksCatalogDefinition_1 = require("../minecraft/BlocksCatalogDefinition");
var TypesInfoGeneratorTest;
(function (TypesInfoGeneratorTest) {
TypesInfoGeneratorTest[TypesInfoGeneratorTest["types"] = 1] = "types";
})(TypesInfoGeneratorTest = exports.TypesInfoGeneratorTest || (exports.TypesInfoGeneratorTest = {}));
class TypesInfoGenerator {
constructor() {
this.id = "TYPES";
this.title = "Types Info Aggregation";
this.performAddOnValidations = false;
}
getTopicData(topicId) {
return {
title: ProjectInfoUtilities_1.default.getTitleFromEnum(TypesInfoGeneratorTest, topicId),
};
}
summarize(info, infoSet) {
info.textureCount = infoSet.getSummedNumberValue(this.id, TypesInfoGeneratorTest.types);
}
async generate(project, contentIndex) {
const items = [];
const typesCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, 1, "Types");
items.push(typesCountPi);
const itemsCopy = project.getItemsCopy();
for (const projectItem of itemsCopy) {
if (projectItem.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior) {
await projectItem.ensureFileStorage();
if (projectItem.file) {
const etd = await EntityTypeDefinition_1.default.ensureOnFile(projectItem.file);
if (etd && etd.id && projectItem.projectPath) {
contentIndex.insert(etd.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.entityTypeSource);
}
}
}
else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.blockTypeBehavior) {
await projectItem.ensureFileStorage();
if (projectItem.file) {
const blockTypeDef = await BlockTypeDefinition_1.default.ensureOnFile(projectItem.file);
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) {
await projectItem.ensureFileStorage();
if (projectItem.file) {
const blockCatalog = await BlocksCatalogDefinition_1.default.ensureOnFile(projectItem.file);
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) {
await projectItem.ensureFileStorage();
if (projectItem.file) {
const itemTypeDef = await ItemTypeBehaviorDefinition_1.default.ensureOnFile(projectItem.file);
if (itemTypeDef && itemTypeDef.id && projectItem.projectPath) {
contentIndex.insert(itemTypeDef.id, projectItem.projectPath, ContentIndex_1.AnnotationCategory.itemTypeSource);
}
}
}
}
return items;
}
}
exports.default = TypesInfoGenerator;
//# sourceMappingURL=../maps/info/TypesInfoGenerator.js.map