flutter/examples/game/example_effect_line.dart
Hixie a0227cab15 flutter analyze command
Other changes in this patch:
- Make the 'flutter' tool say "Updating flutter tool..." when it calls
  pub get, to avoid confusion about what the pub get output is about.
- Make the bash flutter tool call pub get when the revision has
  changed. (This was already happening on Windows.)
- Fix a raft of bugs found by the analyzer.
- Fix some style nits in various bits of code that happened to be near
  things the analyzer noticed.
- Remove the logic in "flutter test" that would run "pub get", since
  upon further reflexion it was determined it didn't work anyway.
  We'll probably have to add better diagnostics here and say to run the
  updater script.
- Remove the native velocity tracker script, since it was testing code
  that has since been removed.

Notes on ignored warnings:
- We ignore warnings in any packages that are not in the Flutter repo or
  in the author's current directory.
- We ignore various irrelevant Strong Mode warnings. We still enable
  strong mode because even though it's not really relevant to our needs,
  it does (more or less accidentally) catch a few things that are
  helpful to us.
- We allow CONSTANTS_LIKE_THIS, since we get some of those from other
  platforms that we are copying for sanity and consistency.
- We allow one-member abstract classes since we have a number of them
  where it's perfectly reasonable.
- We unfortunately still ignore warnings in mojom.dart autogenerated
  files. We should really fix those but that's a separate patch.
- We verify the actual source file when we see the 'Name non-constant
  identifiers using lowerCamelCase.' lint, to allow one-letter variables
  that use capital letters (e.g. for physics expressions) and to allow
  multiple-underscore variable names.
- We ignore all errors on lines that contain the following magic
  incantation and a "#" character:
    // analyzer doesn't like constructor tear-offs
- For all remaining errors, if the line contains a comment of the form
    // analyzer says "..."
  ...then we ignore any errors that have that "..." string in them.
2015-11-12 12:23:29 -08:00

180 lines
4.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_sprites/flutter_sprites.dart';
AssetBundle _initBundle() {
if (rootBundle != null)
return rootBundle;
return new NetworkAssetBundle(Uri.base);
}
final AssetBundle _bundle = _initBundle();
ImageMap _images;
SpriteSheet _spriteSheet;
main() async {
_images = new ImageMap(_bundle);
await _images.load(<String>[
'assets/checker.png',
'assets/line_effects.png'
]);
assert(_images["assets/checker.png"] != null);
runApp(new TestApp());
}
class TestApp extends StatefulComponent {
TestAppState createState() => new TestAppState();
}
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.blue
);
class TestAppState extends State<TestApp> {
TestAppState() {
_testBed = new TestBed(_labelTexts[_selectedLine]);
}
TestBed _testBed;
int _selectedLine = 0;
List<String> _labelTexts = <String>[
"Colored",
"Smoke",
"Electric",
"Rocket Trail"
];
Widget build(BuildContext context) {
return new MaterialApp(
title: 'EffectLine Demo',
theme: _theme,
routes: <String, RouteBuilder>{
'/': _buildColumn
}
);
}
Column _buildColumn(RouteArguments args) {
return new Column(<Widget>[
new Flexible(child: _buildSpriteWidget()),
_buildTabBar()
]);
}
TabBar _buildTabBar() {
return new TabBar(
labels: _buildTabLabels(),
selectedIndex: _selectedLine,
onChanged: (int selectedLine) {
setState(() {
_selectedLine = selectedLine;
});
}
);
}
List<TabLabel> _buildTabLabels() {
List<TabLabel> labels = <TabLabel>[];
for (String text in _labelTexts)
labels.add(new TabLabel(text: text));
return labels;
}
SpriteWidget _buildSpriteWidget() {
_testBed.setupLine(_labelTexts[_selectedLine]);
return new SpriteWidget(
_testBed,
SpriteBoxTransformMode.letterbox
);
}
}
class TestBed extends NodeWithSize {
EffectLine _line;
TestBed(String lineType) : super(new Size(1024.0, 1024.0)) {
userInteractionEnabled = true;
setupLine(lineType);
}
void setupLine(String lineType) {
if (_line != null) {
_line.removeFromParent();
}
if (lineType == "Colored") {
// Create a line with no texture and a color sequence
_line = new EffectLine(
texture: null,
colorSequence: new ColorSequence.fromStartAndEndColor(new Color(0xaaffff00), new Color(0xaaff9900)),
widthMode: EffectLineWidthMode.barrel,
minWidth: 10.0,
maxWidth: 15.0,
fadeAfterDelay: 1.0,
fadeDuration: 1.0
);
} else if (lineType == "Smoke") {
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
Texture smokyLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 0.0, 1024.0, 128.0));
_line = new EffectLine(
texture: smokyLineTexture,
textureLoopLength: 300.0,
colorSequence: new ColorSequence.fromStartAndEndColor(new Color(0xffffffff), new Color(0x00ffffff)),
widthMode: EffectLineWidthMode.barrel,
minWidth: 20.0,
maxWidth: 80.0,
animationMode: EffectLineAnimationMode.scroll
);
} else if (lineType == "Electric") {
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
Texture electricLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 384.0, 1024.0, 512.0));
_line = new EffectLine(
texture: electricLineTexture,
textureLoopLength: 300.0,
widthMode: EffectLineWidthMode.barrel,
minWidth: 20.0,
maxWidth: 100.0,
animationMode: EffectLineAnimationMode.random
);
} else if (lineType == "Rocket Trail") {
Texture baseTexture = new Texture(_images['assets/line_effects.png']);
Texture trailLineTexture = baseTexture.textureFromRect(new Rect.fromLTRB(0.0, 896.0, 1024.0, 1024.0));
_line = new EffectLine(
texture: trailLineTexture,
textureLoopLength: 300.0,
widthMode: EffectLineWidthMode.barrel,
minWidth: 20.0,
maxWidth: 40.0,
widthGrowthSpeed: 40.0,
fadeAfterDelay: 0.5,
fadeDuration: 1.5
);
}
addChild(_line);
}
bool handleEvent(SpriteBoxEvent event) {
if (event.type == "pointerdown")
_line.points = <Point>[];
if (event.type == "pointerdown" || event.type == "pointermove") {
Point pos = convertPointToNodeSpace(event.boxPosition);
_line.addPoint(pos);
}
return true;
}
}