UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

80 lines (79 loc) 4.79 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.CheckExperimentalFlagInfoGeneratorTest = void 0; const ProjectInfoItem_1 = __importDefault(require("../ProjectInfoItem")); const IInfoItemData_1 = require("../IInfoItemData"); const IProjectItemData_1 = require("../../app/IProjectItemData"); const MCWorld_1 = __importDefault(require("../../minecraft/MCWorld")); const WorldLevelDat_1 = __importDefault(require("../../minecraft/WorldLevelDat")); var CheckExperimentalFlagInfoGeneratorTest; (function (CheckExperimentalFlagInfoGeneratorTest) { CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["flagIsOrWasTrue"] = 101] = "flagIsOrWasTrue"; CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["levelDatNotFound"] = 102] = "levelDatNotFound"; CheckExperimentalFlagInfoGeneratorTest[CheckExperimentalFlagInfoGeneratorTest["worldNotFound"] = 103] = "worldNotFound"; })(CheckExperimentalFlagInfoGeneratorTest || (exports.CheckExperimentalFlagInfoGeneratorTest = CheckExperimentalFlagInfoGeneratorTest = {})); /*********** * Generator for Checking Experimental Flag for world * * Will ensure: * * experimental flag is false and has always been false or null * * @see {@link ../../../public/data/forms/mctoolsval/expflag.form.json} for topic definitions */ class CheckExperimentalFlagInfoGenerator { id = "EXPFLAG"; title = "Experimental Flags"; summarize(info, infoSet) { info.experimentalFlagIsOrWasTrue = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.flagIsOrWasTrue); info.levelDatNotFound = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.levelDatNotFound); info.worldNotFound = infoSet.getSummedDataValue(this.id, CheckExperimentalFlagInfoGeneratorTest.worldNotFound); } async generate(project) { const items = []; const projItems = project.getItemsCopy(); for (const item of projItems) { if (item.itemType !== IProjectItemData_1.ProjectItemType.MCWorld && item.itemType !== IProjectItemData_1.ProjectItemType.MCTemplate && item.itemType !== IProjectItemData_1.ProjectItemType.worldFolder && item.itemType !== IProjectItemData_1.ProjectItemType.levelDat && item.itemType !== IProjectItemData_1.ProjectItemType.levelDatOld) { continue; } let levelDat = undefined; if (item.itemType === IProjectItemData_1.ProjectItemType.MCWorld || item.itemType === IProjectItemData_1.ProjectItemType.MCTemplate || item.itemType === IProjectItemData_1.ProjectItemType.worldFolder) { const mcworld = await MCWorld_1.default.ensureOnItem(item); if (!mcworld) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.worldNotFound, "Could not load world.", item)); continue; } await mcworld.loadMetaFiles(); if (!mcworld.levelData) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.levelDatNotFound, "Level.dat not found in a broader world file.", item)); continue; } levelDat = mcworld.levelData; } else if (item.itemType === IProjectItemData_1.ProjectItemType.levelDat || item.itemType === IProjectItemData_1.ProjectItemType.levelDatOld) { if (!item.isContentLoaded) { await item.loadContent(); } if (item.primaryFile && item.primaryFile.content && item.primaryFile.content instanceof Uint8Array) { levelDat = new WorldLevelDat_1.default(); levelDat.loadFromNbtBytes(item.primaryFile.content); } } if (levelDat && (levelDat.experimentalGameplay === true || levelDat.experimentsEverUsed === true)) { items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckExperimentalFlagInfoGeneratorTest.flagIsOrWasTrue, "Experimental gameplay is or was enabled in this world. Shareable content should not use experimental features.", item)); } } return items; } } exports.default = CheckExperimentalFlagInfoGenerator;