[common] add PackId
This commit is contained in:
@@ -160,6 +160,7 @@ const server = new Project(
|
|||||||
*/
|
*/
|
||||||
module.exports.default = gulp.series(
|
module.exports.default = gulp.series(
|
||||||
exports.clean,
|
exports.clean,
|
||||||
|
exports.levels,
|
||||||
module.exports['client:flash:build'],
|
module.exports['client:flash:build'],
|
||||||
module.exports['client:flash:html'],
|
module.exports['client:flash:html'],
|
||||||
module.exports['client:html5:build'],
|
module.exports['client:html5:build'],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tankz",
|
"name": "tankz",
|
||||||
"version": "0.14.4",
|
"version": "0.15.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ class LevelBundle implements ILevelBundle {
|
|||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType, name:String):LevelPack {
|
public function get(id:PackId):LevelPack {
|
||||||
var bytes = Assets.getBytes('levels/${type}_${name}.zip');
|
var bytes = Assets.getBytes('levels/${id}.zip');
|
||||||
return {
|
return {
|
||||||
type: type,
|
id: id,
|
||||||
name: name,
|
|
||||||
data: LevelUtil.unpack(bytes),
|
data: LevelUtil.unpack(bytes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package ru.m.tankz.storage;
|
package ru.m.tankz.storage;
|
||||||
|
|
||||||
import haxework.storage.SharedObjectStorage;
|
import haxework.storage.SharedObjectStorage;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.PackProgress;
|
||||||
import ru.m.tankz.Type.GameType;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class GameStorage extends SharedObjectStorage {
|
class GameStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ class GameStorage extends SharedObjectStorage {
|
|||||||
super('game_${VERSION}');
|
super('game_${VERSION}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get(type:GameType):GameProgress {
|
public function get(id:PackId):PackProgress {
|
||||||
return exists(type) ? read(type) : new GameProgress(type);
|
return exists(id) ? read(id) : new PackProgress(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(progress:GameProgress):Void {
|
public function set(progress:PackProgress):Void {
|
||||||
write(progress.type, progress);
|
write(progress.id, progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ import ru.m.tankz.control.Control;
|
|||||||
|
|
||||||
class SettingsStorage extends SharedObjectStorage {
|
class SettingsStorage extends SharedObjectStorage {
|
||||||
|
|
||||||
|
private static inline var VERSION = 3;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super("settings-3");
|
super('settings_${VERSION}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBinding(index:Int):Binding {
|
public function getBinding(index:Int):Binding {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import ru.m.tankz.network.NetworkManager;
|
|||||||
import ru.m.tankz.sound.SoundManager;
|
import ru.m.tankz.sound.SoundManager;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
import ru.m.tankz.storage.SettingsStorage;
|
import ru.m.tankz.storage.SettingsStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.game.GameView;
|
import ru.m.tankz.view.game.GameView;
|
||||||
import ru.m.tankz.view.GamepadView;
|
import ru.m.tankz.view.GamepadView;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ import ru.m.tankz.view.GamepadView;
|
|||||||
@:provide var state:GameState;
|
@:provide var state:GameState;
|
||||||
@:provide var record:GameRecord;
|
@:provide var record:GameRecord;
|
||||||
@:provide var switcher:FrameSwitcher;
|
@:provide var switcher:FrameSwitcher;
|
||||||
@:provide var gameStorage:GameStorage;
|
@:provide static var gameStorage:GameStorage;
|
||||||
@:provide static var settings:SettingsStorage;
|
@:provide static var settings:SettingsStorage;
|
||||||
|
|
||||||
@:provide var game:IGame;
|
@:provide var game:IGame;
|
||||||
@@ -75,12 +76,28 @@ import ru.m.tankz.view.GamepadView;
|
|||||||
switch event {
|
switch event {
|
||||||
case COMPLETE(state, winner):
|
case COMPLETE(state, winner):
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
updateProgress(game, winner);
|
||||||
stop();
|
stop();
|
||||||
switcher.change(ResultFrame.ID);
|
switcher.change(ResultFrame.ID);
|
||||||
case _:
|
case _:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDo:
|
||||||
|
private static function updateProgress(game:IGame, winner:TeamId):Void {
|
||||||
|
var complete = true;
|
||||||
|
for (rule in game.config.game.complete) {
|
||||||
|
if (rule.team != null && rule.team != winner) {
|
||||||
|
complete = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (complete) {
|
||||||
|
var progress = gameStorage.get(new PackId(game.state.type));
|
||||||
|
progress.completeLevel(game.level.id, game.state.presetId);
|
||||||
|
gameStorage.set(progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onHide():Void {
|
public function onHide():Void {
|
||||||
stop();
|
stop();
|
||||||
soundManager.stopAll();
|
soundManager.stopAll();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import ru.m.tankz.game.GameState;
|
|||||||
import ru.m.tankz.game.IGame;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.local.LocalGame;
|
import ru.m.tankz.local.LocalGame;
|
||||||
import ru.m.tankz.storage.GameStorage;
|
import ru.m.tankz.storage.GameStorage;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
import ru.m.tankz.view.popup.LevelPopup;
|
import ru.m.tankz.view.popup.LevelPopup;
|
||||||
|
|
||||||
@:template class LevelFrame extends VGroupView {
|
@:template class LevelFrame extends VGroupView {
|
||||||
@@ -25,11 +26,12 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
@:provide var levelBundle:ILevelBundle;
|
@:provide var levelBundle:ILevelBundle;
|
||||||
@:provide var storage:GameStorage;
|
@:provide var storage:GameStorage;
|
||||||
|
|
||||||
|
private var pack:LevelPack;
|
||||||
private var levelPopup:LevelPopup;
|
private var levelPopup:LevelPopup;
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
header.text = state.type;
|
header.text = state.type;
|
||||||
var pack = levelBundle.get(state.type, "standard");
|
pack = levelBundle.get(new PackId(state.type));
|
||||||
levels.data = pack.data;
|
levels.data = pack.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +43,7 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
private function levelViewFactory(index:Int, level:LevelConfig):ButtonView {
|
||||||
var progress = storage.get(state.type);
|
var progress = storage.get(pack.id);
|
||||||
var result = new ButtonView();
|
var result = new ButtonView();
|
||||||
result.skinId = "button.level";
|
result.skinId = "button.level";
|
||||||
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
var presetsLine = [for (p in state.config.presets) progress.isPresetCompleted(level.id, p.id) ? '*' : '_'].join('');
|
||||||
@@ -51,7 +53,7 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
private function onLevelSelect(index:Int, level:LevelConfig, view:ButtonView):Void {
|
||||||
if (!storage.get(state.type).isLevelAvailable(level.id)) {
|
if (!storage.get(pack.id).isLevelAvailable(level.id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (levelPopup == null) {
|
if (levelPopup == null) {
|
||||||
@@ -61,7 +63,7 @@ import ru.m.tankz.view.popup.LevelPopup;
|
|||||||
level,
|
level,
|
||||||
state.config.presets,
|
state.config.presets,
|
||||||
state.config.controls,
|
state.config.controls,
|
||||||
storage.get(state.type)
|
storage.get(pack.id)
|
||||||
);
|
);
|
||||||
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
levelPopup.show().then(function(result) result != null ? start(level, result.preset, result.control) : {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ private typedef Result = {
|
|||||||
for (v in typeView.dataViews) {
|
for (v in typeView.dataViews) {
|
||||||
v.on = v == view;
|
v.on = v == view;
|
||||||
}
|
}
|
||||||
levelView.data = levelBundle.get(value, "standard").data;
|
levelView.data = levelBundle.get(new PackId(value)).data;
|
||||||
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
onLevelSelect(0, levelView.data[0], levelView.dataViews[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package ru.m.tankz.view.popup;
|
package ru.m.tankz.view.popup;
|
||||||
|
|
||||||
import haxework.view.ToggleButtonView;
|
|
||||||
import haxework.view.ButtonView;
|
import haxework.view.ButtonView;
|
||||||
import haxework.view.DataView;
|
import haxework.view.DataView;
|
||||||
import haxework.view.LabelView;
|
import haxework.view.LabelView;
|
||||||
import haxework.view.popup.PopupView;
|
import haxework.view.popup.PopupView;
|
||||||
|
import haxework.view.ToggleButtonView;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.game.GameProgress;
|
import ru.m.tankz.game.PackProgress;
|
||||||
|
|
||||||
private typedef Result = {
|
private typedef Result = {
|
||||||
var control:ControlPreset;
|
var control:ControlPreset;
|
||||||
@@ -16,14 +16,14 @@ private typedef Result = {
|
|||||||
@:template class LevelPopup extends PopupView<Result> {
|
@:template class LevelPopup extends PopupView<Result> {
|
||||||
|
|
||||||
private var level:LevelConfig;
|
private var level:LevelConfig;
|
||||||
private var progress:GameProgress;
|
private var progress:PackProgress;
|
||||||
|
|
||||||
@:view var name:LabelView;
|
@:view var name:LabelView;
|
||||||
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
@:view("presets") var presetsView:DataView<GamePreset, ButtonView>;
|
||||||
@:view("controls") var controlsView:DataView<ControlPreset, ToggleButtonView>;
|
@:view("controls") var controlsView:DataView<ControlPreset, ToggleButtonView>;
|
||||||
private var control:ControlPreset;
|
private var control:ControlPreset;
|
||||||
|
|
||||||
public function setData(level:LevelConfig, presets:Array<GamePreset>, controls:Array<ControlPreset>, progress:GameProgress):Void {
|
public function setData(level:LevelConfig, presets:Array<GamePreset>, controls:Array<ControlPreset>, progress:PackProgress):Void {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
name.text = '${level.id}. ${level.name != null ? level.name : "#"}';
|
name.text = '${level.id}. ${level.name != null ? level.name : "#"}';
|
||||||
|
|||||||
@@ -39,5 +39,33 @@ abstract PlayerId(Array<Dynamic>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract PackId(Array<Dynamic>) {
|
||||||
|
public static inline var DEFAULT = "standard";
|
||||||
|
|
||||||
|
public var type(get, never):GameType;
|
||||||
|
public var name(get, never):String;
|
||||||
|
|
||||||
|
public function new(type:GameType, name:String = DEFAULT) {
|
||||||
|
this = [type, name];
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline function get_type():GameType return this[0];
|
||||||
|
|
||||||
|
private inline function get_name():String return this[1];
|
||||||
|
|
||||||
|
@:from static public inline function fromArray(value:Array<Dynamic>):PackId {
|
||||||
|
return new PackId(value[0], value[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@:to public inline function toString():String {
|
||||||
|
return '${type}_${name}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@:op(X == Y) static public inline function equals(x:PackId, y:PackId):Bool {
|
||||||
|
return x.type == y.type && x.name == y.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef LevelId = Int;
|
typedef LevelId = Int;
|
||||||
|
|
||||||
typedef PresetId = Int;
|
typedef PresetId = Int;
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ import ru.m.tankz.config.Config;
|
|||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface ILevelBundle {
|
interface ILevelBundle {
|
||||||
public function get(type:GameType, name:String):LevelPack;
|
public function get(id:PackId):LevelPack;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,8 +115,7 @@ typedef LevelConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef LevelPack = {
|
typedef LevelPack = {
|
||||||
var type:GameType;
|
var id:PackId;
|
||||||
var name:String;
|
|
||||||
var data:Array<LevelConfig>;
|
var data:Array<LevelConfig>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface IGame extends GameListener {
|
|||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
public var level(default, null):LevelConfig;
|
||||||
public var controlFactory(default, null):IControlFactory;
|
public var controlFactory(default, null):IControlFactory;
|
||||||
public var pause(default, set):Bool;
|
public var pause(default, set):Bool;
|
||||||
public var controls(default, null):Map<String, Control>;
|
public var controls(default, null):Map<String, Control>;
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ typedef LevelProgress = {
|
|||||||
var presets:Map<Int, LevelResult>;
|
var presets:Map<Int, LevelResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameProgress {
|
class PackProgress {
|
||||||
|
|
||||||
|
public var id(default, null):PackId;
|
||||||
|
|
||||||
public var type(default, null):GameType;
|
|
||||||
private var completed(default, null):Map<Int, LevelProgress>;
|
private var completed(default, null):Map<Int, LevelProgress>;
|
||||||
|
|
||||||
public function new(type:GameType) {
|
public function new(id:PackId) {
|
||||||
this.type = type;
|
this.id = id;
|
||||||
this.completed = new Map();
|
this.completed = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,12 +11,11 @@ class ServerLevelBundle implements ILevelBundle {
|
|||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
public function get(type:GameType, name:String):LevelPack {
|
public function get(id:PackId):LevelPack {
|
||||||
var path = FileSystem.absolutePath('./levels/${type}_${name}.zip');
|
var path = FileSystem.absolutePath('./levels/${id}.zip');
|
||||||
var bytes = File.getBytes(path);
|
var bytes = File.getBytes(path);
|
||||||
return {
|
return {
|
||||||
type: type,
|
id: id,
|
||||||
name: name,
|
|
||||||
data: LevelUtil.unpack(bytes),
|
data: LevelUtil.unpack(bytes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
import ru.m.tankz.bundle.ILevelBundle;
|
import ru.m.tankz.bundle.ILevelBundle;
|
||||||
import ru.m.tankz.proto.room.RoomSlotProto;
|
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.game.EventUtil;
|
import ru.m.tankz.game.EventUtil;
|
||||||
@@ -10,8 +9,10 @@ import ru.m.tankz.game.GameRunner;
|
|||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
import ru.m.tankz.proto.core.UserProto;
|
import ru.m.tankz.proto.core.UserProto;
|
||||||
import ru.m.tankz.proto.room.RoomProto;
|
import ru.m.tankz.proto.room.RoomProto;
|
||||||
|
import ru.m.tankz.proto.room.RoomSlotProto;
|
||||||
import ru.m.tankz.proto.room.SlotProto;
|
import ru.m.tankz.proto.room.SlotProto;
|
||||||
import ru.m.tankz.server.control.ServerControlFactory;
|
import ru.m.tankz.server.control.ServerControlFactory;
|
||||||
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
class ServerGame extends GameRunner {
|
class ServerGame extends GameRunner {
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ class ServerGame extends GameRunner {
|
|||||||
@:provide static var levelBundle:ILevelBundle;
|
@:provide static var levelBundle:ILevelBundle;
|
||||||
|
|
||||||
public function new(room:RoomProto) {
|
public function new(room:RoomProto) {
|
||||||
super(new GameState(room.game.type, 0), levelBundle.get(room.game.type, "standard").data[room.game.level]);
|
super(new GameState(room.game.type, 0), levelBundle.get(new PackId(room.game.type)).data[room.game.level]);
|
||||||
this.controlFactory = new ServerControlFactory();
|
this.controlFactory = new ServerControlFactory();
|
||||||
this.room = room;
|
this.room = room;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user