feat(app): add network game mode
This commit is contained in:
@@ -20,7 +20,8 @@
|
||||
"svg": "1.1.3",
|
||||
"protohx": "0.4.6",
|
||||
"yield": "3.2.2",
|
||||
"formatter": "1.16.0"
|
||||
"formatter": "1.16.0",
|
||||
"hxWebSockets": "1.4.0"
|
||||
},
|
||||
"haxe": "4.2.5"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package ru.m.puzzlez.net;
|
||||
|
||||
import ru.m.puzzlez.proto.pack.GameCreateRequest;
|
||||
import hw.connect.ConnectionFactory;
|
||||
import hw.connect.IConnection;
|
||||
import hw.signal.Signal;
|
||||
import hw.storage.SharedObjectStorage;
|
||||
import promhx.Promise;
|
||||
import ru.m.data.IDataSource;
|
||||
import ru.m.data.DataSource;
|
||||
import ru.m.puzzlez.proto.core.User;
|
||||
import ru.m.puzzlez.proto.event.GameAction;
|
||||
import ru.m.puzzlez.proto.event.GameEvent;
|
||||
@@ -21,7 +22,13 @@ import ru.m.puzzlez.proto.pack.NotificationResponse;
|
||||
import ru.m.puzzlez.proto.pack.Request;
|
||||
import ru.m.puzzlez.proto.pack.Response;
|
||||
|
||||
@:provide class Network implements IDataSource<String, GameState> {
|
||||
abstract SignalExt<T>(Signal<T>) from Signal<T> to Signal<T> {
|
||||
public function next():Promise<T> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@:provide class Network implements DataSource<GameState> {
|
||||
public var userSignal:Signal<User> = new Signal();
|
||||
public var notificationSignal:Signal<NotificationResponse> = new Signal();
|
||||
public var listSignal:Signal<GameListResponse> = new Signal();
|
||||
@@ -51,17 +58,17 @@ import ru.m.puzzlez.proto.pack.Response;
|
||||
|
||||
public function auth():Promise<User> {
|
||||
connection.send(new Request().setAuth(new AuthRequest().setUser(restoreUser())));
|
||||
return userSignal.next();
|
||||
return cast(userSignal, SignalExt<Dynamic>).next();
|
||||
}
|
||||
|
||||
public function createGame(preset:GamePreset):Promise<GameState> {
|
||||
connection.send(new Request().setJoin(new GameJoinRequest().setPreset(preset)));
|
||||
return joinSignal.next();
|
||||
connection.send(new Request().setCreate(new GameCreateRequest().setPreset(preset)));
|
||||
return cast(joinSignal, SignalExt<Dynamic>).next();
|
||||
}
|
||||
|
||||
public function joinGame(gameId:String):Promise<GameState> {
|
||||
connection.send(new Request().setJoin(new GameJoinRequest().setGameId(gameId)));
|
||||
return joinSignal.next();
|
||||
return cast(joinSignal, SignalExt<Dynamic>).next();
|
||||
}
|
||||
|
||||
public function leaveGame():Void {
|
||||
@@ -113,8 +120,4 @@ import ru.m.puzzlez.proto.pack.Response;
|
||||
data: list.games,
|
||||
}));
|
||||
}
|
||||
|
||||
public function get(id:String):GameState {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package ru.m.puzzlez.net;
|
||||
|
||||
import ru.m.puzzlez.proto.event.GameStart;
|
||||
import hw.signal.Signal;
|
||||
import ru.m.puzzlez.image.IGame;
|
||||
import ru.m.puzzlez.game.IGame;
|
||||
import ru.m.puzzlez.proto.event.GameAction;
|
||||
import ru.m.puzzlez.proto.event.GameEvent;
|
||||
import ru.m.puzzlez.proto.game.GameState;
|
||||
|
||||
@@ -7,6 +7,7 @@ import hw.view.popup.ConfirmView;
|
||||
import promhx.Promise;
|
||||
import ru.m.puzzlez.game.Game;
|
||||
import ru.m.puzzlez.game.IGame;
|
||||
import ru.m.puzzlez.net.NetworkGame;
|
||||
import ru.m.puzzlez.proto.event.GameAction;
|
||||
import ru.m.puzzlez.proto.event.GameEvent;
|
||||
import ru.m.puzzlez.proto.event.gameaction.Action;
|
||||
@@ -37,7 +38,7 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
||||
L.d("Frame", '$ID: ${state.preset.image.source}:${state.preset.image.id}');
|
||||
onHide();
|
||||
if (state.online) {
|
||||
// game = new NetworkGame(state);
|
||||
game = new NetworkGame(state);
|
||||
} else {
|
||||
game = new Game(state);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import hw.view.form.ToggleButtonView;
|
||||
import hw.view.frame.FrameSwitcher;
|
||||
import hw.view.frame.FrameView;
|
||||
import ru.m.puzzlez.game.GameUtil;
|
||||
import ru.m.puzzlez.net.Network;
|
||||
import ru.m.puzzlez.proto.game.ImageId;
|
||||
import ru.m.puzzlez.view.common.PresetView;
|
||||
|
||||
@@ -17,7 +18,7 @@ import ru.m.puzzlez.view.common.PresetView;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
// @:provide var network:Network;
|
||||
@:provide var network:Network;
|
||||
private var imageId:ImageId;
|
||||
|
||||
public function new() {
|
||||
@@ -55,7 +56,7 @@ import ru.m.puzzlez.view.common.PresetView;
|
||||
|
||||
private function start(online:Bool = false):Void {
|
||||
if (online) {
|
||||
// network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state));
|
||||
network.createGame(imageView.state.preset).then(state -> switcher.change(GameFrame.ID, state));
|
||||
} else {
|
||||
switcher.change(GameFrame.ID, imageView.state);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ views:
|
||||
geometry.margin.left: 15
|
||||
text: Network
|
||||
+onPress: ~start(true)
|
||||
visible: false
|
||||
visible: true
|
||||
- id: image
|
||||
$type: ru.m.puzzlez.view.common.PresetView
|
||||
geometry.stretch: true
|
||||
|
||||
@@ -5,8 +5,8 @@ import ru.m.puzzlez.proto.pack.GameListResponse;
|
||||
import ru.m.puzzlez.proto.pack.GameListRequest;
|
||||
import hw.connect.session.ProtoSession;
|
||||
import hw.log.BaseLogger.LoggerUtil;
|
||||
import ru.m.puzzlez.image.Game;
|
||||
import ru.m.puzzlez.image.GameUtil;
|
||||
import ru.m.puzzlez.game.Game;
|
||||
import ru.m.puzzlez.game.GameUtil;
|
||||
import ru.m.puzzlez.proto.core.User;
|
||||
import ru.m.puzzlez.proto.event.GameAction;
|
||||
import ru.m.puzzlez.proto.event.GameEvent;
|
||||
|
||||
Reference in New Issue
Block a user