Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var _, C, C, C, C, C, C, S = C.Sn,
- H = C.Ip,
- I = C.In,
- aW = C.Teks.Write,
- aX = C.Teks.WriteLn,
- aY = C.Teks.Name,
- aZ = C.Teks.Size,
- bA = C.Teks.Align;
- (function(ha) {
- (function(_a) {
- class Cache {
- constructor() {
- this.files = []
- }
- getGbr(_A) {
- for (let i = 0; i < this.files.length; i++)
- if (this.files[i].url == _A) return this.files[i].img;
- return null
- }
- setFile(bD, _b) {
- let _c;
- _c = this.getGbr(bD);
- if (_c) return;
- this.files.push({
- url: bD,
- img: _b
- })
- }
- }
- _a.cache = new Cache
- })()
- })(_ || (_ = {}));
- var C;
- (function(bE) {
- class Camera {
- static get x() {
- return Camera._x
- }
- static set x(bF) {
- Camera._x = bF
- }
- static get y() {
- return Camera._y
- }
- static set y(bG) {
- Camera._y = bG
- }
- static get img() {
- return Camera._img
- }
- static set img(bH) {
- Camera._img = bH
- }
- static init() {
- function bI() {
- window.requestAnimationFrame(bI)
- }
- window.requestAnimationFrame(bI)
- }
- }
- Camera._x = Camera._y = 0;
- bE.Camera = Camera
- })(C || (C = {}));
- (function(bJ) {
- (function(bK) {
- bK['MOUSE_DOWN'] = 'mousedown';
- bK['MOUSE_UP'] = 'mouseup';
- bK['MOUSE_MOVE'] = 'mousemove';
- bK['MOUSE_CLICK'] = 'mouseclick';
- bK['MOUSE_START_DRAG'] = 'mousestartdrag';
- bK['MOUSE_END_DRAG'] = 'mouseenddrag';
- bK['KEYB_DOWN'] = 'keybdown';
- bK['KEYB_UP'] = 'keybup';
- bK['SOUND_LOADED'] = 'soundloaded';
- bK['SOUND_ENDED'] = 'soundended'
- })();
- class Event {
- constructor(bL, f) {
- this._type = '';
- this._type = bL;
- this._f = f
- }
- get type() {
- return this._type
- }
- get f() {
- return this._f
- }
- static addEventListener(bM, f) {
- let e = new Event(bM.toLowerCase(), f);
- Event.list.push(e);
- console.log('add listener: type ', bM);
- return e
- }
- static dispatchEvent(bN) {
- for (const bO of Event.list) bO.type === bN.toLowerCase() && bO.f()
- }
- }
- Event.list = [];
- bJ.Event = Event
- })(C || (C = {}));
- var C;
- (function(bP) {
- class Graphic {
- static handleWindowResize() {
- if (!bP.G._autoScale) return;
- let bQ = bP.G.drawCanvas;
- let _B = bP.G.drawCanvas.width;
- let _C = bP.G.drawCanvas.height;
- let _d = window.innerWidth;
- let _e = window.innerHeight;
- let _f = Math.min((_d / _B), (_e / _C));
- let _g = ~~_B * _f;
- let _h = ~~_C * _f;
- bQ.style.position = 'fixed';
- bQ.style.zIndex = '1';
- bQ.style.width = `${_g}px`;
- bQ.style.height = `${_h}px`;
- bQ.style.top = ((_e - _h) / 2) + 'px';
- bQ.style.left = ((_d - _g) / 2) + 'px'
- }
- static buildCanvas(w, h) {
- let bR;
- bR = document.body.querySelector('canvas');
- if (!bR) {
- bR = document.createElement('canvas');
- document.body.appendChild(bR);
- w && (bR.width = w);
- h && (bR.height = h)
- }
- return bR
- }
- static Canvas() {
- return bP.G.drawCanvas
- }
- static SetCanvas(bS) {
- bP.G.drawCanvas = bS
- }
- static initComp() {
- bP.In.init(bP.G.drawCanvas);
- bP.Keyboard.init();
- bP.Camera.init();
- bP.sprInt.init()
- }
- static initEvent() {
- function bT(bU) {
- let w = window;
- (w[bU] && (typeof w[bU] == 'function')) && w[bU]()
- }
- bP.Event.addEventListener(bP.Evt.KEYB_DOWN, () => bT('KeyboardDown'));
- bP.Event.addEventListener(bP.Evt.KEYB_UP, () => bT('KeyboardUp'));
- bP.Event.addEventListener(bP.Evt.MOUSE_DOWN, () => bT('MouseDown'));
- bP.Event.addEventListener(bP.Evt.MOUSE_END_DRAG, () => bT('MouseEndDrag'));
- bP.Event.addEventListener(bP.Evt.MOUSE_MOVE, () => bT('MouseMove'));
- bP.Event.addEventListener(bP.Evt.MOUSE_START_DRAG, () => bT('MouseStartDrag'));
- bP.Event.addEventListener(bP.Evt.MOUSE_CLICK, () => bT('MouseClick'));
- bP.Event.addEventListener(bP.Evt.MOUSE_UP, () => bT('MouseUp'));
- bP.Event.addEventListener('update', () => bT('Update'));
- bP.Event.addEventListener(bP.Evt.SOUND_ENDED, () => bT('SoundEnded'));
- bP.Event.addEventListener(bP.Evt.SOUND_LOADED, () => bT('SoundLoaded'))
- }
- static Start(bV) {
- bP.G.Graphics(0, 0, bV, 0)
- }
- static Graphics(w, h, bW = null, _D = 1) {
- console.log('init');
- !bW && (bW = bP.G.buildCanvas(w, h));
- bP.G.drawCanvas = bW;
- bP.G._autoScale = (_D == 1);
- bP.G.setupMainCanvas(w, h, _D);
- bP.G.initComp();
- bP.G.initEvent();
- function _E() {
- bP.Event.dispatchEvent('update');
- window.requestAnimationFrame(_E)
- }
- window.requestAnimationFrame(_E);
- setTimeout(() => bP.G.handleWindowResize(), 100);
- bP.G.handleWindowResize();
- N();
- V(0, 0, 0, 0);
- aV(0, 10);
- aZ(10)
- }
- static setupMainCanvas(p, l, bX = 1) {
- p && (bP.G.drawCanvas.width = p);
- l && (bP.G.drawCanvas.height = l);
- bX == 1 && (bP.G.drawCanvas.style.width = `${p}px`, bP.G.drawCanvas.style.padding = '0px', bP.G.drawCanvas.style.margin = '0px', window.addEventListener('resize', () => bP.G.handleWindowResize()))
- }
- static Cls(x = 0, y = 0, w = 0, h = 0) {
- let bY = bP.G.drawCanvas.getContext('2d');
- w = w || bP.G.drawCanvas.width;
- h = h || bP.G.drawCanvas.height;
- bY.clearRect(x, y, w, h)
- }
- static get red() {
- return bP.G._red
- }
- static set red(bZ) {
- bP.G._red = bZ
- }
- static get green() {
- return bP.G._green
- }
- static set green(cA) {
- bP.G._green = cA
- }
- static get blue() {
- return bP.G._blue
- }
- static set blue(cB) {
- bP.G._blue = cB
- }
- static get alpha() {
- return bP.G._transparan
- }
- static set alpha(cC) {
- bP.G._transparan = cC
- }
- }
- Graphic._autoScale = !0;
- Graphic._red = Graphic._green = Graphic._blue = Graphic._transparan = 0;
- bP.Graphic = bP.G = Graphic
- })(C || (C = {}));
- (function(cD) {
- let cE;
- (function(cF) {
- class EventHandler {
- move(cG, cH, e) {
- let cI = Input.getPos(e.clientX, e.clientY, cH);
- cG.x = cI.x;
- cG.y = cI.y;
- cG.moveX = e.movementX;
- cG.moveY = e.movementY
- }
- down(cJ, cK) {
- cJ.xStart = cK.x;
- cJ.yStart = cK.y;
- cJ.xDrag = cJ.yDrag = 0;
- cJ.x = cK.x;
- cJ.y = cK.y;
- cJ.isDown = !0;
- cJ.isTap = cJ.isDrag = !1;
- cJ.timerStart = Date.now()
- }
- up(cL) {
- cL.isDown = cL.isDrag = !1;
- cL.timerEnd = Date.now()
- }
- }
- cF.EventHandler = EventHandler;
- class InpuObj {
- constructor() {
- this.id = this.pointerType = '';
- this.xStart = this.yStart = this.xDrag = this.yDrag = this.moveX = this.moveY = this.x = this.y = 0;
- this._isDrag = this.isDown = this.isTap = !1;
- this.evt = null;
- this.button = -1;
- this.timerStart = this.timerEnd = this.pointerId = 0
- }
- get isDrag() {
- return this._isDrag
- }
- set isDrag(cM) {
- this._isDrag = cM
- }
- }
- cF.InpuObj = InpuObj
- })(cE || (cE = {}));
- class Input {
- constructor() {}
- static get lastButton() {
- return Input._lastButton
- }
- static get keyboardEvent() {
- return Input._keyboardEvent
- }
- static set keyboardEvent(cN) {
- Input._keyboardEvent = cN
- }
- static get pointerEvent() {
- return Input._pointerEvent
- }
- static get debug() {
- return Input._debug
- }
- static set debug(cO) {
- Input._debug = cO
- }
- static getMouse() {
- for (let i = 0; i < Input.lst.length; i++) {
- let cP = Input.lst[i];
- if (cP.pointerType == 'mouse') return cP
- }
- return null
- }
- static getByDraggedStatus(cQ) {
- for (let i = 0; i < Input.lst.length; i++) {
- let cR = Input.lst[i];
- if (cR.isDrag && (cR.pointerType == 'mouse') && cR.button == cQ) return cR;
- if (cR.isDrag && (cR.pointerType == 'touch')) return cR
- }
- return null
- }
- static getByButton(cS) {
- for (let i = 0; i < Input.lst.length; i++) {
- let cT = Input.lst[i];
- if (cT.pointerType == 'mouse')
- if (cT.button == cS) return cT
- }
- return null
- }
- static getById(id) {
- for (let i = 0; i < Input.lst.length; i++) {
- let cU = Input.lst[i];
- if (cU.id == id) return cU
- }
- return null
- }
- static getId(e) {
- return e.pointerType == 'mouse' ? e.pointerType + e.button : e.pointerType + e.pointerId
- }
- static getInput(e) {
- let cV = Input.lst;
- let cW = Input.getId(e);
- for (let i = 0; i < cV.length; i++) {
- let o = cV[i];
- if (o.id == cW) return o
- }
- return this.reg(e)
- }
- static checkTap(cX) {
- if (Math.abs(cX.xDrag) > 5) return 'drag x ' + cX.xDrag;
- if (Math.abs(cX.yDrag) > 5) return 'drag y ' + cX.xDrag;
- let cY = cX.timerEnd - cX.timerStart;
- if ((cY) > 500) return `timer ${cY}`;
- return ''
- }
- static init(cZ) {
- console.log('Input init');
- cZ.style.touchAction = 'none';
- cZ.addEventListener('pointerdown', e => {
- e.stopPropagation();
- e.preventDefault();
- let dB = Input.getPos(e.clientX, e.clientY, cZ);
- let dC = Input.getInput(e);
- let dD = dC.isDown;
- Input.evt.down(dC, dB);
- Input.evt.down(Input.global, dB);
- Input._pointerEvent = e;
- Input._lastButton = e.button;
- dD == !1 && (console.log('dispatch mouse down event, id ' + dC.id), cD.Event.dispatchEvent(cD.Evt.MOUSE_DOWN))
- });
- cZ.addEventListener('pointermove', e => {
- e.stopPropagation();
- e.preventDefault();
- cD.Event.dispatchEvent(cD.Evt.MOUSE_MOVE);
- dE(Input.global);
- for (const dF of Input.lst) dE(dF);
- function dE(dG) {
- Input.evt.move(dG, cZ, e);
- Input._pointerEvent = e;
- if (dG.isDown) {
- if (!dG.isDrag) {
- console.log('dispatch mouse drag, id ' + dG.id);
- dG.isDrag = !0;
- dG.xStart = dG.x;
- dG.yStart = dG.y;
- dG != Input.global && cD.Event.dispatchEvent(cD.Evt.MOUSE_START_DRAG)
- }
- dG.xDrag = dG.x - dG.xStart;
- dG.yDrag = dG.y - dG.yStart
- }
- }
- });
- cZ.addEventListener('pointerout', e => dA(e));
- cZ.addEventListener('pointerup', e => {
- this._lastButton = e.button;
- dA(e)
- });
- function dA(e) {
- e.stopPropagation();
- e.preventDefault();
- console.group('pointer up ' + Input.getId(e));
- let dH = Input.getInput(e);
- Input.evt.up(dH);
- Input.evt.up(Input.global);
- Input._pointerEvent = e;
- let dI = Input.checkTap(dH);
- dH.isTap = (dI == '');
- dH.isTap && cD.Event.dispatchEvent(cD.Evt.MOUSE_CLICK);
- for (const dJ of Input.lst) {
- dJ.isDrag && (console.log('dispatch mouse drag end id ' + dH.id), cD.Event.dispatchEvent(cD.Evt.MOUSE_END_DRAG));
- Input.evt.up(dJ)
- }
- cD.Event.dispatchEvent(cD.Evt.MOUSE_UP);
- console.groupEnd()
- }
- }
- static reg(e) {
- console.log('reg input type ' + e.pointerType + '/button ' + e.button + '/id ' + e.pointerId);
- let dK = new cE.InpuObj;
- dK.id = Input.getId(e);
- dK.pointerType = e.pointerType;
- dK.isDown = dK.isDrag = dK.isTap = !1;
- dK.button = e.button;
- dK.timerEnd = dK.timerStart = dK.x = dK.xDrag = dK.xStart = dK.y = dK.yDrag = dK.yStart = 0;
- dK.evt = null;
- dK.pointerId = e.pointerId;
- dK.moveX = dK.moveY = 0;
- Input.lst.push(dK);
- return dK
- }
- }
- Input._debug = !1;
- Input.lst = [];
- Input.global = new cE.InpuObj;
- Input.evt = new cE.EventHandler;
- Input.getPos = (dL, dM, c) => {
- let r = c.getBoundingClientRect();
- let dN = parseInt(window.getComputedStyle(c).width) / c.width;
- let _F = parseInt(window.getComputedStyle(c).height) / c.height;
- let _G = ~~(dL - r.x) / dN;
- let _H = ~~(dM - r.y) / _F;
- return {
- x: _G,
- y: _H
- }
- };
- cD.Input = cD.In = Input
- })(C || (C = {}));
- var C;
- (function(dO) {
- let dP;
- (function(dQ) {
- class KeybObj {
- constructor(dR, dS) {
- this.key = '';
- this.isDown = !1;
- this.key = dR;
- this.isDown = dS
- }
- }
- dQ.KeybObj = KeybObj
- })(dP || (dP = {}));
- class Keyboard {
- static get lastKey() {
- return Keyboard._lastKey
- }
- static get obj() {
- return Keyboard._obj
- }
- static getByKey(dT) {
- for (let i = 0; i < Keyboard.list.length; i++)
- if (Keyboard.list[i].key == dT) return Keyboard.list[i];
- return Keyboard.reg(dT, !1)
- }
- static reg(dU, dV) {
- console.log(`new key registered: ${dU}`);
- let k = new dP.KeybObj(dU, dV);
- Keyboard.list.push(k);
- return k
- }
- static setDown(dW, dX) {
- let dY = Keyboard.list;
- for (let i = 0; i < dY.length; i++) {
- let o = dY[i];
- if (o.key == dW) {
- o.isDown = dX;
- return o
- }
- }
- return Keyboard.reg(dW, dX)
- }
- static IsDown(dZ = '') {
- let eA = Keyboard.list;
- for (let i = 0; i < eA.length; i++) {
- let o = eA[i];
- if (o.key == dZ) return o.isDown
- }
- this.reg(dZ, !1);
- return !1
- }
- static init() {
- window.addEventListener('keydown', e => {
- Keyboard.anyKey.isDown = !0;
- Keyboard._lastKey = e.key;
- Keyboard._obj = e;
- let k = Keyboard.getByKey(e.key);
- k.isDown == !1 && (Keyboard.setDown(e.key, !0), Keyboard.setDown('', !0), dO.Event.dispatchEvent(dO.Evt.KEYB_DOWN))
- });
- window.addEventListener('keyup', e => {
- Keyboard.anyKey.isDown = !1;
- Keyboard._lastKey = e.key;
- Keyboard._obj = e;
- Keyboard.setDown(e.key, !1);
- Keyboard.setDown('', !1);
- dO.Event.dispatchEvent(dO.Evt.KEYB_UP)
- })
- }
- }
- Keyboard.list = [];
- Keyboard.anyKey = new dP.KeybObj('', !1);
- Keyboard._lastKey = '';
- dO.Keyboard = Keyboard
- })(C || (C = {}));
- (function(eB) {
- class Pt {
- constructor(x = 0, y = 0) {
- this.x = x;
- this.y = y
- }
- get x() {
- return this._x
- }
- set x(eC) {
- this._x = eC
- }
- get y() {
- return this._y
- }
- set y(eD) {
- this._y = eD
- }
- static create(x = 0, y = 0) {
- return new Pt(x, y)
- }
- static copy(p1, p2) {
- p2.x = p1.x;
- p2.y = p1.y
- }
- static clone(p) {
- return Pt.create(p.x, p.y)
- }
- static putarPoros(p, eE = 0, eF = 0, eG = 0) {
- eB.Tf.rotateRel(p.x, p.y, eE, eF, eG);
- p.x = eB.Tf.lastX;
- p.y = eB.Tf.lastY
- }
- }
- eB.Pt = Pt
- })(C || (C = {}));
- var C;
- (function(eH) {
- class Seg {
- constructor(A = new eH.Pt, B = new eH.Pt) {
- this.A = A;
- this.B = B
- }
- get A() {
- return this._A
- }
- set A(eI) {
- this._A = eI
- }
- get B() {
- return this._B
- }
- set B(eJ) {
- this._B = eJ
- }
- static create(eK = new eH.Pt, eL = new eH.Pt) {
- return new eH.Sg(eK, eL)
- }
- static boundCollide(eM, eN) {
- if (eH.Sg.maxX(eM) < eH.Sg.minX(eN)) return !1;
- if (eH.Sg.minX(eM) > eH.Sg.maxX(eN)) return !1;
- if (eH.Sg.maxY(eM) < eH.Sg.minY(eN)) return !1;
- if (eH.Sg.minY(eM) > eH.Sg.maxY(eN)) return !1;
- return !0
- }
- static collide(eO, eP) {
- let eQ = eH.Sg.boundCollide(eO, eP);
- if (!eQ) return !1;
- let eR = eH.Sg.clone(eP);
- let eS = eH.Sg.clone(eO);
- let eT = eH.Sg.deg(eP);
- eH.Sg.rotate(eR, -eT, eP.A.x, eP.A.y);
- eH.Sg.rotate(eS, -eT, eP.A.x, eP.A.y);
- if (!eH.Sg.boundCollide(eS, eR)) return !1;
- eH.Sg.translate(eS, -eP.A.x, -eP.A.y);
- eH.Sg.translate(eR, -eP.A.x, -eP.A.y);
- if (!eH.Sg.crossHor(eS)) return !1;
- let x = eH.Sg.getXAtIdx(eS, eH.Sg.xHorIdx(eS));
- if (x > eH.Sg.maxX(eR)) return !1;
- if (x < eH.Sg.minX(eR)) return !1;
- return !0
- }
- static copy(eU, eV) {
- eH.Pt.copy(eU.A, eV.B);
- eH.Pt.copy(eU.B, eV.B)
- }
- static clone(eW) {
- return new Seg(eH.Pt.clone(eW.A), eH.Pt.clone(eW.B))
- }
- static crossHor(eX) {
- if (eH.Sg.maxY(eX) > 0)
- if (eH.Sg.minY(eX) < 0) return !0;
- return !1
- }
- static deg(eY) {
- return eH.Tf.sudut(eY.B.x - eY.A.x, eY.B.y - eY.A.y)
- }
- static getXAtIdx(eZ, fA) {
- return eZ.A.x + (fA * eH.Sg.vecI(eZ))
- }
- static vecI(fB) {
- return fB.B.x - fB.A.x
- }
- static rotate(fC, fD = 0, fE = 0, fF = 0) {
- eH.Pt.putarPoros(fC.A, fE, fF, fD);
- eH.Pt.putarPoros(fC.B, fE, fF, fD)
- }
- static minX(fG) {
- return Math.min(fG.A.x, fG.B.x)
- }
- static maxX(fH) {
- return Math.max(fH.A.x, fH.B.x)
- }
- static minY(fI) {
- return Math.min(fI.A.y, fI.B.y)
- }
- static maxY(fJ) {
- return Math.max(fJ.A.y, fJ.B.y)
- }
- static translate(fK, x = 0, y = 0) {
- fK.A.x += x;
- fK.A.y += y;
- fK.B.x += x;
- fK.B.y += y
- }
- static xHorIdx(fL) {
- if (!Seg.crossHor(fL)) return NaN;
- let fM = 0;
- fM = (0 - fL.A.y) / (fL.B.y - fL.A.y);
- return fM
- }
- }
- eH.Seg = eH.Sg = Seg
- })(C || (C = {}));
- (function(fN) {
- class Ktk {
- constructor() {
- this.vs = this.segs = []
- }
- static buat(fO = 0, fP = 0, fQ = 0, fR = 0) {
- let r = new Ktk;
- r.vs.push(fN.Pt.create(fO, fP));
- r.vs.push(fN.Pt.create(fQ, fP));
- r.vs.push(fN.Pt.create(fQ, fR));
- r.vs.push(fN.Pt.create(fO, fR));
- r.segs.push(fN.Seg.create(r.vs[0], r.vs[1]));
- r.segs.push(fN.Seg.create(r.vs[1], r.vs[2]));
- r.segs.push(fN.Seg.create(r.vs[2], r.vs[3]));
- r.segs.push(fN.Seg.create(r.vs[3], r.vs[0]));
- return r
- }
- static destroy(r) {
- while (r.vs.length > 0) r.vs.pop();
- while (r.segs.length > 0) {
- let s = r.segs.pop();
- s.A = s.B = null
- }
- }
- static copy(r) {
- let fS = Ktk.buat();
- Ktk.copyInfo(r, fS);
- return fS
- }
- static copyInfo(r1, r2) {
- for (let i = 0; i < r1.segs.length; i++) fN.Seg.copy(r1.segs[i], r2.segs[i])
- }
- static collideBound(r1, r2) {
- if (Ktk.maxX(r1) < Ktk.minX(r2)) return !1;
- if (Ktk.minX(r1) > Ktk.maxX(r2)) return !1;
- if (Ktk.maxY(r1) < Ktk.minY(r2)) return !1;
- if (Ktk.minY(r1) > Ktk.maxY(r2)) return !1;
- return !0
- }
- static collide(fT, fU) {
- let fV = Ktk.collideBound(fT, fU);
- if (!fV) return !1;
- for (let i = 0; i < fT.segs.length; i++)
- for (let j = 0; j < fU.segs.length; j++)
- if (fN.Seg.collide(fT.segs[i], fU.segs[j])) return !0;
- return !1
- }
- static collideDotBound(r, d) {
- if (d.x < Ktk.minX(r)) return !1;
- if (d.x > Ktk.maxX(r)) return !1;
- if (d.y < Ktk.minY(r)) return !1;
- if (d.y > Ktk.maxY(r)) return !1;
- return !0
- }
- static collideDot(r, x, y) {
- let fW = Ktk.copy(r);
- let p = fN.Pt.create(x, y);
- let d = fN.Seg.deg(fW.segs[0]);
- let fX = fW.vs[0];
- if (!Ktk.collideDotBound(r, p)) return !1;
- Ktk.rotate(fW, -d, fX.x, fX.y, !1);
- fN.Pt.putarPoros(p, fX.x, fX.y, -d);
- if (!Ktk.collideDotBound(fW, p)) return !1;
- return !0
- }
- static minX(r) {
- let x = r.vs[0].x;
- for (const item of r.vs) item.x < x && (x = item.x);
- return x
- }
- static maxX(r) {
- let x = r.vs[0].x;
- for (const item of r.vs) item.x > x && (x = item.x);
- return x
- }
- static minY(r) {
- let y = r.vs[0].y;
- for (const item of r.vs) item.y < y && (y = item.y);
- return y
- }
- static maxY(r) {
- let y = r.vs[0].y;
- for (const item of r.vs) item.y > y && (y = item.y);
- return y
- }
- static translate(fY, x, y) {
- for (const v of fY.vs) {
- v.x += x;
- v.y += y
- }
- }
- static rotate(r, fZ, gA = 0, gB, gC = !0) {
- let gD;
- gC ? gD = Ktk.copy(r) : gD = r;
- for (const p of gD.vs) fN.Pt.putarPoros(p, gA, gB, fZ);
- return gD
- }
- }
- fN.Ktk = Ktk
- })(C || (C = {}));
- var C;
- (function(gE) {
- class Transform {
- static get lastX() {
- return gE.Tf._lastX
- }
- static get lastY() {
- return gE.Tf._lastY
- }
- static quadDeg2(x, y, gF) {
- if (x == 0) {
- if (y == 0) return gF;
- if (y > 0) return gF;
- else if (y < 0) return 360 - Math.abs(gF)
- } else if (x > 0) {
- if (y == 0) return gF;
- if (y > 0) return gF;
- else if (y < 0) return 360 - Math.abs(gF)
- } else if (x < 0) {
- if (y == 0) return 180;
- if (y > 0) return 180 - Math.abs(gF);
- else if (y < 0) return 180 + Math.abs(gF)
- }
- throw Error()
- }
- static sudut(x, y) {
- let l;
- let gG;
- l = Math.sqrt(x * x + y * y);
- l == 0 && (l = .00001);
- gG = y / l;
- gG = Math.asin(gG);
- gG *= gE.Tf.RAD2DEG;
- gG = gE.Tf.quadDeg2(x, y, gG);
- gG = gE.Tf.normalizeDeg(gG);
- return gG
- }
- static normalizeDeg(gH) {
- while (gH >= 360) gH -= 360;
- while (gH <= -360) gH += 360;
- gH < 0 && (gH = 360 + gH);
- return gH
- }
- static degDist(gI = 0, gJ, gK = !0) {
- if (gK) return Transform.degDistMin(gI, gJ);
- return Transform.degDistMax(gI, gJ)
- }
- static degDistMax(gL = 0, gM) {
- gL = gE.Tf.normalizeDeg(gL);
- gM = gE.Tf.normalizeDeg(gM);
- let gN = gE.Tf.degDistMin(gL, gM);
- if (gN >= 0) return -(360 - gN);
- return (360 - Math.abs(gN))
- }
- static degDistMin(gO = 0, gP) {
- gO = gE.Tf.normalizeDeg(gO);
- gP = gE.Tf.normalizeDeg(gP);
- if (gP >= gO) {
- if (gP - gO > 180) return -(gO + 360 - gP);
- return gP - gO
- } else {
- if (gO - gP >= 180) return 360 + gP - gO;
- return gP - gO
- }
- }
- static rotateRel(x = 0, y = 0, gQ = 0, gR = 0, gS = 10) {
- let gT = x - gQ;
- let gU = y - gR;
- let gV;
- let _i;
- gS *= gE.Tf.DEG2RAD;
- gV = gT * Math.cos(gS) - gU * Math.sin(gS);
- _i = gT * Math.sin(gS) + gU * Math.cos(gS);
- gE.Tf._lastX = gV + gQ;
- gE.Tf._lastY = _i + gR
- }
- }
- Transform.RAD2DEG = 180.0 / Math.PI;
- Transform.DEG2RAD = Math.PI / 180.0;
- Transform._lastX = Transform._lastY = 0;
- gE.Transform = gE.Tf = Transform
- })(C || (C = {}));
- (function(gW) {
- class ImgImpl {
- static CreateImage(gX, gY) {
- let h = new gW.Image;
- h.canvas = document.createElement('canvas');
- h.canvas.width = gX;
- h.canvas.height = h.frameH = gY;
- h.frameW = h.width = gX;
- h.height = gY;
- h.load = !0;
- h.img = document.createElement('img');
- gW.Ip.register(h, h.url, h.dragType);
- return h
- }
- static MuatAnimasi(gZ, hA, hB, hC = 0) {
- let hD = document.createElement('canvas');
- let hE = new gW.Image(gZ);
- hE.isAnim = !0;
- hE.frameW = hA;
- hE.frameH = hB;
- hE.width = hA;
- hE.height = hB;
- return hE
- }
- static register(hF, hG, hH) {
- let hI;
- hI = hF;
- hI.dragType = hH;
- hI.url = hG;
- gW.Ip.daftar.push(hI);
- return hI
- }
- static free(hJ) {
- for (let i = 0; i < this.daftar.length; i++)
- if (this.daftar[i] == hJ) {
- hJ.canvas = hJ.img = null;
- gW.Ktk.destroy(hJ.rect);
- this.daftar.splice(i, 1);
- return
- }
- }
- static Muat(hK) {
- return new gW.Image(hK)
- }
- static tabrakan(hL, hM, hN, hO, hP, hQ) {
- gW.Ip.resetRect(hL);
- gW.Ip.rectToImageTf(hL, hM, hN);
- gW.Ip.resetRect(hO);
- gW.Ip.rectToImageTf(hO, hP, hQ);
- return gW.Ktk.collide(hL.rect, hO.rect)
- }
- static dotInsideImage(hR, hS, hT, hU, hV) {
- gW.Ip.resetRect(hR);
- gW.Ip.rectToImageTf(hR, hS, hT);
- return gW.Ktk.collideDot(hR.rect, hU, hV)
- }
- static gambarUbin(hW, x = 0, y = 0, hX = 0) {
- let hY = 0;
- let hZ = 0;
- if (hW.load == !1) return;
- let iA = ~~hW.width;
- let iB = ~~hW.height;
- while (x < 0) x += iA;
- while (x > 0) x -= iA;
- while (y < 0) y += iB;
- while (y > 0) y -= iB;
- x -= iA;
- y -= iB;
- hX = ~~hX;
- hY = Math.ceil((gW.G.Canvas().width + Math.abs(x)) / iA);
- hZ = Math.ceil((gW.G.Canvas().height + Math.abs(y)) / iB);
- for (let i = 0; i < hY; i++)
- for (let j = 0; j < hZ; j++) gW.Ip.DrawSingle(hW, x + (i * iA), y + (j * iB), hX)
- }
- static AmbilPiksel(x = 0, y = 0) {
- try {
- let iC = gW.G.Canvas().getContext('2d').getImageData(x, y, 1, 1).data;
- let iD = [];
- iD.push(iC[0]);
- iD.push(iC[1]);
- iD.push(iC[2]);
- iD.push(iC[3]);
- gW.G.red = iC[0];
- gW.G.green = iC[1];
- gW.G.blue = iC[2];
- gW.G.alpha = iC[3]
- } catch (e) {}
- }
- static SetPiksel(x = 0, y = 0) {
- gW.G.Canvas().getContext('2d').fillRect(~~x, ~~y, 1, 1)
- }
- static Draw(iE) {
- iE.tilable ? gW.Ip.gambarUbin(iE, iE.x, iE.y, iE.frame) : gW.Ip.DrawSingle(iE, iE.x, iE.y, iE.frame)
- }
- static DrawSingle(iF, x = 0, y = 0, iG = 0) {
- let iH = gW.G.Canvas().getContext('2d');
- let iI = 0;
- let iJ = 0;
- let iK = 0;
- let _I = 0;
- if (iF.load == !1) return;
- !iF.url ? _I = iF.width : _I = iF.img.naturalWidth;
- iF.ctrIdx = gW.Image.ctrDraw++;
- iG = ~~iG;
- iI = ~~_I / iF.frameW;
- iJ = (iG % iI);
- iK = ~~iG / iI;
- iJ *= iF.frameW;
- iK *= iF.frameH;
- iJ = ~~iJ;
- iK = ~~iK;
- let _j = ~~x;
- let _k = ~~y;
- let _l = ~~iF.width;
- let M = ~~iF.height;
- _j -= iF.handleX;
- _k -= iF.handleY;
- iF.rotation != 0 ? (iH.save(), iH.translate(x, y), iH.rotate(iF.rotation * (Math.PI / 180)), _n(-iF.handleX, -iF.handleY), iH.restore()) : (iH.save(), _n(_j, _k), iH.restore());
- function _n(iL, iM) {
- iL -= gW.Camera.x;
- iM -= gW.Camera.y;
- iH.globalAlpha = iF.alpha / 100;
- iH.drawImage(iF.canvas, iJ, iK, iF.frameW, iF.frameH, ~~iL, ~~iM, _l, M)
- }
- }
- static resetRect(iN) {
- let iO = iN.rect;
- let p;
- p = iO.vs[0];
- p.x = p.y = 0;
- p = iO.vs[1];
- p.x = iN.frameW - 1;
- p.y = 0;
- p = iO.vs[2];
- p.x = iN.frameW - 1;
- p.y = iN.frameH - 1;
- p = iO.vs[3];
- p.x = 0;
- p.y = iN.frameH - 1
- }
- static rectToImageTf(iP, x, y) {
- let iQ = iP.rect;
- let p;
- let iR = iP.width - 1;
- let iS = iP.height - 1;
- p = iQ.vs[1];
- p.x = iR;
- p.y = 0;
- p = iQ.vs[2];
- p.x = iR;
- p.y = iS;
- p = iQ.vs[3];
- p.x = 0;
- p.y = iS;
- gW.Ktk.translate(iQ, x, y);
- gW.Ktk.translate(iQ, -iP.handleX, -iP.handleY);
- gW.Ktk.rotate(iQ, iP.rotation, x, y, !1)
- }
- static AllImageLoaded() {
- for (let i = 0; i < gW.Ip.daftar.length; i++) {
- let iT = gW.Ip.daftar[i];
- if (!iT.load) return !1
- }
- return !0
- }
- }
- ImgImpl.props = ImgImpl.daftar = [];
- gW.ImgImpl = gW.Ip = ImgImpl
- })(C || (C = {}));
- var C;
- (function(iU) {
- let iV;
- (function(iW) {
- iW[iW['drag'] = 1] = 'drag';
- iW[iW['rotasi'] = 2] = 'rotasi';
- iW[iW['remoteDrag'] = 3] = 'remoteDrag';
- iW[iW['remoteRotation'] = 4] = 'remoteRotation'
- })(iV || (iV = {}));
- class ImgIntHandler {
- init() {
- iU.Event.addEventListener(iU.Evt.MOUSE_DOWN, () => this.inputDown({
- x: iU.Input.global.x,
- y: iU.Input.global.y
- }, iU.Input.global.id));
- iU.Event.addEventListener(iU.Evt.MOUSE_MOVE, () => this.inputMove({
- x: iU.Input.global.x,
- y: iU.Input.global.y
- }, iU.Input.global.id));
- iU.Event.addEventListener(iU.Evt.MOUSE_UP, () => {
- console.log('clear image mouse status');
- for (const iX of iU.Ip.daftar) {
- iX.down = iX.dragged = !1
- }
- })
- }
- down(iY, iZ, jA) {
- let jB = {
- x: iZ.x - iU.Camera.x,
- y: iZ.y - iU.Camera.y
- };
- iY.down = !0;
- iY.dragStartX = jB.x - iY.x;
- iY.dragStartY = jB.y - iY.y;
- iY.inputId = jA;
- iY.initialMouseAngle = iU.Tf.sudut(jB.x - iY.x, jB.y - iY.y);
- iY.initialAngle = iY.rotation
- }
- inputDown(jC, jD) {
- console.group('input down');
- let jE = {
- x: jC.x - iU.Camera.x,
- y: jC.y - iU.Camera.y
- };
- let jF = -1;
- let jG = null;
- for (let i = iU.Ip.daftar.length - 1; i >= 0; i--) {
- let jH;
- jH = iU.Ip.daftar[i];
- if (iU.Ip.dotInsideImage(jH, jH.x, jH.y, jE.x, jE.y)) jH.ctrIdx > jF && (jF = jH.ctrIdx, jG = jH);
- else(jH.dragType == 3 || jH.dragType == 4) && this.down(jH, jC, jD)
- }
- jG ? (console.log(`img pressed, id: ${jD}`), this.down(jG, jC, jD)) : (console.log('no image pressed'));
- console.groupEnd()
- }
- inputMove(jI, jJ) {
- let jK = {
- x: jI.x - iU.Camera.x,
- y: jI.y - iU.Camera.y
- };
- for (const jL of iU.Ip.daftar)
- if (jL.down && (jL.dragType != 0) && (jL.inputId == jJ)) {
- jL.dragged = !0;
- if (jL.dragType == iV.drag || (jL.dragType == iV.remoteDrag)) {
- jL.x = jK.x - jL.dragStartX;
- jL.y = jK.y - jL.dragStartY;
- console.debug('item drag move')
- } else if (jL.dragType == iV.rotasi || (jL.dragType == iV.remoteRotation)) {
- let jM = iU.Tf.sudut(jK.x - jL.x, jK.y - jL.y);
- let jN = jM - jL.initialMouseAngle;
- jL.rotation = jL.initialAngle + jN
- }
- }
- }
- }
- iU.sprInt = new ImgIntHandler
- })(C || (C = {}));
- (function(jO) {
- class Teks {
- static get size() {
- return Teks._size
- }
- static set size(jP) {
- Teks._size = jP
- }
- static Goto(x, y) {
- Teks._x = x;
- Teks._y = y
- }
- static Name(jQ = 'cursive') {
- Teks._name = jQ
- }
- static Size(n = 12) {
- Teks.size = n
- }
- static Align(s = 'left') {
- jO.G.Canvas().getContext('2d').textAlign = s
- }
- static WriteLn(jR) {
- jO.G.Canvas().getContext('2d').font = Teks.size + 'px ' + Teks._name;
- jO.G.Canvas().getContext('2d').fillText(jR, Teks._x, Teks._y);
- jO.G.Canvas().getContext('2d').strokeText(jR, Teks._x, Teks._y);
- Teks._y += Teks.size + 2
- }
- static Write(jS) {
- jO.G.Canvas().getContext('2d').font = Teks.size + 'px ' + Teks._name;
- jO.G.Canvas().getContext('2d').fillText(jS, Teks._x, Teks._y);
- jO.G.Canvas().getContext('2d').strokeText(jS, Teks._x, Teks._y)
- }
- }
- Teks._name = 'Arial';
- Teks._size = 12;
- Teks._x = 120;
- Teks._y = 10;
- jO.Teks = jO.Tk = Teks
- })(C || (C = {}));
- var C;
- (function(jT) {
- class Sound {
- constructor() {
- this._src = '';
- this._loaded = !1
- }
- static get lastSound() {
- return Sound._lastSound
- }
- static set lastSound(jU) {
- Sound._lastSound = jU
- }
- get playedCount() {
- return this._playedCount
- }
- set playedCount(jV) {
- this._playedCount = jV
- }
- get sound() {
- return this._sound
- }
- set sound(jW) {
- this._sound = jW
- }
- get loaded() {
- return this._loaded
- }
- set loaded(jX) {
- this._loaded = jX
- }
- get src() {
- return this._src
- }
- set src(jY) {
- this._src = jY
- }
- }
- Sound.list = [];
- jT.Sound = jT.Sn = Sound
- })(C || (C = {}));
- function D(jZ) {
- let kA = document.createElement('audio');
- kA.onload = () => {
- C.Sound.lastSound = kA;
- C.Event.dispatchEvent(C.Evt.SOUND_LOADED);
- console.log('sound loaded')
- };
- kA.onended = () => {
- try {
- C.Sound.lastSound = kA;
- C.Event.dispatchEvent(C.Evt.SOUND_ENDED);
- console.log('sound ended')
- } catch (e) {}
- };
- kA.src = jZ;
- return kA
- }
- function E(s) {
- s.play()
- }
- function F() {
- return C.Sound.lastSound
- }
- var G = C.G;
- function J(c) {
- G.SetCanvas(c)
- }
- function K() {
- return G.Canvas()
- }
- function L(x, y, w, h) {
- G.Canvas().getContext('2d').clearRect(x, y, w, h)
- }
- function m(w = 320, h = 240, kB = null, kC = 1) {
- G.Graphics(w, h, kB, kC)
- }
- function N(x = 0, y = 0, w = 0, h = 0) {
- G.Cls(x, y, w, h)
- }
- function O() {
- return G.green
- }
- function P() {
- return G.red
- }
- function q() {
- return G.blue
- }
- function R() {
- return ~~G.alpha * 100
- }
- function _s(x = 0, y = 0) {
- H.AmbilPiksel(x, y)
- }
- function t(x = 0, y = 0) {
- H.SetPiksel(x, y)
- }
- function u(r = 0, g = 0, b = 0, a = 100) {
- G.Canvas().getContext('2d').fillStyle = `rgba( ${r}, ${g}, ${b}, ${a})`;
- G.red = r;
- G.green = g;
- G.blue = b;
- G.alpha = a
- }
- function V(r = 0, g = 0, b = 0, a = 1) {
- G.Canvas().getContext('2d').strokeStyle = `rgba( ${r}, ${g}, ${b}, ${a})`;
- G.red = r;
- G.green = g;
- G.blue = b;
- G.alpha = a
- }
- function W(kD, kE, kF, kG) {
- let kH = K().getContext('2d');
- kD = ~~kD;
- kE = ~~kE;
- kF = ~~kF;
- kG = ~~kG;
- kH.beginPath();
- kH.moveTo(kD, kE);
- kH.lineTo(kF, kG);
- kH.stroke()
- }
- function X(kI, kJ, kK, kL) {
- let kM = K().getContext('2d');
- kM.fillRect(kI, kJ, kK - kI, kL - kJ);
- kM.strokeRect(kI, kJ, kK - kI, kL - kJ)
- }
- function Y(x = 0, y = 0, kN) {
- let kO = K().getContext('2d');
- kO.save();
- kO.translate(x, y);
- kO.beginPath();
- kO.arc(0, 0, kN, 0, 2 * Math.PI, !1);
- kO.restore();
- kO.stroke()
- }
- window.addEventListener('load', () => {
- let w = window;
- w['Start'] && (typeof w['Start'] == 'function') ? w['Start']() : console.log('Start not found')
- });
- function z(kP = 0) {
- return I.getByButton(kP)?.isDown
- }
- function aA(kQ = 0) {
- return I.getByButton(kQ)?.isDrag
- }
- function aB(kR = 0) {
- return I.getByDraggedStatus(kR)?.xDrag
- }
- function aC(kS = 0) {
- return I.getByDraggedStatus(kS)?.yDrag
- }
- function aD() {
- return I.global?.x
- }
- function aE() {
- return I.global?.y
- }
- function aF(kT = 0) {
- return I.getByButton(kT)?.xStart
- }
- function aG(kU = 0) {
- return I.getByButton(kU)?.yStart
- }
- function aH() {
- return I.lastButton
- }
- function aI() {
- return I.global.moveX
- }
- function aJ() {
- return I.global.moveY
- }
- function aK(kV = 0, kW, kX = !0) {
- return C.Transform.degDist(kV, kW, kX)
- }
- function aL(x, y) {
- return C.Tf.sudut(x, y)
- }
- function aM(n, kY, kZ) {
- if (n < kY) return kY;
- if (n > kZ) return kZ;
- return n
- }
- function aN(lA) {
- return H.Muat(lA)
- }
- function aO(lB) {
- H.Draw(lB)
- }
- function aP(lC, lD) {
- return H.tabrakan(lC, lC.x, lC.y, lD, lD.x, lD.y)
- }
- function aQ(lE, x, y) {
- return H.dotInsideImage(lE, lE.x, lE.y, x, y)
- }
- function aR(lF, lG) {
- return H.CreateImage(lF, lG)
- }
- function aS() {
- return H.AllImageLoaded()
- }
- function aT(lH) {
- H.free(lH)
- }
- function aU(lI, x, y) {
- let lJ = lI.canvas.getContext('2d');
- lJ.clearRect(0, 0, lI.canvas.width, lI.canvas.height);
- lJ.drawImage(K(), -x, -y)
- }
- var aV = C.Teks.Goto;
- function bB(lK = '') {
- return C.Keyboard.IsDown(lK)
- }
- function bC() {
- return C.Keyboard.lastKey
- }
- var C;
- (function(lL) {
- class Image {
- constructor(lM = '') {
- this._x = this._y = 0;
- this._alpha = 100;
- this._handleX = this._handleY = this._panjang = this._lebar = this._rotasi = 0;
- this._tilable = !1;
- this._frameW = this._frameH = 0;
- this._dragged = this._down = !1;
- this._frame = 0;
- this.load = !1;
- this._ctrIdx = 0;
- this.isAnim = !1;
- this.rect = new lL.Ktk;
- this._tipeDrag = this._dragStartY = this._dragStartX = this._sudutTekanAwal = this._sudutAwal = 0;
- let lN = document.createElement('img');
- let lO = document.createElement('canvas');
- let lP = lO.getContext('2d');
- let lQ;
- lQ = this;
- lL.Ip.register(this, lM, 0);
- lQ.img = lN;
- lQ.canvas = lO;
- lQ.rect = lL.Ktk.buat(0, 0, lN.naturalWidth, lN.naturalHeight);
- lQ.load = !1;
- !lQ.url && (lQ.load = !0);
- lN.onload = () => lS(lN);
- lN.onerror = () => {
- console.warn(`gagal load image, url ${lM}`);
- lT()
- };
- let lR = _.be.cache.getGbr(lM);
- if (lR) lS(lR);
- else lM && (lN.src = lM);
- function lS(lU) {
- lO.width = lU.naturalWidth;
- lO.height = lU.naturalHeight;
- lP.drawImage(lU, 0, 0);
- lQ.rect = lL.Ktk.buat(0, 0, lU.naturalWidth, lU.naturalHeight);
- lQ.load = !0;
- lQ.img = lU;
- !lQ.width && (lQ.width = lU.naturalWidth);
- !lQ.height && (lQ.height = lU.naturalHeight);
- !lQ._frameH && (lQ.frameH = lU.naturalHeight);
- !lQ._frameW && (lQ.frameW = lU.naturalWidth);
- _.be.cache.setFile(lM, lU)
- }
- function lT() {}
- }
- get inputId() {
- return this._inputId
- }
- set inputId(lV) {
- this._inputId = lV
- }
- get frame() {
- return this._frame
- }
- set frame(lW) {
- this._frame = lW
- }
- get canvas() {
- return this._canvas
- }
- set canvas(lX) {
- this._canvas = lX
- }
- get tilable() {
- return this._tilable
- }
- set tilable(lY) {
- this._tilable = lY
- }
- get frameW() {
- return this._frameW
- }
- set frameW(lZ) {
- this._frameW = lZ
- }
- get frameH() {
- return this._frameH
- }
- set frameH(mA) {
- this._frameH = mA
- }
- get x() {
- return this._x
- }
- set x(mB) {
- this._x = mB
- }
- get y() {
- return this._y
- }
- set y(mC) {
- this._y = mC
- }
- get alpha() {
- return this._alpha
- }
- set alpha(mD) {
- this._alpha = mD
- }
- get handleY() {
- return this._handleY
- }
- set handleY(mE) {
- this._handleY = mE
- }
- get handleX() {
- return this._handleX
- }
- set handleX(mF) {
- this._handleX = mF
- }
- get width() {
- if (this._panjang) return this._panjang;
- if (this.img) return this.img.naturalWidth;
- return 0
- }
- set width(mG) {
- this._panjang = mG
- }
- get height() {
- if (this._lebar) return this._lebar;
- if (this.img) return this.img.naturalHeight;
- return 0
- }
- set height(mH) {
- this._lebar = mH
- }
- get ctrIdx() {
- return this._ctrIdx
- }
- set ctrIdx(mI) {
- this._ctrIdx = mI
- }
- get rotation() {
- return this._rotasi
- }
- set rotation(mJ) {
- this._rotasi = mJ
- }
- get dragStartX() {
- return this._dragStartX
- }
- set dragStartX(mK) {
- this._dragStartX = mK
- }
- get dragStartY() {
- return this._dragStartY
- }
- set dragStartY(mL) {
- this._dragStartY = mL
- }
- get dragged() {
- return this._dragged
- }
- set dragged(mM) {
- this._dragged = mM
- }
- get down() {
- return this._down
- }
- set down(mN) {
- this._down = mN
- }
- get dragType() {
- return this._tipeDrag
- }
- set dragType(mO) {
- this._tipeDrag = mO
- }
- get url() {
- return this._url
- }
- set url(mP) {
- this._url = mP
- }
- static get ctrDraw() {
- return Image._ctrDraw
- }
- static set ctrDraw(mQ) {
- Image._ctrDraw = mQ
- }
- get initialMouseAngle() {
- return this._sudutTekanAwal
- }
- set initialMouseAngle(mR) {
- this._sudutTekanAwal = mR
- }
- get initialAngle() {
- return this._sudutAwal
- }
- set initialAngle(mS) {
- this._sudutAwal = mS
- }
- }
- Image._ctrDraw = 0;
- lL.Image = Image
- })(C || (C = {}));
Add Comment
Please, Sign In to add comment