@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
117 lines (115 loc) • 6.11 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnimationResourceInfoGeneratorTest = void 0;
const ProjectInfoItem_1 = require("./ProjectInfoItem");
const IProjectItemData_1 = require("../app/IProjectItemData");
const IInfoItemData_1 = require("./IInfoItemData");
const AnimationResourceDefinition_1 = require("../minecraft/AnimationResourceDefinition");
const ProjectInfoUtilities_1 = require("./ProjectInfoUtilities");
var AnimationResourceInfoGeneratorTest;
(function (AnimationResourceInfoGeneratorTest) {
AnimationResourceInfoGeneratorTest[AnimationResourceInfoGeneratorTest["animations"] = 1] = "animations";
AnimationResourceInfoGeneratorTest[AnimationResourceInfoGeneratorTest["bones"] = 2] = "bones";
})(AnimationResourceInfoGeneratorTest = exports.AnimationResourceInfoGeneratorTest || (exports.AnimationResourceInfoGeneratorTest = {}));
class AnimationResourceInfoGenerator {
constructor() {
this.id = "RESOURCEANIMATION";
this.title = "Resource Animation";
this.performAddOnValidations = false;
}
getTopicData(topicId) {
return {
title: ProjectInfoUtilities_1.default.getTitleFromEnum(AnimationResourceInfoGeneratorTest, topicId),
};
}
summarize(info, infoSet) {
info.animationCount = infoSet.getSummedNumberValue("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) {
await projectItem.ensureFileStorage();
if (projectItem.file) {
const ra = await AnimationResourceDefinition_1.default.ensureOnFile(projectItem.file);
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 (val.constructor === Array) {
isKeyframedBoneAnimation = true;
break;
}
}
if (isKeyframedBoneAnimation) {
boneCountPi.incrementFeature("Resource Animation Bone " + type + " Keyframe", "Count", 1);
for (const key in value) {
const val = value[key];
if (val.constructor === Array) {
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 (value.constructor === Array) {
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;
//# sourceMappingURL=../maps/info/AnimationResourceInfoGenerator.js.map