var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.BreadToggle = function() { EHDI.aka.Container.call(this); this.basketCloth = new EHDI.aka.Sprite(EHDI.Assets.images["bread-cloth"]); this.basketCloth.anchor.set(0.5, 0); this.addChild(this.basketCloth); this.glow = new EHDI.aka.Sprite(EHDI.Assets.images["glow"]); this.glow.anchor.set(0.5, 0.5); this.glow.scale.set(0, 0); this.addChild(this.glow); this.basketContainer = new EHDI.aka.Container(); this.addChild(this.basketContainer); this.basketContainer.y = - EHDI.GAME.sceneManager.getStageHeight() * 0.03; this.design = new EHDI.aka.Sprite(EHDI.Assets.images["bread-stuff"]); this.design.anchor.set(0.5, 0.5); this.design.position.y = EHDI.GAME.sceneManager.getStageHeight() * 0.13; this.design.position.x = -EHDI.GAME.sceneManager.getStageWidth() * 0.025; this.addChild(this.design); this.basketBack = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_basketback"]); this.basketBack.anchor.x = 0.5; this.basketBack.anchor.y = 0.5; this.basketContainer.addChild(this.basketBack); this.bread = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_basketbread"]); this.bread.anchor.x = 0.5; this.bread.anchor.y = 0.5; this.basketContainer.addChild(this.bread); this.basketFront = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_basketfront"]); this.basketFront.anchor.x = 0.5; this.basketFront.anchor.y = 0.15; this.basketContainer.addChild(this.basketFront); this.interactive = true; }; EHDI.components.BreadToggle.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.BreadToggle.prototype.mousedown = function(mousedata) { this.isPressed = true; if(this.animateTimeline) this.animateTimeline.kill(); this.animateTimeline = new TimelineMax(); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1.1, y: 1.1}); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1.1, y : 1.1}, 0); this.animateTimeline.to(this.glow.scale, 0.15, {x : 1.1, y : 1.1, ease : Power0.easeNone}, 0); this.animateTimeline.to(this.bread, 0.125, {y : -this.bread.width * 0.1}, 0); }; EHDI.components.BreadToggle.prototype.touchstart = function(touchdata) { this.isPressed = true; if(this.animateTimeline) this.animateTimeline.kill(); this.animateTimeline = new TimelineMax(); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1.1, y: 1.1}); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1.1, y : 1.1}, 0); this.animateTimeline.to(this.glow.scale, 0.15, {x : 1.1, y : 1.1, ease : Power0.easeNone}, 0); this.animateTimeline.to(this.bread, 0.125, {y : -this.bread.width * 0.1}, 0); }; EHDI.components.BreadToggle.prototype.touchend = function(touchdata) { if(!this.isPressed) return; this.isPressed = false; this.animateTimeline.to(this.bread, 0.25, {y : 0}, 0.125); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1, y: 1}, 0.125); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1, y : 1}, 0.125); this.animateTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0, ease : Power0.easeNone}, 0.15); EHDI.GAME.customerSpawner.current.breadToggle(); }; EHDI.components.BreadToggle.prototype.mouseup = function(touchdata) { if(!this.isPressed) return; this.isPressed = false; this.animateTimeline.to(this.bread, 0.25, {y : 0}, 0.125); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1, y: 1}, 0.125); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1, y : 1}, 0.125); this.animateTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0, ease : Power0.easeNone}, 0.15); EHDI.GAME.customerSpawner.current.breadToggle(); }; EHDI.components.BreadToggle.prototype.touchendoutside = function(touchdata) { if(!this.isPressed) return; this.isPressed = false; this.animateTimeline.to(this.bread, 0.25, {y : 0}, 0.125); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1, y: 1}, 0.125); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1, y : 1}, 0.125); this.animateTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0, ease : Power0.easeNone}, 0.15); } EHDI.components.BreadToggle.prototype.mouseupoutside = function(touchdata) { if(!this.isPressed) return; this.isPressed = false; this.animateTimeline.to(this.bread, 0.25, {y : 0}, 0.125); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1, y: 1}, 0.125); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1, y : 1}, 0.125); this.animateTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0, ease : Power0.easeNone}, 0.15); } EHDI.components.BreadToggle.prototype.animateBread = function() { if(this.animateTimeline) this.animateTimeline.kill(); this.animateTimeline = new TimelineMax(); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1.1, y: 1.1}); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1.1, y : 1.1}, 0); this.animateTimeline.to(this.glow.scale, 0.15, {x : 1.1, y : 1.1, ease : Power0.easeNone}, 0); this.animateTimeline.to(this.bread, 0.125, {y : -this.bread.width * 0.1}, 0); this.animateTimeline.to(this.bread, 0.25, {y : 0}, 0.125); this.animateTimeline.to(this.basketFront.scale, 0.125, {x : 1, y: 1}, 0.125); this.animateTimeline.to(this.basketBack.scale, 0.125, {x : 1, y : 1}, 0.125); this.animateTimeline.to(this.glow.scale, 0.15, {x : 0, y : 0, ease : Power0.easeNone}, 0.15); }; EHDI.components.BreadToggle.prototype.toggleBread = function() { if(EHDI.GAME.customerSpawner.current && EHDI.GAME.customerSpawner.interaction && !EHDI.GAME.pauseButton.isPaused) { this.animateBread(); EHDI.GAME.customerSpawner.current.breadToggle(); } }