kaplay-atb-plugin
Version:
A KAPLAY plugin to create active time bar!
2 lines (1 loc) • 1.11 kB
JavaScript
(function(n,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(n=typeof globalThis<"u"?globalThis:n||self,n.Plugin=o())})(this,function(){"use strict";function n(o){return{createATB(c,a,y,d,w,b={radious:-1,outline:-1}){const{wrapperColor:x,barColor:C,radious:i,outline:f,reverse:l,stay:T}=b;let e=x??[0,0,0],r=C??[10,130,180];const p=o.add([o.rect(a,y),o.pos(d.x,d.y),l?o.color(r[0],r[1],r[2]):o.color(e[0],e[1],e[2]),f&&f>0?o.outline(f,l?o.color(r[0],r[1],r[2]).color:o.color(e[0],e[1],e[2]).color):"none"]);let t=l?100:0;c=c*10;const s=o.add([o.rect(a,y),o.pos(d.x,d.y),l?o.color(e[0],e[1],e[2]):o.color(r[0],r[1],r[2])]);i&&i>0&&(p.radius=i,s.radius=i);const h=o.loop(.1,()=>{const u=Math.floor(100/c);l?t=t-u<0?0:t-u:t=t+u>100?100:t+u;const g=a*(t/100);o.tween(s.width,g,0,v=>s.width=v,o.easings.linear)},c);return h.onEnd(()=>{w(),T||(p.destroy(),s.destroy())}),{wrapper:p,bar:s,controller:h,pause(){this.controller.paused=!this.controller.paused},remove(){this.controller.cancel(),this.wrapper.destroy(),this.bar.destroy()}}}}}return n});