[common] remove GameSave; [client] update @:template macro use
This commit is contained in:
@@ -13,7 +13,7 @@ import haxework.resources.IResources;
|
||||
#if flash import haxework.log.JSLogger; #end
|
||||
#if debug import haxework.log.SocketLogger; #end
|
||||
|
||||
|
||||
@:style("ru/m/tankz/Style.yaml")
|
||||
class Client {
|
||||
private static inline var TAG = 'Tankz';
|
||||
|
||||
@@ -36,16 +36,16 @@ class Client {
|
||||
}
|
||||
}
|
||||
|
||||
@:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml')
|
||||
class ClientView extends VGroupView {
|
||||
@:view private var switcher(default, null):IFrameSwitcher;
|
||||
|
||||
@:template class ClientView extends VGroupView {
|
||||
private static inline var TAG = 'Tankz';
|
||||
|
||||
@:view private var switcher(default, null):IFrameSwitcher;
|
||||
@:provide var resources:IResources;
|
||||
|
||||
public function init():Void {
|
||||
var font:Font = Font.enumerateFonts()[0];
|
||||
Provider.get(IResources).text.put('font', 'Bookman Old Style');
|
||||
Provider.get(IResources).text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||
resources.text.put('font', 'Bookman Old Style');
|
||||
resources.text.put('version', 'v${Const.VERSION} b${Const.BUILD}');
|
||||
Provider.set(IFrameSwitcher, switcher);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.game.Player;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.bot.BotControl;
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ class ClientControlFactory implements IControlFactory {
|
||||
humanControlIndex = 0;
|
||||
}
|
||||
|
||||
public function build(player:Player):Control {
|
||||
return switch (player.config.control) {
|
||||
case Control.HUMAN: new HumanControl(player.id, humanControlIndex++);
|
||||
case Control.BOT: new BotControl(player.id);
|
||||
public function build(id:PlayerId, type:ControlType):Control {
|
||||
return switch (type) {
|
||||
case Control.HUMAN: new HumanControl(id, humanControlIndex++);
|
||||
case Control.BOT: new BotControl(id);
|
||||
case Control.NONE: null;
|
||||
case _: throw 'Unsupported control type: "${player.config.control}"';
|
||||
case _: throw 'Unsupported control type: "${type}"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import ru.m.tankz.frame.game.DotaGamePanel;
|
||||
import ru.m.tankz.frame.game.IGamePanel;
|
||||
import ru.m.tankz.frame.game.ClassicGamePanel;
|
||||
import ru.m.tankz.preset.DotaGame;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.Type.GameType;
|
||||
import haxework.gui.View;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.network.NetworkGame;
|
||||
import flash.events.Event;
|
||||
import haxe.ds.Option;
|
||||
import haxe.Timer;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.frame.game.ClassicGamePanel;
|
||||
import ru.m.tankz.frame.game.DotaGamePanel;
|
||||
import ru.m.tankz.frame.game.IGamePanel;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.game.GameSave;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkGame;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.preset.DotaGame;
|
||||
import ru.m.tankz.render.Render;
|
||||
import ru.m.tankz.sound.SoundManager;
|
||||
import ru.m.tankz.storage.SaveStorage;
|
||||
import ru.m.tankz.Type.GameType;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
class GameFrame extends VGroupView {
|
||||
@:template class GameFrame extends VGroupView {
|
||||
|
||||
private static inline var TAG = "GameFrame";
|
||||
|
||||
@@ -36,9 +31,13 @@ class GameFrame extends VGroupView {
|
||||
@:view var dotaPanel(default, null):DotaGamePanel;
|
||||
@:view var classicPanel(default, null):ClassicGamePanel;
|
||||
|
||||
var panels:Map<GameType, IGamePanel>;
|
||||
private var panels:Map<GameType, IGamePanel>;
|
||||
|
||||
@:provide var network:NetworkManager;
|
||||
@:provide var sound:SoundManager;
|
||||
@:provide var state:GameState;
|
||||
@:provide var storage:SaveStorage;
|
||||
@:provide var switcher:IFrameSwitcher;
|
||||
|
||||
private var game:Game;
|
||||
private var timer:Timer;
|
||||
@@ -50,35 +49,36 @@ class GameFrame extends VGroupView {
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
start(Provider.get(GameSave));
|
||||
start(state);
|
||||
}
|
||||
|
||||
private function connectGame(game: Game) {
|
||||
game.engine.connect(render);
|
||||
game.engine.connect(Provider.get(SoundManager));
|
||||
game.engine.connect(sound);
|
||||
}
|
||||
|
||||
private function start(save:GameSave):Void {
|
||||
private function start(state:GameState):Void {
|
||||
for (type in panels.keys()) {
|
||||
panels.get(type).visible = type == save.state.type;
|
||||
panels.get(type).inLayout = type == save.state.type;
|
||||
panels.get(type).visible = type == state.type;
|
||||
panels.get(type).inLayout = type == state.type;
|
||||
}
|
||||
switch (save.server) {
|
||||
case GameServer.LOCAL:
|
||||
game = new Game(save.state.type);
|
||||
// ToDo: local / network game
|
||||
switch (1) {
|
||||
case 1:
|
||||
game = new Game(state.type);
|
||||
connectGame(game);
|
||||
game.start(save).then(onGameStateChange).endThen(onGameComplete);
|
||||
game.start(state).then(onGameStateChange).endThen(onGameComplete);
|
||||
timer = new Timer(10);
|
||||
timer.run = updateEngine;
|
||||
case GameServer.NETWORK:
|
||||
game = new NetworkGame(save.state.type);
|
||||
case 2:
|
||||
game = new NetworkGame(state.type);
|
||||
connectGame(game);
|
||||
network.game = cast game;
|
||||
}
|
||||
panels.get(save.state.type).game = game;
|
||||
panels.get(state.type).game = game;
|
||||
content.addEventListener(Event.ENTER_FRAME, redraw);
|
||||
render.draw(game.engine);
|
||||
Provider.get(SoundManager).play('start');
|
||||
sound.play('start');
|
||||
}
|
||||
|
||||
private function stop():Void {
|
||||
@@ -107,12 +107,13 @@ class GameFrame extends VGroupView {
|
||||
}
|
||||
switch (game.next()) {
|
||||
case Option.Some(s):
|
||||
var save = game.save();
|
||||
Provider.get(SaveStorage).write(save);
|
||||
var state = game.save();
|
||||
this.state = state;
|
||||
storage.write(state);
|
||||
stop();
|
||||
start(save);
|
||||
start(state);
|
||||
case Option.None:
|
||||
Provider.get(IFrameSwitcher).change(StartFrame.ID);
|
||||
switcher.change(StartFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.game.GameSave;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.network.NetworkManager;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.proto.core.GameInfoProto;
|
||||
@@ -16,8 +16,7 @@ import ru.m.tankz.proto.core.GameStateProto;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/NetworkFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
class NetworkFrame extends VGroupView {
|
||||
@:template class NetworkFrame extends VGroupView {
|
||||
public static var ID(default, never):String = "network";
|
||||
|
||||
@:view var frameSwitcher(default, null):IFrameSwitcher;
|
||||
@@ -80,7 +79,7 @@ class NetworkFrame extends VGroupView {
|
||||
userList.data = game.players;
|
||||
frameSwitcher.change(gameFrame.id);
|
||||
if (game.state == GameStateProto.STARTED) {
|
||||
Provider.set(GameSave, new GameSave({type: ClassicGame.TYPE, presetId: ClassicGame.PLAYER1}, null, GameServer.NETWORK));
|
||||
Provider.set(GameState, new GameState(ClassicGame.TYPE, ClassicGame.PLAYER1));
|
||||
mainFrameSwitcher.change(GameFrame.ID);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -5,8 +5,7 @@ import haxework.gui.ButtonView;
|
||||
import haxework.gui.VGroupView;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/SettingsFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
class SettingsFrame extends VGroupView {
|
||||
@:template class SettingsFrame extends VGroupView {
|
||||
|
||||
public static var ID(default, never):String = "settings";
|
||||
|
||||
|
||||
@@ -3,16 +3,13 @@ package ru.m.tankz.frame;
|
||||
import haxework.gui.ButtonView;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
import ru.m.tankz.preset.DotaGame;
|
||||
import ru.m.tankz.game.GameSave;
|
||||
import ru.m.tankz.storage.SaveStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/StartFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
class StartFrame extends VGroupView {
|
||||
@:template class StartFrame extends VGroupView {
|
||||
|
||||
public static var ID(default, never):String = "start";
|
||||
|
||||
@@ -22,6 +19,7 @@ class StartFrame extends VGroupView {
|
||||
@:view var settings(default, null):ButtonView;
|
||||
|
||||
@:provide var frameSwitcher:IFrameSwitcher;
|
||||
@:provide var state:GameState;
|
||||
@:provide var storage:SaveStorage;
|
||||
|
||||
public function init():Void {
|
||||
@@ -45,7 +43,7 @@ class StartFrame extends VGroupView {
|
||||
}
|
||||
|
||||
private function startGame(type:GameType, presetId:PresetId):Void {
|
||||
Provider.set(GameSave, new GameSave({type: type, presetId: presetId}));
|
||||
state = new GameState(type, presetId);
|
||||
frameSwitcher.change(StartGameFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package ru.m.tankz.frame;
|
||||
|
||||
import ru.m.tankz.storage.SaveStorage;
|
||||
import haxework.gui.frame.IFrameSwitcher;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.VGroupView;
|
||||
import haxework.provider.Provider;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.frame.level.PresetsView;
|
||||
import ru.m.tankz.game.GameSave;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.storage.SaveStorage;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/StartGameFrame.yaml", "ru/m/tankz/Style.yaml")
|
||||
class StartGameFrame extends VGroupView {
|
||||
@:template class StartGameFrame extends VGroupView {
|
||||
public static inline var ID = "level";
|
||||
|
||||
@:view var presets(default, null):PresetsView;
|
||||
@:view var players(default, null):ListView<PlayerConfig>;
|
||||
@:view var players(default, null):ListView<PlayerId>;
|
||||
@:view var levels(default, null):ListView<Int>;
|
||||
|
||||
@:provide var save:GameSave;
|
||||
@:provide var state:GameState;
|
||||
@:provide var storage:SaveStorage;
|
||||
|
||||
public var gameType(default, set):GameType;
|
||||
@@ -43,7 +43,7 @@ class StartGameFrame extends VGroupView {
|
||||
presetId = null;
|
||||
presetId = config.presets[0].id;
|
||||
|
||||
var save:GameSave = storage.read(gameType);
|
||||
var save:GameState = storage.read(gameType);
|
||||
// ToDo: start save button
|
||||
}
|
||||
return gameType;
|
||||
@@ -53,13 +53,19 @@ class StartGameFrame extends VGroupView {
|
||||
if (presetId != value) {
|
||||
presetId = value;
|
||||
presets.selected = presetId;
|
||||
save.state.presetId = presetId;
|
||||
state = new GameState(gameType, presetId);
|
||||
if (presetId != null) {
|
||||
preset = config.getPreset(presetId);
|
||||
var players:Array<PlayerConfig> = [];
|
||||
var players:Array<PlayerId> = [];
|
||||
for (team in preset.teams) {
|
||||
players.push({index: -1, control: 'Team "${team.id}"', tanks: []});
|
||||
players = players.concat(team.players);
|
||||
var human = true;
|
||||
players.push(new PlayerId(team.id, -1));
|
||||
for (player in team.players) {
|
||||
var playerId = new PlayerId(team.id, player.index);
|
||||
state.control.set(playerId, human ? Control.HUMAN : Control.BOT);
|
||||
human = false;
|
||||
players.push(playerId);
|
||||
}
|
||||
}
|
||||
this.players.data = players;
|
||||
} else {
|
||||
@@ -70,14 +76,14 @@ class StartGameFrame extends VGroupView {
|
||||
}
|
||||
|
||||
public function onShow():Void {
|
||||
gameType = save.state.type;
|
||||
if (save.state.presetId != null) {
|
||||
presetId = save.state.presetId;
|
||||
gameType = state.type;
|
||||
if (state.presetId != null) {
|
||||
presetId = state.presetId;
|
||||
}
|
||||
}
|
||||
|
||||
public function onListItemClick(item:IListItemView<Int>):Void {
|
||||
Provider.get(GameSave).state.level = item.data;
|
||||
state.level = item.data;
|
||||
Provider.get(IFrameSwitcher).change(GameFrame.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ views:
|
||||
pHeight: 100
|
||||
views:
|
||||
- id: players
|
||||
$type: haxework.gui.list.VListView<ru.m.tankz.config.Config.PlayerConfig>
|
||||
$type: haxework.gui.list.VListView<PlayerId>
|
||||
factory: "@class:ru.m.tankz.frame.level.PlayerView"
|
||||
pWidth: 50
|
||||
pHeight: 100
|
||||
|
||||
@@ -5,8 +5,7 @@ import haxework.gui.VGroupView;
|
||||
import ru.m.tankz.game.Game;
|
||||
import ru.m.tankz.preset.ClassicGame;
|
||||
|
||||
@:template("ru/m/tankz/frame/game/ClassicGamePanel.yaml", "ru/m/tankz/Style.yaml")
|
||||
class ClassicGamePanel extends VGroupView implements IGamePanel {
|
||||
@:template class ClassicGamePanel extends VGroupView implements IGamePanel {
|
||||
|
||||
@:view var botstate(default, null):LabelView;
|
||||
@:view var player1state(default, null):LabelView;
|
||||
|
||||
@@ -4,8 +4,7 @@ import haxework.gui.LabelView;
|
||||
import haxework.gui.HGroupView;
|
||||
import ru.m.tankz.game.Game;
|
||||
|
||||
@:template("ru/m/tankz/frame/game/DotaGamePanel.yaml", "ru/m/tankz/Style.yaml")
|
||||
class DotaGamePanel extends HGroupView implements IGamePanel {
|
||||
@:template class DotaGamePanel extends HGroupView implements IGamePanel {
|
||||
|
||||
@:view var state(default, null):LabelView;
|
||||
|
||||
@@ -18,7 +17,7 @@ class DotaGamePanel extends HGroupView implements IGamePanel {
|
||||
var result:Array<String> = [];
|
||||
result.push('Level: ${game.state.level}');
|
||||
for (team in game.teams) {
|
||||
if (game.state.loser == team.id) {
|
||||
if (game.loser == team.id) {
|
||||
result.push('${team.id}: LOSE');
|
||||
} else if (team.life > 0) {
|
||||
result.push('${team.id}: ${team.life}');
|
||||
|
||||
@@ -5,8 +5,7 @@ import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/level/LevelView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class LevelView extends HGroupView implements IListItemView<Int> {
|
||||
@:template class LevelView extends HGroupView implements IListItemView<Int> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):Int;
|
||||
|
||||
@@ -4,39 +4,52 @@ import haxework.gui.ButtonView;
|
||||
import haxework.gui.HGroupView;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView.IListItemView;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/level/PlayerView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class PlayerView extends HGroupView implements IListItemView<PlayerConfig> {
|
||||
@:template class PlayerView extends HGroupView implements IListItemView<PlayerId> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):PlayerConfig;
|
||||
public var data(default, set):PlayerId;
|
||||
|
||||
@:view("index") var indexLabel(default, null):LabelView;
|
||||
@:view var control(default, null):ButtonView;
|
||||
|
||||
@:provide var state:GameState;
|
||||
|
||||
private function init():Void {
|
||||
control.onPress = this;
|
||||
}
|
||||
|
||||
private function set_data(value:PlayerConfig):PlayerConfig {
|
||||
private function set_data(value:PlayerId):PlayerId {
|
||||
data = value;
|
||||
indexLabel.text = data.index == -1 ? "" : Std.string(data.index);
|
||||
control.text = data.control;
|
||||
control.fontColor = data.index == -1 ? 0x00ff00 : 0xffffff;
|
||||
if (data.index == -1) {
|
||||
indexLabel.text = "";
|
||||
control.text = data.team;
|
||||
control.fontColor = 0x00ff00;
|
||||
} else {
|
||||
indexLabel.text = Std.string(data.index);
|
||||
var controlType = state.control.get(value);
|
||||
control.text = controlType;
|
||||
control.fontColor = switch controlType {
|
||||
case Control.HUMAN: 0xffff00;
|
||||
case _: 0xffffff;
|
||||
};
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public function onPress(view:ButtonView):Void {
|
||||
if (data != null && data.index > -1) {
|
||||
data.control = switch (data.control) {
|
||||
var controlType = switch state.control.get(data) {
|
||||
case Control.BOT: Control.HUMAN;
|
||||
case Control.HUMAN: Control.BOT;
|
||||
case _: Control.BOT;
|
||||
}
|
||||
control.text = data.control;
|
||||
state.control.set(data, controlType);
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,7 @@ import haxework.gui.list.ListView;
|
||||
import ru.m.tankz.proto.core.GameInfoProto;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/network/GameItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
|
||||
@:template class GameItemView extends HGroupView implements IListItemView<GameInfoProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):GameInfoProto;
|
||||
|
||||
@@ -6,8 +6,7 @@ import haxework.gui.list.ListView;
|
||||
import ru.m.tankz.proto.core.UserProto;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/network/UserItemView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class UserItemView extends HGroupView implements IListItemView<UserProto> {
|
||||
@:template class UserItemView extends HGroupView implements IListItemView<UserProto> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):UserProto;
|
||||
|
||||
@@ -38,8 +38,7 @@ class KeyboardMap {
|
||||
}
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/settings/ActionView.yaml", "ru/m/tankz/Style.yaml")
|
||||
class ActionView extends HGroupView implements IListItemView<ActionItem> {
|
||||
@:template class ActionView extends HGroupView implements IListItemView<ActionItem> {
|
||||
|
||||
public var item_index(default, default):Int;
|
||||
public var data(default, set):ActionItem;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package ru.m.tankz.frame.settings;
|
||||
|
||||
import haxework.gui.LabelView;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
import haxework.gui.ButtonView;
|
||||
import ru.m.tankz.control.ActionConfig.ActionItem;
|
||||
import haxework.gui.LabelView;
|
||||
import haxework.gui.list.ListView;
|
||||
import haxework.gui.VGroupView;
|
||||
import promhx.Promise;
|
||||
import ru.m.tankz.control.ActionConfig.ActionItem;
|
||||
import ru.m.tankz.control.ActionConfig;
|
||||
import ru.m.tankz.storage.SettingsStorage;
|
||||
|
||||
|
||||
@:template("ru/m/tankz/frame/settings/SettingsEditor.yaml", "ru/m/tankz/Style.yaml")
|
||||
class SettingsEditor extends VGroupView {
|
||||
@:template class SettingsEditor extends VGroupView {
|
||||
|
||||
public var controlIndex(default, set): Int;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package ru.m.tankz.storage;
|
||||
|
||||
import flash.net.SharedObject;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.Type;
|
||||
import ru.m.tankz.game.GameSave;
|
||||
|
||||
|
||||
class SaveStorage {
|
||||
@@ -15,19 +15,19 @@ class SaveStorage {
|
||||
so = SharedObject.getLocal('tankz');
|
||||
}
|
||||
|
||||
public function read(type:GameType):Null<GameSave> {
|
||||
public function read(type:GameType):Null<GameState> {
|
||||
var data:String = Reflect.getProperty(so.data, type);
|
||||
L.d(TAG, 'read: ${data}');
|
||||
if (data != null) {
|
||||
return GameSave.fromYaml(data);
|
||||
return GameState.fromYaml(data);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function write(save:GameSave):Void {
|
||||
public function write(save:GameState):Void {
|
||||
var data:String = save.toYaml();
|
||||
L.d(TAG, 'write: ${data}');
|
||||
so.setProperty(save.state.type, data);
|
||||
so.setProperty(save.type, data);
|
||||
so.flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class SettingsStorage {
|
||||
}
|
||||
|
||||
public static function getDefault(index: Int): ActionConfig {
|
||||
return defaults.get(index).clone();
|
||||
return (defaults.exists(index) ? defaults.get(index) : empty).clone();
|
||||
}
|
||||
|
||||
private static var defaults: Map<Int, ActionConfig> = [
|
||||
@@ -52,4 +52,12 @@ class SettingsStorage {
|
||||
{action:TankAction.SHOT, key:Keyboard.NUMPAD_0},
|
||||
]),
|
||||
];
|
||||
|
||||
private static var empty: ActionConfig = new ActionConfig([
|
||||
{action:TankAction.MOVE(Direction.TOP), key:-1},
|
||||
{action:TankAction.MOVE(Direction.LEFT), key:-1},
|
||||
{action:TankAction.MOVE(Direction.BOTTOM), key:-1},
|
||||
{action:TankAction.MOVE(Direction.RIGHT), key:-1},
|
||||
{action:TankAction.SHOT, key:-1},
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user