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

Unified Diff: samples/pop_pop_win/lib/src/html/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/html/game_manager.dart ('k') | samples/pop_pop_win/lib/src/html/game_view.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/html/game_storage.dart
diff --git a/samples/pop_pop_win/lib/src/html/game_storage.dart b/samples/pop_pop_win/lib/src/html/game_storage.dart
deleted file mode 100644
index 5f4ca8ea23d43bd6e5a8f9ae2546ac04748870c1..0000000000000000000000000000000000000000
--- a/samples/pop_pop_win/lib/src/html/game_storage.dart
+++ /dev/null
@@ -1,87 +0,0 @@
-part of pop_pop_win.html;
-
-class GameStorage {
- static const _gameCountKey = 'gameCount';
- final EventHandle _bestTimeUpdated = new EventHandle();
- final Map<String, String> _cache = new Map<String, String>();
-
- Future<int> get gameCount => _getIntValue(_gameCountKey);
-
- Stream get bestTimeUpdated => _bestTimeUpdated.stream;
-
- void recordState(GameState state) {
- assert(state != null);
- _incrementIntValue(state.name);
- }
-
- Future<bool> updateBestTime(Game game) {
- 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;
- }
- });
- }
-
- Future<int> getBestTimeMilliseconds(int width, int height, int bombCount) {
- final key = _getKey(width, height, bombCount);
- return _getIntValue(key, null);
- }
-
- Future reset() {
- _cache.clear();
- return targetPlatform.clearValues();
- }
-
- Future<int> _getIntValue(String key, [int defaultValue = 0]) {
- assert(key != null);
- if (_cache.containsKey(key)) {
- return new Future.value(_parseValue(_cache[key], defaultValue));
- }
-
- return targetPlatform.getValue(key)
- .then((String strValue) {
- _cache[key] = strValue;
- return _parseValue(strValue, defaultValue);
- });
- }
-
- Future _setIntValue(String key, int value) {
- assert(key != null);
- _cache.remove(key);
- String val = (value == null) ? null : value.toString();
- return targetPlatform.setValue(key, val);
- }
-
- Future _incrementIntValue(String key) {
- 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) {
- return defaultValue;
- } else {
- return int.parse(value);
- }
- }
-
-}
« no previous file with comments | « samples/pop_pop_win/lib/src/html/game_manager.dart ('k') | samples/pop_pop_win/lib/src/html/game_view.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698