@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
292 lines (291 loc) • 14.7 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 });
const IProjectItemData_1 = require("../app/IProjectItemData");
const ContentIndex_1 = require("../core/ContentIndex");
const ModelGeometryDefinition_1 = __importDefault(require("../minecraft/ModelGeometryDefinition"));
const AnimationResourceDefinition_1 = __importDefault(require("../minecraft/AnimationResourceDefinition"));
const AnimationBehaviorDefinition_1 = __importDefault(require("../minecraft/AnimationBehaviorDefinition"));
const AnimationControllerResourceDefinition_1 = __importDefault(require("../minecraft/AnimationControllerResourceDefinition"));
const AnimationControllerBehaviorDefinition_1 = __importDefault(require("../minecraft/AnimationControllerBehaviorDefinition"));
const RenderControllerSetDefinition_1 = __importDefault(require("../minecraft/RenderControllerSetDefinition"));
const ParticleEffectResourceDefinition_1 = __importDefault(require("../minecraft/ParticleEffectResourceDefinition"));
const FogResourceDefinition_1 = __importDefault(require("../minecraft/FogResourceDefinition"));
const RecipeBehaviorDefinition_1 = __importDefault(require("../minecraft/RecipeBehaviorDefinition"));
const BiomeBehaviorDefinition_1 = __importDefault(require("../minecraft/BiomeBehaviorDefinition"));
const SpawnRulesBehaviorDefinition_1 = __importDefault(require("../minecraft/SpawnRulesBehaviorDefinition"));
const SoundDefinitionCatalogDefinition_1 = __importDefault(require("../minecraft/SoundDefinitionCatalogDefinition"));
const StorageUtilities_1 = __importDefault(require("../storage/StorageUtilities"));
class CrossReferenceIndexGenerator {
id = "CROSSREFINDEX";
title = "Cross-Reference Index";
performAddOnValidations = false;
summarize(_info, _infoSet) {
// No summary needed — this generator only populates the content index
}
async generate(project, contentIndex) {
const itemsCopy = project.getItemsCopy();
for (const projectItem of itemsCopy) {
const path = projectItem.projectPath;
if (!path) {
continue;
}
switch (projectItem.itemType) {
case IProjectItemData_1.ProjectItemType.modelGeometryJson:
await this.indexGeometry(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.animationResourceJson:
await this.indexAnimationResource(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.animationBehaviorJson:
await this.indexAnimationBehavior(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.animationControllerResourceJson:
await this.indexAnimationControllerResource(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.animationControllerBehaviorJson:
await this.indexAnimationControllerBehavior(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.renderControllerJson:
await this.indexRenderController(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.particleJson:
await this.indexParticle(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.fogResourceJson:
await this.indexFog(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.soundDefinitionCatalog:
await this.indexSoundDefinitions(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.lootTableBehavior:
this.indexLootTable(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.recipeBehavior:
await this.indexRecipe(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.biomeBehavior:
await this.indexBiome(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.spawnRuleBehavior:
await this.indexSpawnRule(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.dialogueBehaviorJson:
this.indexDialogue(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.MCFunction:
this.indexFunction(projectItem, contentIndex, path);
break;
case IProjectItemData_1.ProjectItemType.structure:
this.indexStructure(projectItem, contentIndex, path);
break;
}
}
return [];
}
async indexGeometry(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const modGeo = await ModelGeometryDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (modGeo && modGeo.identifiers) {
for (const geoId of modGeo.identifiers) {
contentIndex.insert(geoId, path, ContentIndex_1.AnnotationCategory.geometrySource);
}
}
}
}
async indexAnimationResource(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const animDef = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (animDef && animDef.animations) {
for (const animName in animDef.animations) {
contentIndex.insert(animName, path, ContentIndex_1.AnnotationCategory.animationSource);
}
}
}
}
async indexAnimationBehavior(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const animDef = await AnimationBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (animDef) {
const data = animDef.data;
if (data && data.animations) {
for (const animName in data.animations) {
contentIndex.insert(animName, path, ContentIndex_1.AnnotationCategory.animationSource);
}
}
}
}
}
async indexAnimationControllerResource(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const acDef = await AnimationControllerResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (acDef && acDef.idList) {
for (const acId of acDef.idList) {
contentIndex.insert(acId, path, ContentIndex_1.AnnotationCategory.animationControllerSource);
}
}
}
}
async indexAnimationControllerBehavior(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const acDef = await AnimationControllerBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (acDef) {
const data = acDef.data;
if (data && data.animation_controllers) {
for (const acId in data.animation_controllers) {
contentIndex.insert(acId, path, ContentIndex_1.AnnotationCategory.animationControllerSource);
}
}
}
}
}
async indexRenderController(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const rcDef = await RenderControllerSetDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (rcDef && rcDef.idList) {
for (const rcId of rcDef.idList) {
contentIndex.insert(rcId, path, ContentIndex_1.AnnotationCategory.renderControllerSource);
}
}
}
}
async indexParticle(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const particleDef = await ParticleEffectResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (particleDef && particleDef.id) {
contentIndex.insert(particleDef.id, path, ContentIndex_1.AnnotationCategory.particleSource);
}
}
}
async indexFog(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const fogDef = await FogResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (fogDef && fogDef.id) {
contentIndex.insert(fogDef.id, path, ContentIndex_1.AnnotationCategory.fogSource);
}
}
}
async indexSoundDefinitions(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const soundDef = await SoundDefinitionCatalogDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (soundDef) {
const soundNames = soundDef.getSoundDefinitionSetNameList();
if (soundNames) {
for (const soundName of soundNames) {
contentIndex.insert(soundName, path, ContentIndex_1.AnnotationCategory.soundEventSource);
}
}
}
}
}
indexLootTable(projectItem, contentIndex, path) {
// Loot tables are referenced by their path relative to the pack root
// e.g., "loot_tables/entities/zombie.json"
const normalizedPath = path.replace(/\\/g, "/");
const lootTablesIdx = normalizedPath.indexOf("loot_tables/");
if (lootTablesIdx >= 0) {
const lootPath = normalizedPath.substring(lootTablesIdx);
contentIndex.insert(lootPath, path, ContentIndex_1.AnnotationCategory.lootTableSource);
}
}
async indexRecipe(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const recipeDef = await RecipeBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (recipeDef && recipeDef.id) {
contentIndex.insert(recipeDef.id, path, ContentIndex_1.AnnotationCategory.recipeSource);
}
}
}
async indexBiome(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const biomeDef = await BiomeBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (biomeDef && biomeDef.id) {
contentIndex.insert(biomeDef.id, path, ContentIndex_1.AnnotationCategory.biomeSource);
}
}
}
async indexSpawnRule(projectItem, contentIndex, path) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const spawnDef = await SpawnRulesBehaviorDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (spawnDef && spawnDef.id) {
contentIndex.insert(spawnDef.id, path, ContentIndex_1.AnnotationCategory.spawnRuleSource);
}
}
}
indexDialogue(projectItem, contentIndex, path) {
// Dialogues are referenced by their scene tag, but we index path as well
const normalizedPath = path.replace(/\\/g, "/");
const baseName = StorageUtilities_1.default.getBaseFromName(normalizedPath);
if (baseName) {
contentIndex.insert(baseName, path, ContentIndex_1.AnnotationCategory.dialogueSource);
}
}
indexFunction(projectItem, contentIndex, path) {
// Functions are referenced by path relative to functions/ folder, without extension
// e.g., "my_function" from "functions/my_function.mcfunction"
const normalizedPath = path.replace(/\\/g, "/");
const functionsIdx = normalizedPath.indexOf("functions/");
if (functionsIdx >= 0) {
let funcPath = normalizedPath.substring(functionsIdx + "functions/".length);
// Remove .mcfunction extension
if (funcPath.endsWith(".mcfunction")) {
funcPath = funcPath.substring(0, funcPath.length - ".mcfunction".length);
}
contentIndex.insert(funcPath, path, ContentIndex_1.AnnotationCategory.functionSource);
}
}
indexStructure(projectItem, contentIndex, path) {
// Structures are referenced by namespace:name format or by path
const normalizedPath = path.replace(/\\/g, "/");
const structuresIdx = normalizedPath.indexOf("structures/");
if (structuresIdx >= 0) {
let structPath = normalizedPath.substring(structuresIdx + "structures/".length);
// Remove .mcstructure extension
if (structPath.endsWith(".mcstructure")) {
structPath = structPath.substring(0, structPath.length - ".mcstructure".length);
}
contentIndex.insert(structPath, path, ContentIndex_1.AnnotationCategory.structureSource);
}
}
}
exports.default = CrossReferenceIndexGenerator;