Commit 5477d46f authored by Adam Barth's avatar Adam Barth

Port SkySprites and clients to fn3

parent 8a46b15b
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
import 'package:skysprites/skysprites.dart'; import 'package:skysprites/skysprites.dart';
AssetBundle _initBundle() { AssetBundle _initBundle() {
...@@ -14,7 +14,6 @@ final AssetBundle _bundle = _initBundle(); ...@@ -14,7 +14,6 @@ final AssetBundle _bundle = _initBundle();
ImageMap _images; ImageMap _images;
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
TestApp _app;
main() async { main() async {
_images = new ImageMap(_bundle); _images = new ImageMap(_bundle);
...@@ -26,12 +25,19 @@ main() async { ...@@ -26,12 +25,19 @@ main() async {
assert(_images["assets/checker.png"] != null); assert(_images["assets/checker.png"] != null);
_app = new TestApp(); runApp(new TestApp());
runApp(_app);
} }
class TestApp extends App { class TestApp extends StatefulComponent {
TestAppState createState() => new TestAppState();
}
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue
);
class TestAppState extends State<TestApp> {
TestApp() { TestApp() {
_testBed = new TestBed(_labelTexts[_selectedLine]); _testBed = new TestBed(_labelTexts[_selectedLine]);
} }
...@@ -46,22 +52,17 @@ class TestApp extends App { ...@@ -46,22 +52,17 @@ class TestApp extends App {
"Rocket Trail" "Rocket Trail"
]; ];
Widget build() { Widget build(BuildContext context) {
ThemeData theme = new ThemeData( return new App(
brightness: ThemeBrightness.light, title: 'EffectLine Demo',
primarySwatch: Colors.blue theme: _theme,
); routes: {
'/': _buildColumn
return new Theme( }
data: theme,
child: new Title(
title: 'EffectLine Demo',
child: _buildColumn()
)
); );
} }
Column _buildColumn() { Column _buildColumn(NavigatorState navigator, Route route) {
return new Column([ return new Column([
new Flexible(child: _buildSpriteWidget()), new Flexible(child: _buildSpriteWidget()),
_buildTabBar() _buildTabBar()
......
...@@ -8,7 +8,7 @@ import 'package:sky/material.dart'; ...@@ -8,7 +8,7 @@ import 'package:sky/material.dart';
import 'package:sky/painting.dart'; import 'package:sky/painting.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
import 'package:skysprites/skysprites.dart'; import 'package:skysprites/skysprites.dart';
import 'game_demo.dart'; import 'game_demo.dart';
...@@ -24,7 +24,6 @@ final AssetBundle _bundle = _initBundle(); ...@@ -24,7 +24,6 @@ final AssetBundle _bundle = _initBundle();
ImageMap _imageMap; ImageMap _imageMap;
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
SpriteSheet _spriteSheetUI; SpriteSheet _spriteSheetUI;
GameDemoApp _app;
Map<String,SoundEffect> _sounds = {}; Map<String,SoundEffect> _sounds = {};
main() async { main() async {
...@@ -58,55 +57,42 @@ main() async { ...@@ -58,55 +57,42 @@ main() async {
json = await _bundle.loadString('assets/game_ui.json'); json = await _bundle.loadString('assets/game_ui.json');
_spriteSheetUI = new SpriteSheet(_imageMap['assets/game_ui.png'], json); _spriteSheetUI = new SpriteSheet(_imageMap['assets/game_ui.png'], json);
_app = new GameDemoApp();
assert(_spriteSheet.image != null); assert(_spriteSheet.image != null);
SoundTrackPlayer stPlayer = SoundTrackPlayer.sharedInstance(); SoundTrackPlayer stPlayer = SoundTrackPlayer.sharedInstance();
SoundTrack music = await stPlayer.load(_bundle.load('assets/temp_music.aac')); SoundTrack music = await stPlayer.load(_bundle.load('assets/temp_music.aac'));
stPlayer.play(music); stPlayer.play(music);
runApp(_app); runApp(new GameDemo());
} }
class GameDemoApp extends App { // TODO(viktork): The task bar purple is the wrong purple, we may need
// a custom theme swatch to match the purples in the sprites.
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
class GameDemo extends StatefulComponent {
GameDemoState createState() => new GameDemoState();
}
NavigationState _navigationState; class GameDemoState extends State<GameDemo> {
NodeWithSize _game; NodeWithSize _game;
int _lastScore = 0; int _lastScore = 0;
void initState() { Widget build(BuildContext context) {
_navigationState = new NavigationState([ return new App(
new Route( title: 'Asteroids',
name: '/', theme: _theme,
builder: _buildMainScene routes: {
), '/': _buildMainScene,
new Route( '/game': _buildGameScene
name: '/game', }
builder: _buildGameScene
),
]);
super.initState();
}
Widget build() {
// TODO(viktork): The task bar purple is the wrong purple, we may need
// a custom theme swatch to match the purples in the sprites.
ThemeData theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
return new Theme(
data: theme,
child: new Title(
title: 'Asteroids',
child: new Navigator(_navigationState)
)
); );
} }
Widget _buildGameScene(navigator, route) { Widget _buildGameScene(NavigatorState navigator, Route route) {
return new SpriteWidget(_game, SpriteBoxTransformMode.fixedWidth); return new SpriteWidget(_game, SpriteBoxTransformMode.fixedWidth);
} }
...@@ -144,7 +130,7 @@ class GameDemoApp extends App { ...@@ -144,7 +130,7 @@ class GameDemoApp extends App {
} }
} }
class TextureButton extends ButtonBase { class TextureButton extends StatefulComponent {
TextureButton({ TextureButton({
Key key, Key key,
this.onPressed, this.onPressed,
...@@ -160,41 +146,46 @@ class TextureButton extends ButtonBase { ...@@ -160,41 +146,46 @@ class TextureButton extends ButtonBase {
final double width; final double width;
final double height; final double height;
Widget buildContent() { TextureButtonState createState() => new TextureButtonState();
}
class TextureButtonState extends ButtonState<TextureButton> {
Widget buildContent(BuildContext context) {
return new Listener( return new Listener(
child: new Container( child: new Container(
width: width, width: config.width,
height: height, height: config.height,
child: new CustomPaint( child: new CustomPaint(
callback: paintCallback, callback: paintCallback,
token: new _TextureButtonToken( token: new _TextureButtonToken(
highlight, highlight,
texture, config.texture,
textureDown, config.textureDown,
width, config.width,
height config.height
) )
) )
), ),
onPointerUp: (_) { onPointerUp: (_) {
if (onPressed != null) onPressed(); if (config.onPressed != null)
config.onPressed();
} }
); );
} }
void paintCallback(PaintingCanvas canvas, Size size) { void paintCallback(PaintingCanvas canvas, Size size) {
if (texture == null) if (config.texture == null)
return; return;
canvas.save(); canvas.save();
if (highlight && textureDown != null) { if (highlight && config.textureDown != null) {
// Draw down state // Draw down state
canvas.scale(size.width / textureDown.size.width, size.height / textureDown.size.height); canvas.scale(size.width / config.textureDown.size.width, size.height / config.textureDown.size.height);
textureDown.drawTexture(canvas, Point.origin, new Paint()); config.textureDown.drawTexture(canvas, Point.origin, new Paint());
} else { } else {
// Draw up state // Draw up state
canvas.scale(size.width / texture.size.width, size.height / texture.size.height); canvas.scale(size.width / config.texture.size.width, size.height / config.texture.size.height);
texture.drawTexture(canvas, Point.origin, new Paint()); config.texture.drawTexture(canvas, Point.origin, new Paint());
} }
canvas.restore(); canvas.restore();
} }
......
...@@ -3,7 +3,7 @@ import 'dart:sky'; ...@@ -3,7 +3,7 @@ import 'dart:sky';
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
import 'package:skysprites/skysprites.dart'; import 'package:skysprites/skysprites.dart';
AssetBundle _initBundle() { AssetBundle _initBundle() {
...@@ -16,7 +16,11 @@ final AssetBundle _bundle = _initBundle(); ...@@ -16,7 +16,11 @@ final AssetBundle _bundle = _initBundle();
ImageMap _images; ImageMap _images;
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
TestDrawAtlasApp _app;
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
main() async { main() async {
_images = new ImageMap(_bundle); _images = new ImageMap(_bundle);
...@@ -28,29 +32,18 @@ main() async { ...@@ -28,29 +32,18 @@ main() async {
String json = await _bundle.loadString('assets/sprites.json'); String json = await _bundle.loadString('assets/sprites.json');
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json); _spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
_app = new TestDrawAtlasApp(); runApp(new App(
runApp(_app); title: 'Test drawAtlas',
} theme: _theme,
routes: {
class TestDrawAtlasApp extends App { '/': (NavigatorState navigator, Route route) {
return new SpriteWidget(
Widget build() {
ThemeData theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
return new Theme(
data: theme,
child: new Title(
title: 'Test drawAtlas',
child: new SpriteWidget(
new TestDrawAtlas(), new TestDrawAtlas(),
SpriteBoxTransformMode.fixedWidth SpriteBoxTransformMode.fixedWidth
) );
) }
); }
} ));
} }
class TestDrawAtlas extends NodeWithSize { class TestDrawAtlas extends NodeWithSize {
......
...@@ -4,7 +4,7 @@ import 'dart:math' as math; ...@@ -4,7 +4,7 @@ import 'dart:math' as math;
import 'package:sky/material.dart'; import 'package:sky/material.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
import 'package:skysprites/skysprites.dart'; import 'package:skysprites/skysprites.dart';
AssetBundle _initBundle() { AssetBundle _initBundle() {
...@@ -17,7 +17,11 @@ final AssetBundle _bundle = _initBundle(); ...@@ -17,7 +17,11 @@ final AssetBundle _bundle = _initBundle();
ImageMap _images; ImageMap _images;
SpriteSheet _spriteSheet; SpriteSheet _spriteSheet;
TestApp _app;
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
main() async { main() async {
_images = new ImageMap(_bundle); _images = new ImageMap(_bundle);
...@@ -29,26 +33,15 @@ main() async { ...@@ -29,26 +33,15 @@ main() async {
String json = await _bundle.loadString('assets/sprites.json'); String json = await _bundle.loadString('assets/sprites.json');
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json); _spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
_app = new TestApp(); runApp(new App(
runApp(_app); title: 'Test Sprite Performance',
} theme: _theme,
routes: {
class TestApp extends App { '/': (NavigatorState navigator, RouteState route) {
return new SpriteWidget(new TestPerformance());
Widget build() { }
ThemeData theme = new ThemeData( }
brightness: ThemeBrightness.light, ));
primarySwatch: Colors.purple
);
return new Theme(
data: theme,
child: new Title(
title: 'Test Sprite Performance',
child: new SpriteWidget(new TestPerformance())
)
);
}
} }
class TestPerformance extends NodeWithSize { class TestPerformance extends NodeWithSize {
......
...@@ -16,7 +16,7 @@ import 'package:sky/animation.dart'; ...@@ -16,7 +16,7 @@ import 'package:sky/animation.dart';
import 'package:sky/painting.dart'; import 'package:sky/painting.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
import 'package:sky/services.dart'; import 'package:sky/services.dart';
import 'package:sky/widgets.dart'; import 'package:sky/widgets_next.dart';
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
part 'action.dart'; part 'action.dart';
......
part of skysprites; part of skysprites;
/// A widget that uses a [SpriteBox] to render a sprite node tree to the screen. /// A widget that uses a [SpriteBox] to render a sprite node tree to the screen.
class SpriteWidget extends OneChildRenderObjectWrapper { class SpriteWidget extends OneChildRenderObjectWidget {
/// The rootNode of the sprite node tree. /// The rootNode of the sprite node tree.
/// ///
...@@ -24,13 +24,9 @@ class SpriteWidget extends OneChildRenderObjectWrapper { ...@@ -24,13 +24,9 @@ class SpriteWidget extends OneChildRenderObjectWrapper {
/// var mySpriteWidget = new SpriteWidget(mySpriteTree, SpriteBoxTransformMode.fixedHeight); /// var mySpriteWidget = new SpriteWidget(mySpriteTree, SpriteBoxTransformMode.fixedHeight);
SpriteWidget(this.rootNode, [this.transformMode = SpriteBoxTransformMode.letterbox]); SpriteWidget(this.rootNode, [this.transformMode = SpriteBoxTransformMode.letterbox]);
SpriteBox get renderObject => super.renderObject; SpriteBox createRenderObject() => new SpriteBox(rootNode, transformMode);
SpriteBox createNode() => new SpriteBox(rootNode, transformMode);
void syncRenderObject(SpriteWidget old) {
super.syncRenderObject(old);
void updateRenderObject(SpriteBox renderObject, SpriteWidget oldWidget) {
renderObject.rootNode = rootNode; renderObject.rootNode = rootNode;
renderObject.transformMode = transformMode; renderObject.transformMode = transformMode;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment