croupier: Add Hard Restart
This is a similar strategy to the Go one, but it relies more on the
data already present in Syncbase.
Confirmed using Solitaire that this will survive hard restarts (and
full hard restarts)
Also slipped in a change that makes Go's clean better.
Change-Id: I852edc905a1b2bd8857ca788bdd661a8bd8b58c4
diff --git a/go/Makefile b/go/Makefile
index b40eb73..b498a4e 100644
--- a/go/Makefile
+++ b/go/Makefile
@@ -72,7 +72,7 @@
rm -rf bin
rm -rf credentials
rm -rf pkg
- rm -rf src/golang.org/x/mobile/cmd/gomobile
+ rm -rf src/golang.org/x/mobile
rm -rf tmp/syncbase
all: bin/hearts
diff --git a/lib/components/croupier.dart b/lib/components/croupier.dart
index 89d146d..61b73b4 100644
--- a/lib/components/croupier.dart
+++ b/lib/components/croupier.dart
@@ -52,10 +52,10 @@
logic_croupier.CroupierState.JoinGame)),
new FlatButton(
child: new Text('Resume Game', style: style.Text.titleStyle),
- onPressed: config.croupier.mostRecentGameID != null
+ onPressed: config.croupier.settings.hasLastGame
? makeSetStateCallback(
logic_croupier.CroupierState.ResumeGame,
- config.croupier.mostRecentGameID)
+ config.croupier.settings.lastGameID)
: null),
new CroupierProfileComponent(
settings: config.croupier.settings,
diff --git a/lib/logic/croupier.dart b/lib/logic/croupier.dart
index c4fcf5b..146d5d3 100644
--- a/lib/logic/croupier.dart
+++ b/lib/logic/croupier.dart
@@ -33,7 +33,6 @@
Map<String, GameStartData> games_found; // empty, but loads asynchronously
Map<int, int> players_found; // empty, but loads asynchronously
Game game; // null until chosen
- int mostRecentGameID; // null until a game was started.
NoArgCb informUICb;
// Futures to use in order to cancel scans and advertisements.
@@ -93,7 +92,8 @@
void _setCurrentGame(Game g) {
game = g;
- mostRecentGameID = game.gameID;
+ settings.lastGameID = g.gameID;
+ settings_manager.save(settings.userID, settings.toJSONString()); // async
}
Game _createNewGame(GameType gt) {
diff --git a/lib/logic/croupier_settings.dart b/lib/logic/croupier_settings.dart
index 69823a4..0522fed 100644
--- a/lib/logic/croupier_settings.dart
+++ b/lib/logic/croupier_settings.dart
@@ -8,7 +8,12 @@
/// CroupierSettings is a simple struct that contains player-specific settings.
/// Players can modify a subset of their settings via the UI.
class CroupierSettings {
- int userID; // This is a value the user cannot set on their own.
+ // Values the user does not set.
+ int userID;
+ int lastGameID; // Note: Some versions of Croupier do not support lastGameID.
+ bool get hasLastGame => lastGameID != null;
+
+ // Values the user can customize
String avatar;
String name;
int color;
@@ -20,7 +25,6 @@
}
CroupierSettings.placeholder() {
- userID = 0;
avatar = "Heart.png";
name = "Loading...";
color = 0xcfcccccc;
@@ -29,6 +33,7 @@
CroupierSettings.fromJSONString(String json) {
var data = JSON.decode(json);
userID = data["userID"];
+ lastGameID = data["lastGameID"];
avatar = data["avatar"];
name = data["name"];
color = data["color"];
@@ -77,8 +82,13 @@
}
String toJSONString() {
- return JSON.encode(
- {"userID": userID, "avatar": avatar, "name": name, "color": color});
+ return JSON.encode({
+ "userID": userID,
+ "lastGameID": lastGameID,
+ "avatar": avatar,
+ "name": name,
+ "color": color
+ });
}
void _randomInitialization() {
diff --git a/pubspec.lock b/pubspec.lock
index eda60cd..25a0d88 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -238,7 +238,7 @@
syncbase:
description: syncbase
source: hosted
- version: "0.0.23"
+ version: "0.0.26"
test:
description: test
source: hosted
@@ -254,7 +254,7 @@
v23discovery:
description: v23discovery
source: hosted
- version: "0.0.7"
+ version: "0.0.8"
vector_math:
description: vector_math
source: hosted