Files
tankz/src/client/haxe/ru/m/tankz/view/common/LifeView.hx

68 lines
1.9 KiB
Haxe

package ru.m.tankz.view.common;
import haxework.view.HGroupView;
import haxework.view.ImageView;
import haxework.view.LabelView;
import openfl.Assets;
import ru.m.tankz.game.GameState;
@:template class LifeView extends HGroupView {
@:provide static var currentState:GameState;
@:view("tank") public var tankImage:ImageView;
@: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 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 && value != tank) {
tank = value;
tankImage.image = Assets.getBitmapData('resources/image/tank/${tank}-0.png');
}
return tank;
}
private inline function set_color(value:Int):Int {
tankImage.color = value;
return value;
}
private inline function set_life(value:Int):Int {
lifeLabel.text = '${value}';
return value;
}
private inline function set_score(value:Int):Int {
scoreLabel.text = '${value}$';
return value;
}
override public function update():Void {
super.update();
if (state != null && currentState != 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;
}
}