@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
118 lines (117 loc) • 6.23 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.AnimationResourceInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = __importDefault(require("./ProjectInfoItem"));
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const AnimationResourceDefinition_1 = __importDefault(require("../minecraft/AnimationResourceDefinition"));
const ProjectInfoUtilities_1 = __importDefault(require("./ProjectInfoUtilities"));
var AnimationResourceInfoGeneratorTest;
(function (AnimationResourceInfoGeneratorTest) {
AnimationResourceInfoGeneratorTest[AnimationResourceInfoGeneratorTest["animations"] = 101] = "animations";
AnimationResourceInfoGeneratorTest[AnimationResourceInfoGeneratorTest["bones"] = 102] = "bones";
})(AnimationResourceInfoGeneratorTest || (exports.AnimationResourceInfoGeneratorTest = AnimationResourceInfoGeneratorTest = {}));
/**
* Aggregates animation resource information from resource packs.
*
* @see {@link ../../public/data/forms/mctoolsval/resourceanimation.form.json} for topic definitions
*/
class AnimationResourceInfoGenerator {
id = "RESOURCEANIMATION";
title = "Resource Animation";
performAddOnValidations = false;
summarize(info, infoSet) {
info.animationCount = infoSet.getSummedDataValue("RESOURCEANIMATION", 1);
}
async generate(project, contentIndex) {
const items = [];
const animationCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, AnimationResourceInfoGeneratorTest.animations, ProjectInfoUtilities_1.default.getTitleFromEnum(AnimationResourceInfoGeneratorTest, AnimationResourceInfoGeneratorTest.animations));
items.push(animationCountPi);
const boneCountPi = new ProjectInfoItem_1.default(IInfoItemData_1.InfoItemType.featureAggregate, this.id, AnimationResourceInfoGeneratorTest.bones, ProjectInfoUtilities_1.default.getTitleFromEnum(AnimationResourceInfoGeneratorTest, AnimationResourceInfoGeneratorTest.bones));
items.push(boneCountPi);
const itemsCopy = project.getItemsCopy();
for (const projectItem of itemsCopy) {
if (projectItem.itemType === IProjectItemData_1.ProjectItemType.animationResourceJson) {
if (!projectItem.isContentLoaded) {
await projectItem.loadContent();
}
if (projectItem.primaryFile) {
const ra = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.primaryFile);
if (ra && ra.animations) {
for (const animationName in ra.animations) {
const animation = ra.animations[animationName];
animationCountPi.incrementFeature("Resource", "Count", 1);
if (animation && animation.bones) {
for (const boneName in animation.bones) {
const bone = animation.bones[boneName];
if (bone) {
boneCountPi.incrementFeature("Resource Animation Bone", "Count", 1);
if (bone.position) {
this.processAnimationValue(boneCountPi, bone.position, "Position");
}
if (bone.rotation) {
this.processAnimationValue(boneCountPi, bone.rotation, "Rotation");
}
if (bone.scale) {
this.processAnimationValue(boneCountPi, bone.scale, "Scale");
}
}
}
}
}
}
}
}
}
return items;
}
processAnimationValue(boneCountPi, value, type) {
let isKeyframedBoneAnimation = false;
if (typeof value === "string") {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Expression", "Count", 1);
return;
}
for (const key in value) {
const val = value[key];
if (Array.isArray(val)) {
isKeyframedBoneAnimation = true;
break;
}
}
if (isKeyframedBoneAnimation) {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Keyframe", "Count", 1);
for (const key in value) {
const val = value[key];
if (Array.isArray(val)) {
for (const valAtom of val) {
if (typeof valAtom === "string") {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Keyframe with Molang", "Count", 1);
}
else {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Keyframe", "Count", 1);
}
}
}
}
}
else {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Continuous", "Count", 1);
if (Array.isArray(value)) {
for (const val of value) {
if (typeof val.position === "string") {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Continuous with Molang", "Count", 1);
}
else {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Continuous", "Count", 1);
}
}
}
}
}
}
exports.default = AnimationResourceInfoGenerator;