UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

230 lines (228 loc) 19.6 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.CooperativeAddOnItemRequirementsGeneratorTest = void 0; const ProjectInfoItem_1 = require("./ProjectInfoItem"); const IProjectItemData_1 = require("../app/IProjectItemData"); const IInfoItemData_1 = require("./IInfoItemData"); const CooperativeAddOnRequirementsGenerator_1 = require("./CooperativeAddOnRequirementsGenerator"); const RenderControllerSetDefinition_1 = require("../minecraft/RenderControllerSetDefinition"); const ResourceManifestDefinition_1 = require("../minecraft/ResourceManifestDefinition"); const ModelGeometryDefinition_1 = require("../minecraft/ModelGeometryDefinition"); const Material_1 = require("../minecraft/Material"); const AnimationResourceDefinition_1 = require("../minecraft/AnimationResourceDefinition"); const AnimationBehaviorDefinition_1 = require("../minecraft/AnimationBehaviorDefinition"); const AnimationControllerBehaviorDefinition_1 = require("../minecraft/AnimationControllerBehaviorDefinition"); const AnimationControllerResourceDefinition_1 = require("../minecraft/AnimationControllerResourceDefinition"); const MinecraftDefinitions_1 = require("../minecraft/MinecraftDefinitions"); const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities"); // rule name/check. For validation errors, name should be a terse description of "your problem" var CooperativeAddOnItemRequirementsGeneratorTest; (function (CooperativeAddOnItemRequirementsGeneratorTest) { CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["BehaviorAnimationControllerIdNotInExpectedForm"] = 100] = "BehaviorAnimationControllerIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["BehaviorAnimationControllerNameNotInExpectedForm"] = 101] = "BehaviorAnimationControllerNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["BehaviorAnimationIdNotInExpectedForm"] = 110] = "BehaviorAnimationIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["BehaviorAnimationNameNotInExpectedForm"] = 111] = "BehaviorAnimationNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["JsonIdentifierNotInExpectedForm"] = 112] = "JsonIdentifierNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["ResourceAnimationControllerIdNotInExpectedForm"] = 120] = "ResourceAnimationControllerIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["ResourceAnimationControllerNameNotInExpectedForm"] = 121] = "ResourceAnimationControllerNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["ResourceAnimationIdNotInExpectedForm"] = 130] = "ResourceAnimationIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["ResourceAnimationNameNotInExpectedForm"] = 131] = "ResourceAnimationNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["RenderControllerIdNotInExpectedForm"] = 140] = "RenderControllerIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["RenderControllerNameNotInExpectedForm"] = 141] = "RenderControllerNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["GeometryIdNotInExpectedForm"] = 150] = "GeometryIdNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["GeometryNameNotInExpectedForm"] = 151] = "GeometryNameNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["MaterialsIdentifierNotInExpectedForm"] = 160] = "MaterialsIdentifierNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["MaterialsFirstSegmentNotInExpectedForm"] = 161] = "MaterialsFirstSegmentNotInExpectedForm"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["ResourcePackDoesNotHavePackScopeWorld"] = 170] = "ResourcePackDoesNotHavePackScopeWorld"; CooperativeAddOnItemRequirementsGeneratorTest[CooperativeAddOnItemRequirementsGeneratorTest["NoDimensionJson"] = 191] = "NoDimensionJson"; })(CooperativeAddOnItemRequirementsGeneratorTest = exports.CooperativeAddOnItemRequirementsGeneratorTest || (exports.CooperativeAddOnItemRequirementsGeneratorTest = {})); class CooperativeAddOnItemRequirementsGenerator { constructor() { this.id = "CADDONIREQ"; this.title = "Cooperative Add-On Item Requirements Generator"; this.canAlwaysProcess = true; } getTopicData(topicId) { return { title: ProjectInfoUtilities_1.default.getTitleFromEnum(CooperativeAddOnItemRequirementsGeneratorTest, topicId), }; } summarize(info, infoSet) { } async generate(projectItem, contentIndex) { const items = []; if (projectItem.itemType === IProjectItemData_1.ProjectItemType.dimensionJson) { // CADDONIREQ191 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.NoDimensionJson, `Dimension definition resources are not permitted in an add-on targeted behavior pack`, projectItem)); } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.resourcePackManifestJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const rpManifest = await ResourceManifestDefinition_1.default.ensureOnFile(projectItem.file); if (rpManifest) { await rpManifest.load(); if (!rpManifest.packScope) { // CADDONIREQ170 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.ResourcePackDoesNotHavePackScopeWorld, `Resource pack manifest does not specify that header/pack_scope that should be 'world'`, projectItem)); } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationControllerBehaviorJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const bacManifest = await AnimationControllerBehaviorDefinition_1.default.ensureOnFile(projectItem.file); if (bacManifest && bacManifest.data && bacManifest.data.animation_controllers) { for (let bacName in bacManifest.data.animation_controllers) { let bacNameBreak = bacName.split("."); if (bacNameBreak.length < 3 || bacNameBreak[0] !== "controller" || bacNameBreak[1] !== "animation") { // CADDONIREQ100 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.BehaviorAnimationControllerIdNotInExpectedForm, `Behavior pack animation controller identifier is not in the expected form of controller.animation.xyz`, projectItem, bacName)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(bacNameBreak[2])) { // CADDONIREQ101 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.BehaviorAnimationControllerNameNotInExpectedForm, `Behavior pack animation controller name section is not in the expected form of controller.animation.creatorshortname_projectshortname`, projectItem, bacName)); } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationBehaviorJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const baManifest = await AnimationBehaviorDefinition_1.default.ensureOnFile(projectItem.file); if (baManifest && baManifest.data && baManifest.data.animations) { for (let aName in baManifest.data.animations) { let baNameBreak = aName.split("."); if (baNameBreak.length < 2 || baNameBreak[0] !== "animation") { // CADDONIREQ110 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.BehaviorAnimationIdNotInExpectedForm, `Behavior animation identifier is not in the expected form of animation.xyz.animation_name`, projectItem, aName)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(baNameBreak[1])) { // CADDONIREQ111 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.BehaviorAnimationNameNotInExpectedForm, `Behavior pack animation name section is not in the expected form of animation.creatorshortname_projectshortname.animation_name`, projectItem, aName)); } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationControllerResourceJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const racManifest = await AnimationControllerResourceDefinition_1.default.ensureOnFile(projectItem.file); if (racManifest && racManifest.data && racManifest.data.animation_controllers) { for (let racName in racManifest.data.animation_controllers) { let racNameBreak = racName.split("."); if (racNameBreak.length < 3 || racNameBreak[0] !== "controller" || racNameBreak[1] !== "animation") { // CADDONIREQ120 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.ResourceAnimationControllerIdNotInExpectedForm, `Resource pack animation controller identifier is not in the expected form of controller.animation.xyz`, projectItem, racName)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(racNameBreak[2])) { // CADDONIREQ121 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.ResourceAnimationControllerNameNotInExpectedForm, `Resource pack animation controller name section is not in the expected form of controller.animation.creatorshortname_projectshortname`, projectItem, racName)); } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationResourceJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const raManifest = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.file); if (raManifest && raManifest.animations) { for (let aName in raManifest.animations) { let raNameBreak = aName.split("."); if (raNameBreak.length < 2 || raNameBreak[0] !== "animation") { // CADDONIREQ130 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.ResourceAnimationIdNotInExpectedForm, `Resource animation identifier is not in the expected form of animation.xyz.animation_name`, projectItem, aName)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(raNameBreak[1])) { // CADDONIREQ131 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.ResourceAnimationNameNotInExpectedForm, `Resource animation name section is not in the expected form of animation.creatorshortname_projectshortname.animation_name`, projectItem, aName)); } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.renderControllerJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const racManifest = await RenderControllerSetDefinition_1.default.ensureOnFile(projectItem.file); if (racManifest && racManifest.data && racManifest.data.render_controllers) { for (let rrcName in racManifest.data.render_controllers) { let racNameBreak = rrcName.split("."); if (racNameBreak.length < 3 || racNameBreak[0] !== "controller" || racNameBreak[1] !== "render") { // CADDONIREQ140 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.RenderControllerIdNotInExpectedForm, `Resource pack render controller identifier is not in the expected form of controller.render.creatorshortname_projectshortname.other`, projectItem, rrcName)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(racNameBreak[2])) { // CADDONIREQ141 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.RenderControllerNameNotInExpectedForm, `Resource pack render controller name section is not in the expected form of controller.render.creatorshortname_projectshortname`, projectItem, rrcName)); } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.modelGeometryJson) { await projectItem.ensureFileStorage(); if (projectItem.file) { const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.file); if (modGeo) { for (const modId of modGeo.identifiers) { if (modGeo && modId) { let modGeoBreaks = modId.split("."); if (modGeoBreaks.length < 2 || modGeoBreaks[0] !== "geometry") { // CADDONIREQ150 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.GeometryIdNotInExpectedForm, `Geometry is not in the expected form of geometry.creatorshortname_projectshortname.other`, projectItem, modId)); } else if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(modGeoBreaks[1])) { // CADDONIREQ151 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.GeometryNameNotInExpectedForm, `Geometry identifier section is not in the expected form of geometry.creatorshortname_projectshortname`, projectItem, modId)); } } } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.recipeBehavior || projectItem.itemType === IProjectItemData_1.ProjectItemType.entityTypeBehavior || projectItem.itemType === IProjectItemData_1.ProjectItemType.blockTypeBehavior || projectItem.itemType === IProjectItemData_1.ProjectItemType.itemTypeBehavior) { await projectItem.ensureFileStorage(); if (projectItem.file) { const projectItemDef = await MinecraftDefinitions_1.default.get(projectItem); if (projectItemDef && projectItemDef.id) { if (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(projectItemDef.id)) { // CADDONIREQ112 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.JsonIdentifierNotInExpectedForm, `JSON namespaced identifier is not in the expected form of creatorshortname_projectshortname:myitem`, projectItem, projectItemDef.id)); } } } } else if (projectItem.itemType === IProjectItemData_1.ProjectItemType.material) { await projectItem.ensureFileStorage(); if (projectItem.file) { const mat = await Material_1.default.ensureOnFile(projectItem.file); if (mat && mat.definition && mat.definition.materials) { for (const modId in mat.definition.materials) { let modIdBreaks = modId.split(":"); // CADDONIREQ160 if (modIdBreaks.length < 1) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.MaterialsIdentifierNotInExpectedForm, `Materials section identifier is not in the expected form of creatorshortname_projectshortname:other`, projectItem, modId)); } else if (modIdBreaks[0] !== "version" && (!CooperativeAddOnRequirementsGenerator_1.default.isNamespacedString(modIdBreaks[0]) || CooperativeAddOnRequirementsGenerator_1.default.isCommonMaterialName(modIdBreaks[0]))) { // CADDONIREQ161 items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.error, this.id, CooperativeAddOnItemRequirementsGeneratorTest.MaterialsFirstSegmentNotInExpectedForm, `First segment of a Materials section identifier is not in the expected form of creatorshortname_projectshortname_materialname or creatorshortname_projectshortname_materialname:baseitem`, projectItem, modId)); } } } } } return items; } } exports.default = CooperativeAddOnItemRequirementsGenerator; //# sourceMappingURL=../maps/info/CooperativeAddOnItemRequirementsGenerator.js.map