UNPKG

kaplay-atb-plugin

Version:

A KAPLAY plugin to create active time bar!

64 lines (63 loc) 2.49 kB
function B(o) { return { /** * Creates an ATB (Active Time Battle) bar. * @param time - Number of seconds for the ATB to fill * @param width - Width of the ATB bar * @param height - Height of the ATB bar * @param pos - Position of the ATB bar in the game world * @param action - Function to call when the ATB bar is filled * @param options - Optional parameters for customizing the ATB bar * @param options.wrapperColor - Color of the wrapper in rgb format (default: [0, 0, 0]) * @param options.barColor - Color of the ATB bar in rgb format (default: [10, 130, 180]) * @param options.radious - A number to set radius for the corners of the ATB bar (default: null) * @param options.outline - A number to set the weight of outline (default : null) * @param options.reverse - If true, the bar will fill in reverse order (default: false) * @param options.stay - If true, the bar will stay on the screen after filling (default: false) * @returns - An object containing the wrapper, bar, and controller for the ATB bar */ createATB(s, i, y, a, w, h = { radious: -1, outline: -1 }) { const { wrapperColor: b, barColor: C, radious: c, outline: u, reverse: l, stay: x } = h; let r = b ?? [0, 0, 0], e = C ?? [10, 130, 180]; const p = o.add([ o.rect(i, y), o.pos(a.x, a.y), l ? o.color(e[0], e[1], e[2]) : o.color(r[0], r[1], r[2]), u && u > 0 ? o.outline(u, l ? o.color(e[0], e[1], e[2]).color : o.color(r[0], r[1], r[2]).color) : "none" ]); let t = l ? 100 : 0; s = s * 10; const n = o.add([ o.rect(i, y), o.pos(a.x, a.y), l ? o.color(r[0], r[1], r[2]) : o.color(e[0], e[1], e[2]) ]); c && c > 0 && (p.radius = c, n.radius = c); const f = o.loop(0.1, () => { const d = Math.floor(100 / s); l ? t = t - d < 0 ? 0 : t - d : t = t + d > 100 ? 100 : t + d; const v = i * (t / 100); o.tween(n.width, v, 0, (A) => n.width = A, o.easings.linear); }, s); return f.onEnd(() => { w(), x || (p.destroy(), n.destroy()); }), { wrapper: p, bar: n, controller: f, pause() { this.controller.paused = !this.controller.paused; }, remove() { this.controller.cancel(), this.wrapper.destroy(), this.bar.destroy(); } }; } }; } export { B as default };