@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
124 lines (123 loc) • 6.63 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.CheckFeatureDeprecationInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("../ProjectInfoItem"));
const IInfoItemData_1 = require("../IInfoItemData");
const StorageUtilities_1 = __importDefault(require("../../storage/StorageUtilities"));
var CheckFeatureDeprecationInfoGeneratorTest;
(function (CheckFeatureDeprecationInfoGeneratorTest) {
CheckFeatureDeprecationInfoGeneratorTest[CheckFeatureDeprecationInfoGeneratorTest["deprecatedBlockOverride"] = 101] = "deprecatedBlockOverride";
CheckFeatureDeprecationInfoGeneratorTest[CheckFeatureDeprecationInfoGeneratorTest["deprecatedTerrainTexture"] = 102] = "deprecatedTerrainTexture";
CheckFeatureDeprecationInfoGeneratorTest[CheckFeatureDeprecationInfoGeneratorTest["deprecatedTexture"] = 103] = "deprecatedTexture";
CheckFeatureDeprecationInfoGeneratorTest[CheckFeatureDeprecationInfoGeneratorTest["jsonParseError"] = 104] = "jsonParseError";
})(CheckFeatureDeprecationInfoGeneratorTest || (exports.CheckFeatureDeprecationInfoGeneratorTest = CheckFeatureDeprecationInfoGeneratorTest = {}));
const DEPRECATED_BLOCKS = ["fletching_table", "smithing_table"];
const DEPRECATED_TEXTURES = [
"smithing_table_top.png",
"smithing_table_side1.png",
"smithing_table_side2.png",
"fletcher_table_top.png",
"fletcher_table_side1.png",
"fletcher_table_side2.png",
];
const DEPRECATED_TEXTURE_ENTRIES = [
"smithing_table_top",
"smithing_table_side_a",
"smithing_table_side_b",
"fletching_table_top",
"fletching_table_side1",
"fletching_table_side2",
];
/***********
* Generator for Checking Feature Deprecation
*
* Will check:
* * blocks.json for deprecated block overrides (fletching_table, smithing_table)
* * terrain_texture.json for deprecated texture entries
* * textures/blocks/ folder for deprecated textures
*
* @see {@link ../../../public/data/forms/mctoolsval/checkfeaturedeprecation.form.json} for topic definitions
*/
class CheckFeatureDeprecationInfoGenerator {
id = "CHECKFEATUREDEPRECATION";
title = "Feature Deprecation";
summarize(info, infoSet) {
info.deprecatedBlockOverride = infoSet.getSummedDataValue(this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedBlockOverride);
info.deprecatedTerrainTexture = infoSet.getSummedDataValue(this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedTerrainTexture);
info.deprecatedTexture = infoSet.getSummedDataValue(this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedTexture);
}
async generate(project) {
const items = [];
const projItems = project.getItemsCopy();
for (const item of projItems) {
if (item.name === "blocks.json") {
if (!item.isContentLoaded) {
await item.loadContent();
}
if (!item.primaryFile) {
continue;
}
if (!item.primaryFile.isContentLoaded) {
await item.primaryFile.loadContent();
}
const content = item.primaryFile.content;
if (!content || typeof content !== "string") {
continue;
}
try {
const parsedContent = StorageUtilities_1.default.getJsonObject(item.primaryFile);
if (parsedContent) {
for (const deprecatedBlock of DEPRECATED_BLOCKS) {
if (parsedContent[deprecatedBlock]) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedBlockOverride, `Entity [${deprecatedBlock}] will be affected in an upcoming client update.`, item, deprecatedBlock));
}
}
}
}
catch (error) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckFeatureDeprecationInfoGeneratorTest.jsonParseError, `Failed to parse JSON for entity. Error: ${error}`, item));
}
}
if (item.name === "terrain_texture.json") {
if (!item.isContentLoaded) {
await item.loadContent();
}
if (!item.primaryFile) {
continue;
}
if (!item.primaryFile.isContentLoaded) {
await item.primaryFile.loadContent();
}
const content = item.primaryFile.content;
if (!content || typeof content !== "string") {
continue;
}
const parsedContent = StorageUtilities_1.default.getJsonObject(item.primaryFile);
try {
if (parsedContent) {
for (const deprecatedTexture of DEPRECATED_TEXTURE_ENTRIES) {
if (parsedContent.texture_data[deprecatedTexture]) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedTerrainTexture, `Entity [${deprecatedTexture}] will be affected in an upcoming client update.`, item, deprecatedTexture));
}
}
}
}
catch (error) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckFeatureDeprecationInfoGeneratorTest.jsonParseError, `Failed to parse JSON for entity. Error: ${error}`, item));
}
}
if (item.getFolder()?.name === "blocks") {
if (DEPRECATED_TEXTURES.includes(item.name)) {
items.push(new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.warning, this.id, CheckFeatureDeprecationInfoGeneratorTest.deprecatedTexture, `Texture [${item.name}] will be affected in an upcoming client update. Please resubmit with no modifications to this texture.`, item, item.name));
}
}
}
return items;
}
}
exports.default = CheckFeatureDeprecationInfoGenerator;