diff --git a/package.json b/package.json index 380594b..ff7819b 100755 --- a/package.json +++ b/package.json @@ -20,6 +20,6 @@ "yaml": "1.3.0", "orm": "2.1.0", "haxe-crypto": "0.0.7", - "svg": "1.1.2" + "svg": "1.1.3" } } diff --git a/src/client/haxe/ru/m/animate/Animate.hx b/src/client/haxe/ru/m/animate/Animate.hx index 2c27205..428252f 100644 --- a/src/client/haxe/ru/m/animate/Animate.hx +++ b/src/client/haxe/ru/m/animate/Animate.hx @@ -1,47 +1,62 @@ package ru.m.animate; -import flash.display.PixelSnapping; -import haxe.Timer; import flash.display.Bitmap; import flash.display.BitmapData; - +import flash.display.PixelSnapping; +import haxe.Timer; typedef Frame = { var image:BitmapData; var length:Int; } -class Animate extends Bitmap { +class AnimateManager { + public var playing(default, default):Bool; - private static var timer:Timer; - private static var instances:Array = []; + private var timer:Timer; + private var animations:Array; - private static function init():Void { - if (timer == null) { - timer = new Timer(30); - timer.run = updateAll; - } + public function new() { + animations = []; + timer = new Timer(30); + timer.run = update; } - private static function updateAll():Void { - for (instance in instances) { - if (instance.playing) { - instance.update(); + public function update():Void { + if (playing) { + for (animation in animations) { + if (animation.playing) { + animation.update(); + } } } } - public var playing(default, set):Bool; + public function add(animate:Animate):Void { + animations.push(animate); + } + + public function remove(animate:Animate):Void { + if (animations.indexOf(animate) > -1) { + animations.remove(animate); + } + } +} + +class Animate extends Bitmap { + + public var playing(default, default):Bool; public var frames(default, set):Array; private var sequence:Array; private var index:Int; + @:provide private static var manager:AnimateManager; + public function new(?frames:Array) { super(null, PixelSnapping.AUTO, true); this.frames = frames == null ? [] : frames; - init(); - instances.push(this); + manager.add(this); } public function set_frames(value:Array):Array { @@ -59,14 +74,7 @@ class Animate extends Bitmap { return frames; } - public function set_playing(value:Bool):Bool { - if (playing != value) { - playing = value; - } - return playing; - } - - private function update():Void { + public function update():Void { if (++index >= sequence.length) { index = 0; } @@ -77,8 +85,6 @@ class Animate extends Bitmap { } public function dispose():Void { - if (instances.indexOf(this) > -1) { - instances.remove(this); - } + manager.remove(this); } } diff --git a/src/client/haxe/ru/m/animate/OnceAnimate.hx b/src/client/haxe/ru/m/animate/OnceAnimate.hx index 088ebff..3e510cf 100644 --- a/src/client/haxe/ru/m/animate/OnceAnimate.hx +++ b/src/client/haxe/ru/m/animate/OnceAnimate.hx @@ -3,7 +3,6 @@ package ru.m.animate; import promhx.Deferred; import promhx.Promise; - class OnceAnimate extends Animate { private var deferred:Deferred; @@ -14,13 +13,14 @@ class OnceAnimate extends Animate { return deferred.promise(); } - override private function update():Void { + override public function update():Void { super.update(); if (index == 0) { playing = false; if (deferred != null) { deferred.resolve(this); } + dispose(); } } } diff --git a/src/client/haxe/ru/m/tankz/Init.hx b/src/client/haxe/ru/m/tankz/Init.hx index 79df69a..e47dc44 100644 --- a/src/client/haxe/ru/m/tankz/Init.hx +++ b/src/client/haxe/ru/m/tankz/Init.hx @@ -1,5 +1,6 @@ package ru.m.tankz; +import ru.m.animate.Animate.AnimateManager; import flash.Lib; import haxework.animate.FadeAnimate; import haxework.animate.UnFadeAnimate; @@ -49,6 +50,7 @@ class Init { @:provide static var bus:IControlBus; @:provide static var loaderManager:ILoaderManager; @:provide static var updater:Updater; + @:provide static var animateManager:AnimateManager; private static function buildConnection():IConnection { var host:String = CompilationOption.get("host"); @@ -75,6 +77,7 @@ class Init { recordStorage = new RecordStorage(); soundManager = new SoundManager(); popupManager = new PopupManager(); + animateManager = new AnimateManager(); popupManager.showAnimateFactory = function(v) return new UnFadeAnimate(v, 100); popupManager.closeAnimateFactory = function(v) return new FadeAnimate(v, 100); diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 48ea9c9..7ee9cdf 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -40,6 +40,8 @@ class Render extends SpriteView implements IRender { private var items:Map; private var paused:Bool; + @:provide private static var animateManager:AnimateManager; + public function new() { super(); items = new Map(); @@ -119,12 +121,14 @@ class Render extends SpriteView implements IRender { public function onGameEvent(event:GameEvent):Void { switch event { case START(start): + animateManager.playing = true; gridSize = start.level.size; content.addEventListener(Event.ENTER_FRAME, onEnterFrame); case COMPLETE(_): content.removeEventListener(Event.ENTER_FRAME, onEnterFrame); case PAUSE(paused): - this.paused = paused; + this.paused = paused; + animateManager.playing = !paused; case SPAWN(BRICK(bricks)): drawBackground(); for (brick in bricks) {