UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

83 lines (82 loc) 5.09 kB
"use strict"; // 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.StrictPlatformInfoGeneratorTest = void 0; const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem")); const IProjectItemData_1 = require("../app/IProjectItemData"); const IInfoItemData_1 = require("./IInfoItemData"); const EntityTypeDefinition_1 = __importDefault(require("../minecraft/EntityTypeDefinition")); const ItemTypeDefinition_1 = __importDefault(require("../minecraft/ItemTypeDefinition")); var StrictPlatformInfoGeneratorTest; (function (StrictPlatformInfoGeneratorTest) { StrictPlatformInfoGeneratorTest[StrictPlatformInfoGeneratorTest["entityTypeUsesAMinecraftIdentifier"] = 100] = "entityTypeUsesAMinecraftIdentifier"; StrictPlatformInfoGeneratorTest[StrictPlatformInfoGeneratorTest["entityTypeUsesAMinecraftRuntimeIdentifier"] = 101] = "entityTypeUsesAMinecraftRuntimeIdentifier"; StrictPlatformInfoGeneratorTest[StrictPlatformInfoGeneratorTest["itemTypeUsesAMinecraftIdentifier"] = 104] = "itemTypeUsesAMinecraftIdentifier"; })(StrictPlatformInfoGeneratorTest || (exports.StrictPlatformInfoGeneratorTest = StrictPlatformInfoGeneratorTest = {})); /** * Validates strict platform requirements for identifiers and runtime identifiers. * * @see {@link ../../public/data/forms/mctoolsval/strict.form.json} for topic definitions */ class StrictPlatformInfoGenerator { id = "STRICT"; title = "Strict Platform"; canAlwaysProcess = true; identifierOverridesAreErrors = false; summarize(info, infoSet) { } async generate(project, contentIndex) { const infoItems = []; if (project.isVanillaEditSession) { return infoItems; } const itemsCopy = project.getItemsCopy(); for (let i = 0; i < itemsCopy.length; i++) { const pi = itemsCopy[i]; if (pi.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior) { if (!pi.isContentLoaded) { await pi.loadContent(); } if (pi.primaryFile) { const bpEntityType = await EntityTypeDefinition_1.default.ensureOnFile(pi.primaryFile); if (bpEntityType) { await bpEntityType.load(); if (bpEntityType && bpEntityType._data && bpEntityType._data.description) { const desc = bpEntityType._data.description; if (desc.identifier !== undefined && desc.identifier.toLowerCase().startsWith("minecraft:")) { infoItems.push(new ProjectInfoItem_1.default(this.identifierOverridesAreErrors ? IInfoItemData_1.InfoItemType.error : IInfoItemData_1.InfoItemType.warning, this.id, StrictPlatformInfoGeneratorTest.entityTypeUsesAMinecraftIdentifier, `Uses a minecraft: identifier override`, pi, desc.identifier)); } if (desc.runtime_identifier !== undefined && desc.runtime_identifier.toLowerCase !== undefined && desc.runtime_identifier.toLowerCase().startsWith("minecraft:")) { infoItems.push(new ProjectInfoItem_1.default(this.identifierOverridesAreErrors ? IInfoItemData_1.InfoItemType.error : IInfoItemData_1.InfoItemType.warning, this.id, StrictPlatformInfoGeneratorTest.entityTypeUsesAMinecraftRuntimeIdentifier, `Uses a runtime_identifier override`, pi, desc.runtime_identifier)); } } } } } else if (pi.itemType === IProjectItemData_1.ProjectItemType.itemTypeBehavior) { if (!pi.isContentLoaded) { await pi.loadContent(); } if (pi.primaryFile) { const bpItemType = await ItemTypeDefinition_1.default.ensureOnFile(pi.primaryFile); if (bpItemType) { await bpItemType.load(); if (bpItemType && bpItemType.data && bpItemType.data.description) { const desc = bpItemType.data.description; if (desc.identifier !== undefined && desc.identifier.toLowerCase().startsWith("minecraft:")) { infoItems.push(new ProjectInfoItem_1.default(this.identifierOverridesAreErrors ? IInfoItemData_1.InfoItemType.error : IInfoItemData_1.InfoItemType.warning, this.id, StrictPlatformInfoGeneratorTest.itemTypeUsesAMinecraftIdentifier, `Uses a minecraft: identifier override`, pi, desc.identifier)); } } } } } } return infoItems; } } exports.default = StrictPlatformInfoGenerator;