[common] add GameDispatcher
This commit is contained in:
@@ -1,25 +1,37 @@
|
||||
package ru.m.tankz.view.common;
|
||||
|
||||
import openfl.Assets;
|
||||
import haxework.view.LabelView;
|
||||
import haxework.view.ImageView;
|
||||
import haxework.view.HGroupView;
|
||||
import haxework.view.ImageView;
|
||||
import haxework.view.LabelView;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.game.GameState.PlayerState;
|
||||
import ru.m.tankz.game.GameState;
|
||||
|
||||
@:template class LifeView extends HGroupView {
|
||||
@:provide static var currentState:GameState;
|
||||
|
||||
@:view("tank") public var tankImage:ImageView;
|
||||
@:view("live") public var liveLabel:LabelView;
|
||||
@:view("life") public var lifeLabel:LabelView;
|
||||
@:view("score") public var scoreLabel:LabelView;
|
||||
|
||||
public var state(null, set):PlayerState;
|
||||
public var tank(null, set):String;
|
||||
public var color(null, set):Int;
|
||||
public var live(null, set):Int;
|
||||
public var life(null, set):Int;
|
||||
public var score(null, set):Int;
|
||||
|
||||
private inline function set_state(value:PlayerState):PlayerState {
|
||||
state = value;
|
||||
toUpdate();
|
||||
return state;
|
||||
}
|
||||
|
||||
private inline function set_tank(value:String):String {
|
||||
if (value != null) {
|
||||
tankImage.image = Assets.getBitmapData('resources/image/tank/${value}-0.png');
|
||||
if (value != null && value != tank) {
|
||||
tank = value;
|
||||
tankImage.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
|
||||
}
|
||||
return value;
|
||||
return tank;
|
||||
}
|
||||
|
||||
private inline function set_color(value:Int):Int {
|
||||
@@ -27,8 +39,8 @@ import haxework.view.HGroupView;
|
||||
return value;
|
||||
}
|
||||
|
||||
private inline function set_live(value:Int):Int {
|
||||
liveLabel.text = '${value}';
|
||||
private inline function set_life(value:Int):Int {
|
||||
lifeLabel.text = '${value}';
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -36,4 +48,21 @@ import haxework.view.HGroupView;
|
||||
scoreLabel.text = '${value}$';
|
||||
return value;
|
||||
}
|
||||
|
||||
override public function update():Void {
|
||||
super.update();
|
||||
if (state != null) {
|
||||
var tankConfig = currentState.config.getTank(state.tank);
|
||||
tank = tankConfig == null ? 'ba' : tankConfig.skin;
|
||||
color = currentState.config.getColor(state.id);
|
||||
life = state.life;
|
||||
score = state.score;
|
||||
}
|
||||
}
|
||||
|
||||
public static inline function factory(index:Int, data:PlayerState):LifeView {
|
||||
var result = new LifeView();
|
||||
result.state = data;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user