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

Unified Diff: sky/sdk/example/game/lib/image_map.dart

Issue 1227373004: Make Sky example game run offline (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
Index: sky/sdk/example/game/lib/image_map.dart
diff --git a/sky/sdk/example/game/lib/image_map.dart b/sky/sdk/example/game/lib/image_map.dart
index 7f0185c8fb0dc1ae9f7df7dc0cd7d3929f05cf97..407c29ffc6cb47df43fa35cb94b66e445075f424 100644
--- a/sky/sdk/example/game/lib/image_map.dart
+++ b/sky/sdk/example/game/lib/image_map.dart
@@ -1,37 +1,25 @@
-part of sprites;
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
-typedef void ImageMapCallback(ImageMap preloader);
+part of sprites;
class ImageMap {
+ ImageMap(AssetBundle bundle) : _bundle = bundle;
- Map<String, Image> _images;
-
- int _totalNumImages = 0;
- int _numLoadedImages = 0;
+ final AssetBundle _bundle;
+ final Map<String, Image> _images = new Map<String, Image>();
- ImageMapCallback _callback;
-
- ImageMap(List<String> urls, ImageMapCallback this._callback) {
- _images = new Map();
- _totalNumImages = urls.length;
- urls.forEach(_addURL);
+ Future<List<Image>> load(List<String> urls) {
+ return Future.wait(urls.map(_loadImage));
}
- void _addURL(String url) {
- image_cache.load(url).then((Image image) {
- // Store reference to image
- _images[url] = image;
-
- // Check if all images are loaded
- _numLoadedImages++;
- if (_numLoadedImages==_totalNumImages) {
- // Everything loaded, make callback
- _callback(this);
- }
- });
+ Future<Image> _loadImage(String url) async {
+ Image image = await _bundle.loadImage(url);
+ _images[url] = image;
+ return image;
}
Image getImage(String url) => _images[url];
-
Image operator [](String url) => _images[url];
}

Powered by Google App Engine
This is Rietveld 408576698