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