Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 part of sprites; | |
|
jackson
2015/06/23 22:09:43
check indentation here
| |
| 2 | |
| 3 class SpriteSheet { | |
| 4 | |
| 5 Image _image; | |
| 6 Map<String, Texture> _textures; | |
|
jackson
2015/06/23 21:56:54
You should be able to initialize this here.
| |
| 7 | |
| 8 SpriteSheet(this._image, String jsonDefinition) { | |
| 9 assert(_image != null); | |
| 10 assert(jsonDefinition != null); | |
| 11 | |
| 12 _textures = new Map(); | |
| 13 | |
| 14 JsonDecoder decoder = new JsonDecoder(); | |
| 15 Map file = decoder.convert(jsonDefinition); | |
| 16 assert(file != null); | |
| 17 | |
| 18 List frames = file["frames"]; | |
| 19 | |
| 20 for (Map frameInfo in frames) { | |
| 21 String fileName = frameInfo["filename"]; | |
| 22 Rect frame = _readJsonRect(frameInfo["frame"]); | |
| 23 bool rotated = frameInfo["rotated"]; | |
| 24 bool trimmed = frameInfo["trimmed"]; | |
| 25 Rect spriteSourceSize = _readJsonRect(frameInfo["spriteSourceSize"]); | |
| 26 Size sourceSize = _readJsonSize(frameInfo["sourceSize"]); | |
| 27 Point pivot = _readJsonPoint(frameInfo["pivot"]); | |
| 28 | |
| 29 var texture = new Texture._fromSpriteFrame(_image, fileName, sourceSize, r otated, trimmed, frame, | |
| 30 spriteSourceSize, pivot); | |
| 31 _textures[fileName] = texture; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 Rect _readJsonRect(Map data) { | |
| 36 num x = data["x"]; | |
| 37 num y = data["y"]; | |
| 38 num w = data["w"]; | |
| 39 num h = data["h"]; | |
| 40 | |
| 41 return new Rect.fromLTRB(x.toDouble(), y.toDouble(), (x + w).toDouble(), (y + h).toDouble()); | |
| 42 } | |
| 43 | |
| 44 Size _readJsonSize(Map data) { | |
| 45 num w = data["w"]; | |
| 46 num h = data["h"]; | |
| 47 | |
| 48 return new Size(w.toDouble(), h.toDouble()); | |
| 49 } | |
| 50 | |
| 51 Point _readJsonPoint(Map data) { | |
| 52 num x = data["x"]; | |
| 53 num y = data["y"]; | |
| 54 | |
| 55 return new Point(x.toDouble(), y.toDouble()); | |
| 56 } | |
| 57 | |
| 58 Image get image => _image; | |
| 59 | |
| 60 Texture operator [](String fileName) => _textures[fileName]; | |
| 61 } | |
| OLD | NEW |