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); |
} |
} |
- |
} |