asajs
Version:
Make your Minecraft JsonUI with ScriptingAPI
128 lines (127 loc) • 4.97 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var Animation_exports = {};
__export(Animation_exports, {
Animation: () => Animation
});
module.exports = __toCommonJS(Animation_exports);
var import_Config = require("../compilers/Config");
var import_AnimTypes = require("../types/enums/AnimTypes");
var import_AnimationKeyFrame = require("./AnimationKeyFrame");
var import_Class = require("./Class");
var import_Random = require("./Random");
class Animation extends import_Class.Class {
constructor(animation, identifier) {
super();
this.identifier = identifier;
__publicField(this, "keyFrames", []);
__publicField(this, "buildKey", 0);
__publicField(this, "config", import_Config.Configs.getConfig());
if (!(identifier && !this.config.compiler.UI.obfuscateName))
identifier = {
name: import_Random.Random.getAnimationName(),
namespace: import_Random.Random.getNamespace()
};
else {
if (!identifier.name) identifier.name = import_Random.Random.getAnimationName();
if (!identifier.namespace) identifier.namespace = import_Random.Random.getAnimationName();
}
this.buildAnimation(animation, identifier);
}
static register(animation, identifier) {
return new Animation(animation, identifier);
}
getKeyIndex(index) {
let i = index < 0 ? 0 : Math.min(index, this.keyFrames.length);
return "@".concat(this.keyFrames[index]);
}
buildAnimation({ from, keyFrames, loop, type, durationPerKeyFrame = 1, smartCycle, defaultEase }, identifier) {
var _a;
const prefix = keyFrames.length - 1;
if ((smartCycle === void 0 || smartCycle) && loop) {
if (typeof keyFrames[prefix] == "number") keyFrames[prefix] = {
duration: keyFrames[prefix],
to: from
};
else if (JSON.stringify(keyFrames[prefix].to) != JSON.stringify(from)) {
keyFrames.push({
to: (_a = keyFrames[0].from) != null ? _a : from,
duration: durationPerKeyFrame,
easing: defaultEase
});
}
}
const frameLength = keyFrames.length - 1;
keyFrames.forEach((keyFrame, index) => {
var _a2;
this.keyFrames.push("".concat(identifier.namespace, ".").concat(identifier.name));
const currentIdentifier = identifier;
let next;
if (index === frameLength) {
if (loop) next = this.getKeyIndex(0);
} else {
identifier = this.generateIdentifier();
next = this.getFrameKeyByIdentifier(identifier);
}
if (typeof keyFrame == "number") {
new import_AnimationKeyFrame.AnimationKeyFrame(
{
next,
anim_type: import_AnimTypes.AnimationTypes.Wait,
duration: keyFrame
},
currentIdentifier
);
} else {
new import_AnimationKeyFrame.AnimationKeyFrame(
{
next,
anim_type: type,
from,
duration: (_a2 = keyFrame.duration) != null ? _a2 : durationPerKeyFrame,
easing: defaultEase,
...keyFrame
},
currentIdentifier
);
}
if (typeof keyFrame === "object") from = keyFrame.to;
});
}
generateIdentifier() {
var _a, _b;
if (this.config.compiler.UI.obfuscateName) return {
name: import_Random.Random.getAnimationName(),
namespace: import_Random.Random.getNamespace()
};
else return {
name: ((_a = this.identifier) == null ? void 0 : _a.name) ? "".concat(this.identifier.name, "-f").concat(this.buildKey++) : import_Random.Random.getAnimationName(),
namespace: ((_b = this.identifier) == null ? void 0 : _b.namespace) || import_Random.Random.getNamespace()
};
}
getFrameKeyByIdentifier(identifier) {
return "@".concat(identifier.namespace, ".").concat(identifier.name);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Animation
});