Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Unified Diff: samples/pop_pop_win/lib/src/game_storage.dart

Issue 242443008: samples/pop_pop_win: now based on StageXL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tiny nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/pop_pop_win/lib/src/game_manager.dart ('k') | samples/pop_pop_win/lib/src/html.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/pop_pop_win/lib/src/game_storage.dart
diff --git a/samples/pop_pop_win/lib/src/html/game_storage.dart b/samples/pop_pop_win/lib/src/game_storage.dart
similarity index 61%
rename from samples/pop_pop_win/lib/src/html/game_storage.dart
rename to samples/pop_pop_win/lib/src/game_storage.dart
index 5f4ca8ea23d43bd6e5a8f9ae2546ac04748870c1..bbc8a7b090e77ff70607c4936fc42d1eb3f9164e 100644
--- a/samples/pop_pop_win/lib/src/html/game_storage.dart
+++ b/samples/pop_pop_win/lib/src/game_storage.dart
@@ -1,8 +1,13 @@
-part of pop_pop_win.html;
+library pop_pop_win.game_storage;
+
+import 'dart:async';
+
+import 'game.dart';
+import 'platform.dart';
class GameStorage {
static const _gameCountKey = 'gameCount';
- final EventHandle _bestTimeUpdated = new EventHandle();
+ final StreamController _bestTimeUpdated = new StreamController();
final Map<String, String> _cache = new Map<String, String>();
Future<int> get gameCount => _getIntValue(_gameCountKey);
@@ -18,23 +23,22 @@ class GameStorage {
assert(game != null);
assert(game.state == GameState.won);
- final w = game.field.width;
- final h = game.field.height;
- final m = game.field.bombCount;
- final duration = game.duration.inMilliseconds;
-
- final key = _getKey(w, h, m);
-
- return _getIntValue(key, null)
- .then((int currentScore) {
- if(currentScore == null || currentScore > duration) {
- _setIntValue(key, duration);
- _bestTimeUpdated.add(null);
- return true;
- } else {
- return false;
- }
- });
+ var w = game.field.width;
+ var h = game.field.height;
+ var m = game.field.bombCount;
+ var duration = game.duration.inMilliseconds;
+
+ var key = _getKey(w, h, m);
+
+ return _getIntValue(key, null).then((int currentScore) {
+ if (currentScore == null || currentScore > duration) {
+ _setIntValue(key, duration);
+ _bestTimeUpdated.add(null);
+ return true;
+ } else {
+ return false;
+ }
+ });
}
Future<int> getBestTimeMilliseconds(int width, int height, int bombCount) {
@@ -53,11 +57,10 @@ class GameStorage {
return new Future.value(_parseValue(_cache[key], defaultValue));
}
- return targetPlatform.getValue(key)
- .then((String strValue) {
- _cache[key] = strValue;
- return _parseValue(strValue, defaultValue);
- });
+ return targetPlatform.getValue(key).then((String strValue) {
+ _cache[key] = strValue;
+ return _parseValue(strValue, defaultValue);
+ });
}
Future _setIntValue(String key, int value) {
@@ -68,20 +71,18 @@ class GameStorage {
}
Future _incrementIntValue(String key) {
- return _getIntValue(key)
- .then((int val) {
- return _setIntValue(key, val + 1);
- });
+ return _getIntValue(key).then((int val) {
+ return _setIntValue(key, val + 1);
+ });
}
static String _getKey(int w, int h, int m) => "w$w-h$h-m$m";
static int _parseValue(String value, int defaultValue) {
- if(value == null) {
+ if (value == null) {
return defaultValue;
} else {
return int.parse(value);
}
}
-
}
« no previous file with comments | « samples/pop_pop_win/lib/src/game_manager.dart ('k') | samples/pop_pop_win/lib/src/html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698