@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
244 lines (243 loc) • 20.3 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.CooperativeAddOnItemRequirementsGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const CooperativeAddOnRequirementsGenerator_1 = __importDefault(require("./CooperativeAddOnRequirementsGenerator"));
const RenderControllerSetDefinition_1 = __importDefault(require("../minecraft/RenderControllerSetDefinition"));
const ResourceManifestDefinition_1 = __importDefault(require("../minecraft/ResourceManifestDefinition"));
const ModelGeometryDefinition_1 = __importDefault(require("../minecraft/ModelGeometryDefinition"));
const Material_1 = __importDefault(require("../minecraft/Material"));
const AnimationResourceDefinition_1 = __importDefault(require("../minecraft/AnimationResourceDefinition"));
const AnimationBehaviorDefinition_1 = __importDefault(require("../minecraft/AnimationBehaviorDefinition"));
const AnimationControllerBehaviorDefinition_1 = __importDefault(require("../minecraft/AnimationControllerBehaviorDefinition"));
const AnimationControllerResourceDefinition_1 = __importDefault(require("../minecraft/AnimationControllerResourceDefinition"));
const MinecraftDefinitions_1 = __importDefault(require("../minecraft/MinecraftDefinitions"));
/**
* Validates cooperative add-on item requirements for naming conventions and identifiers.
*
* @see {@link ../../public/data/forms/mctoolsval/caddonireq.form.json} for topic definitions
*/
// 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 = CooperativeAddOnItemRequirementsGeneratorTest = {}));
class CooperativeAddOnItemRequirementsGenerator {
id = "CADDONIREQ";
title = "Cooperative Add-On Item Requirements Generator";
canAlwaysProcess = true;
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const rpManifest = await ResourceManifestDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const bacManifest = await AnimationControllerBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const baManifest = await AnimationBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const racManifest = await AnimationControllerResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const raManifest = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const racManifest = await RenderControllerSetDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.primaryFile);
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.loadFileContent();
if (projectItem.primaryFile) {
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) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const mat = await Material_1.default.ensureOnFile(projectItem.primaryFile);
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;