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

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

Issue 786443002: Delete pop-pop-win from the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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/platform.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/game_storage.dart b/samples/pop_pop_win/lib/src/game_storage.dart
deleted file mode 100644
index 633e642a43496c714c065c27537b553fb7217d49..0000000000000000000000000000000000000000
--- a/samples/pop_pop_win/lib/src/game_storage.dart
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-library pop_pop_win.game_storage;
-
-import 'dart:async';
-
-import 'game.dart';
-import 'platform.dart';
-
-class GameStorage {
- static const _gameCountKey = 'gameCount';
- final StreamController _bestTimeUpdated = new StreamController();
- 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);
-
- 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) {
- 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/game_manager.dart ('k') | samples/pop_pop_win/lib/src/platform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698