[client] use class provide macro

This commit is contained in:
2019-11-18 18:01:26 +03:00
parent 8c16b5ba90
commit d9d385b0ef
6 changed files with 37 additions and 54 deletions

View File

@@ -3,46 +3,12 @@ package ru.m.animate;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.PixelSnapping;
import haxe.Timer;
typedef Frame = {
var image:BitmapData;
var length:Int;
}
class AnimateManager {
public var playing(default, default):Bool;
private var timer:Timer;
private var animations:Array<Animate>;
public function new() {
animations = [];
timer = new Timer(30);
timer.run = update;
}
public function update():Void {
if (playing) {
for (animation in animations) {
if (animation.playing) {
animation.update();
}
}
}
}
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;

View File

@@ -0,0 +1,34 @@
package ru.m.animate;
@:provide class AnimateManager {
public var playing(default, default):Bool;
private var timer:Timer;
private var animations:Array<Animate>;
public function new() {
animations = [];
timer = new Timer(30);
timer.run = update;
}
public function update():Void {
if (playing) {
for (animation in animations) {
if (animation.playing) {
animation.update();
}
}
}
}
public function add(animate:Animate):Void {
animations.push(animate);
}
public function remove(animate:Animate):Void {
if (animations.indexOf(animate) > -1) {
animations.remove(animate);
}
}
}

View File

@@ -1,13 +1,8 @@
package ru.m.tankz;
import ru.m.animate.Animate.AnimateManager;
import flash.Lib;
import haxework.animate.FadeAnimate;
import haxework.animate.UnFadeAnimate;
import haxework.net.manage.ILoaderManager;
import haxework.net.manage.LoaderManager;
import haxework.resources.IResources;
import haxework.resources.Resources;
import haxework.storage.SharedObjectStorage;
import haxework.view.popup.PopupManager;
import haxework.view.theme.ITheme;
@@ -23,10 +18,8 @@ import ru.m.tankz.bundle.ClientLevelSource;
import ru.m.tankz.bundle.ConfigBundle;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.network.NetworkManager;
import ru.m.tankz.proto.pack.Request;
import ru.m.tankz.proto.pack.Response;
import ru.m.tankz.sound.SoundManager;
import ru.m.tankz.storage.GameStorage;
import ru.m.tankz.storage.NetworkStorage;
import ru.m.tankz.storage.RecordStorage;
@@ -36,21 +29,16 @@ import ru.m.update.Updater;
class Init {
@:provide static var theme:ITheme;
@:provide static var resources:IResources;
@:provide static var levelBundle:ILevelBundle;
@:provide static var configBundle:IConfigBundle;
@:provide static var settingsStorage:SettingsStorage;
@:provide static var multiplayerStorage:NetworkStorage;
@:provide static var gameStorage:GameStorage;
@:provide static var recordStorage:RecordStorage;
@:provide static var soundManager:SoundManager;
@:provide static var networkManager:NetworkManager;
@:provide static var popupManager:PopupManager;
@:provide static var connection:IConnection<Request, Response>;
@: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<Request, Response> {
var host:String = CompilationOption.get("host");
@@ -67,7 +55,6 @@ class Init {
public static function init():Void {
theme = new AppTheme();
resources = new Resources();
levelBundle = new CachedLevelBundle(new ClientLevelSource(), new SharedObjectStorage());
levelBundle.load();
configBundle = new ConfigBundle();
@@ -75,20 +62,15 @@ class Init {
multiplayerStorage = new NetworkStorage();
gameStorage = new GameStorage();
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);
connection = buildConnection();
networkManager = new NetworkManager();
bus = new ControlBus();
bus.connect(new KeyboardDevice(Lib.current.stage));
loaderManager = new LoaderManager();
updater = new Updater(Const.VERSION, "https://shmyga.ru/repo/tankz/packages.json");
for (device in Gamepad.devices) {

View File

@@ -36,7 +36,7 @@ enum ConnectionState {
ERROR(error:Dynamic);
}
class NetworkManager {
@:provide class NetworkManager {
private static inline var TAG = "NetworkManager";

View File

@@ -9,6 +9,7 @@ import haxework.view.form.LabelView;
import haxework.view.SpriteView;
import promhx.Promise;
import ru.m.animate.Animate;
import ru.m.animate.AnimateManager;
import ru.m.animate.OnceAnimate;
import ru.m.geom.Point;
import ru.m.tankz.config.Config;

View File

@@ -9,7 +9,7 @@ import ru.m.tankz.config.Config;
import ru.m.tankz.game.GameEvent;
import ru.m.tankz.game.IGame;
class SoundManager implements GameListener {
@:provide class SoundManager implements GameListener {
private static var TAG(default, never):String = "SoundManager";
#if flash