Skip to content

Commit 8e28310

Browse files
committed
Using async/await, require Dart 1.9, use latest StageXL
1 parent 33c4fe5 commit 8e28310

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

lib/platform_target.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ class _DefaultPlatform extends PlatformTarget {
4242
_DefaultPlatform() : super.base();
4343

4444
@override
45-
Future clearValues() => new Future(_values.clear);
45+
Future clearValues() async => _values.clear();
4646

4747
@override
48-
Future setValue(String key, String value) => new Future(() {
49-
_values[key] = value;
50-
});
48+
Future setValue(String key, String value) async => _values[key] = value;
5149

5250
@override
53-
Future<String> getValue(String key) => new Future(() => _values[key]);
51+
Future<String> getValue(String key) async => _values[key];
5452

5553
int get size => 7;
5654

lib/pop_pop_win.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'src/stage.dart';
1515

1616
const String _ASSET_DIR = 'packages/pop_pop_win/assets';
1717

18-
Future startGame(PlatformTarget platform) {
18+
Future startGame(PlatformTarget platform) async {
1919
initPlatform(platform);
2020

2121
var stage = new Stage(querySelector('#gameCanvas'),
@@ -30,7 +30,8 @@ Future startGame(PlatformTarget platform) {
3030
..addTextureAtlas(
3131
"static", '$_ASSET_DIR/images/static.json', TextureAtlasFormat.JSON);
3232

33-
return resourceManager.load().then((resMan) => _initialLoad(resMan, stage));
33+
var resMan = await resourceManager.load();
34+
_initialLoad(resMan, stage);
3435
}
3536

3637
void _initialLoad(ResourceManager resourceManager, Stage stage) {

lib/src/game_storage.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,15 @@ class GameStorage {
5454
return targetPlatform.clearValues();
5555
}
5656

57-
Future<int> _getIntValue(String key, [int defaultValue = 0]) {
57+
Future<int> _getIntValue(String key, [int defaultValue = 0]) async {
5858
assert(key != null);
5959
if (_cache.containsKey(key)) {
6060
return new Future.value(_parseValue(_cache[key], defaultValue));
6161
}
6262

63-
return targetPlatform.getValue(key).then((String strValue) {
64-
_cache[key] = strValue;
65-
return _parseValue(strValue, defaultValue);
66-
});
63+
var strValue = await targetPlatform.getValue(key);
64+
_cache[key] = strValue;
65+
return _parseValue(strValue, defaultValue);
6766
}
6867

6968
Future _setIntValue(String key, int value) {
@@ -73,10 +72,9 @@ class GameStorage {
7372
return targetPlatform.setValue(key, val);
7473
}
7574

76-
Future _incrementIntValue(String key) {
77-
return _getIntValue(key).then((int val) {
78-
return _setIntValue(key, val + 1);
79-
});
75+
Future _incrementIntValue(String key) async {
76+
var val = await _getIntValue(key);
77+
return _setIntValue(key, val + 1);
8078
}
8179

8280
static String _getKey(int w, int h, int m) => "w$w-h$h-m$m";

pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ author: Dart Team <misc@dartlang.org>
33
description: '"Pop, Pop, Win!" is an implementation of Minesweeper in Dart.'
44
homepage: https://github.com/dart-lang/sample-pop_pop_win
55
environment:
6-
sdk: '>=1.3.0 <2.0.0'
6+
sdk: '>=1.9.0 <2.0.0'
77
dependencies:
8-
bot: '>=0.26.0 <0.29.0'
9-
browser: '>=0.10.0 <0.11.0'
10-
chrome: '>=0.6.3 <0.7.0'
11-
stagexl: '>=0.9.1 <0.11.0'
8+
bot: '^0.28.0'
9+
browser: '^0.10.0'
10+
chrome: '^0.6.3'
11+
stagexl: '^0.11.0'
1212
dev_dependencies:
13-
unittest: '>=0.10.0 <0.12.0'
13+
unittest: '^0.11.0'

web/platform_web.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@ class PlatformWeb extends PlatformTarget {
1818
}
1919

2020
@override
21-
Future clearValues() {
22-
window.localStorage.clear();
23-
return new Future.value();
24-
}
21+
Future clearValues() async => window.localStorage.clear();
2522

2623
@override
27-
Future setValue(String key, String value) {
28-
window.localStorage[key] = value;
29-
return new Future.value();
30-
}
24+
Future setValue(String key, String value) async =>
25+
window.localStorage[key] = value;
3126

3227
@override
33-
Future<String> getValue(String key) =>
34-
new Future.value(window.localStorage[key]);
28+
Future<String> getValue(String key) async => window.localStorage[key];
3529

3630
int get size {
3731
_sizeAccessed = true;

0 commit comments

Comments
 (0)