Skip to content

Commit

Permalink
Merge pull request #215 from kevmoo/tweaks
Browse files Browse the repository at this point in the history
Tweaks
  • Loading branch information
bp74 committed Sep 19, 2015
2 parents feb60ea + e96bc37 commit 37a4ec9
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
.packages
.pub/
build/
packages/
packages
pubspec.lock
7 changes: 3 additions & 4 deletions lib/src/display/bitmap_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BitmapData implements BitmapDrawable {

/// Loads a BitmapData from the given url.
static Future<BitmapData> load(String url, [BitmapDataLoadOptions bitmapDataLoadOptions]) {
static Future<BitmapData> load(String url, [BitmapDataLoadOptions bitmapDataLoadOptions]) async {

if (bitmapDataLoadOptions == null) {
bitmapDataLoadOptions = BitmapData.defaultLoadOptions;
Expand All @@ -83,9 +83,8 @@ class BitmapData implements BitmapDrawable {
}

var imageLoader = new ImageLoader(url, webpAvailable, corsEnabled);
return imageLoader.done.then((image) {
return new BitmapData.fromImageElement(image, pixelRatio);
});
var image = await imageLoader.done;
return new BitmapData.fromImageElement(image, pixelRatio);
}

//----------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions lib/src/display/display_object_children.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class DisplayObjectChildren implements Iterable<DisplayObject> {
return _children.any(test);
}

bool contains(DisplayObject element) {
return _children.contains(element);
}
bool contains(Object element) => _children.contains(element);

DisplayObject elementAt(int index) {
return _children[index];
Expand Down
4 changes: 2 additions & 2 deletions lib/src/display/stage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ class Stage extends DisplayObjectContainer {
int button = event.button;

InteractiveObject target = null;
Point stagePoint = _clientTransformation.transformPoint(event.client);
Point localPoint = new Point<num>(0.0, 0.0);
var stagePoint = _clientTransformation.transformPoint(event.client);
var localPoint = new Point<num>(0.0, 0.0);

if (button < 0 || button > 2) return;
if (event.type == "mousemove" && _mousePosition == stagePoint) return;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/display_ex/canvas_shadow_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class CanvasShadowWrapper extends DisplayObject {
var renderContext = renderState.renderContext;
if (renderContext is RenderContextCanvas) {

RenderContextCanvas renderContextCanvas = renderContext as RenderContextCanvas;
CanvasRenderingContext2D rawContext = renderContextCanvas.rawContext;
CanvasRenderingContext2D rawContext = renderContext.rawContext;
Matrix shadowMatrix = renderState.globalMatrix;

rawContext.save();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/events/event_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ part of stagexl.events;
class EventDispatcher {

Map<String, EventStream> _eventStreams;
Map<String, EventStream<Event>> _eventStreams;

//----------------------------------------------------------------------------

Expand All @@ -45,7 +45,7 @@ class EventDispatcher {

var eventStreams = _eventStreams;
if (eventStreams == null) {
eventStreams = new Map<String, EventStream>();
eventStreams = new Map<String, EventStream<Event>>();
_eventStreams = eventStreams;
}

Expand Down
29 changes: 17 additions & 12 deletions lib/src/events/event_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class EventStream<T extends Event> extends Stream<T> {
bool get isBroadcast => true;

@override
Stream<T> asBroadcastStream({
void onListen(StreamSubscription subscription),
void onCancel(StreamSubscription subscription)}) => this;
Stream<T> asBroadcastStream(
{void onListen(StreamSubscription<T> subscription),
void onCancel(StreamSubscription<T> subscription)}) => this;

bool get hasSubscriptions => _subscriptions.length > 0;
bool get hasCapturingSubscriptions => _capturingSubscriptionCount > 0;
Expand All @@ -53,9 +53,11 @@ class EventStream<T extends Event> extends Stream<T> {
/// as the stream has no errors and is never done.
@override
EventStreamSubscription<T> listen(void onData(T event), {
void onError(error), void onDone(),
bool cancelOnError: false, int priority: 0 }) {
EventStreamSubscription<T> listen(void onData(T event),
{Function onError,
void onDone(),
bool cancelOnError: false,
int priority: 0}) {

return _subscribe(onData, false, priority);
}
Expand Down Expand Up @@ -98,15 +100,15 @@ class EventStream<T extends Event> extends Stream<T> {
//----------------------------------------------------------------------------

EventStreamSubscription<T> _subscribe(
EventListener eventListener, bool captures, int priority) {

var subscription = new EventStreamSubscription<T>._(this,
eventListener, captures, priority);
EventListener<T> eventListener, bool captures, int priority) {
var subscription = new EventStreamSubscription<T>._(
this, eventListener, captures, priority);

// Insert the new subscription according to its priority.

var oldSubscriptions = _subscriptions;
var newSubscriptions = new List(oldSubscriptions.length + 1);
var newSubscriptions =
new List<EventStreamSubscription>(oldSubscriptions.length + 1);
var index = newSubscriptions.length - 1;

for(int o = 0, n = 0; o < oldSubscriptions.length; o++) {
Expand Down Expand Up @@ -157,7 +159,8 @@ class EventStream<T extends Event> extends Stream<T> {
var oldSubscriptions = _subscriptions;
if (oldSubscriptions.length == 0) return;

var newSubscriptions = new List(oldSubscriptions.length - 1);
var newSubscriptions =
new List<EventStreamSubscription>(oldSubscriptions.length - 1);

for(int o = 0, n = 0; o < oldSubscriptions.length; o++) {
var oldSubscription = oldSubscriptions[o];
Expand All @@ -179,6 +182,8 @@ class EventStream<T extends Event> extends Stream<T> {

var subscriptions = _subscriptions;
var isCapturing = eventPhase == EventPhase.CAPTURING_PHASE;
// dartanalyzer --strong known issues
// https://github.com/dart-lang/dev_compiler/issues/327
var inputEvent = event is InputEvent ? event : null;

for(var i = 0; i < subscriptions.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/events/event_stream_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EventStreamSubscription<T extends Event> extends StreamSubscription<T> {
}

@override
void onError(void handleError(error)) {
void onError(Function handleError) {
// This stream has no errors.
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/filters/displacement_map_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ class DisplacementMapFilterProgram extends BitmapFilterProgram {
disMatrix.copyFrom(renderTextureQuad.samplerMatrix);
disMatrix.scale(displacementMapFilter.scaleX, displacementMapFilter.scaleY);

var uMapMatrix = new Float32List.fromList([
var uMapMatrix = new Float32List.fromList(<double>[
mapMatrix.a, mapMatrix.c, mapMatrix.tx,
mapMatrix.b, mapMatrix.d, mapMatrix.ty,
0.0, 0.0, 1.0]);

var uDisMatrix = new Float32List.fromList([
var uDisMatrix = new Float32List.fromList(<double>[
disMatrix.a, disMatrix.c, 0.0,
disMatrix.b, disMatrix.d, 0.0,
0.0, 0.0, 1.0]);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/geom/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Point<T extends num> implements math.Point<T> {

/// Calculates the distance from this Point to another Point.
num distanceTo(math.Point<num> point) {
double distanceTo(math.Point<T> point) {
return sqrt(squaredDistanceTo(point));
}

Expand Down
10 changes: 6 additions & 4 deletions lib/src/media/implementation/audio_element_sound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class AudioElementSound extends Sound {
return new AudioElementSound._(audioElement);
} catch (e) {
if (soundLoadOptions.ignoreErrors) {
// dartanalyzer --strong known issues
// https://github.com/dart-lang/dev_compiler/issues/316
return MockSound.load(url, soundLoadOptions);
} else {
throw new StateError("Failed to load audio.");
Expand All @@ -41,7 +43,7 @@ class AudioElementSound extends Sound {

static Future<Sound> loadDataUrl(String dataUrl) async {

var audioUrls = [dataUrl];
var audioUrls = <String>[dataUrl];
var loadData = false;
var corsEnabled = false;

Expand All @@ -61,7 +63,7 @@ class AudioElementSound extends Sound {
SoundChannel play([bool loop = false, SoundTransform soundTransform]) {
var startTime = 0.0;
var duration = _audioElement.duration;
if (duration.isInfinite) duration = 3600;
if (duration.isInfinite) duration = 3600.0;
return new AudioElementSoundChannel(
this, startTime, duration, loop, soundTransform);
}
Expand All @@ -84,7 +86,7 @@ class AudioElementSound extends Sound {
}
}

var audioElement = _audioElement.clone(true);
var audioElement = _audioElement.clone(true) as AudioElement;
var audioCanPlay = audioElement.onCanPlay.first;
if (audioElement.readyState == 0) await audioCanPlay;
audioElement.onEnded.listen(_onAudioEnded);
Expand All @@ -97,7 +99,7 @@ class AudioElementSound extends Sound {
_soundChannels[audioElement] = null;
}

void _onAudioEnded(event) {
void _onAudioEnded(html.Event event) {
var audioElement = event.target;
var soundChannel = _soundChannels[audioElement];
if (soundChannel != null) soundChannel._onAudioEnded();
Expand Down
2 changes: 2 additions & 0 deletions lib/src/media/implementation/web_audio_api_sound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class WebAudioApiSound extends Sound {
}

if (soundLoadOptions.ignoreErrors) {
// dartanalyzer --strong known issues
// https://github.com/dart-lang/dev_compiler/issues/316
return MockSound.load(url, soundLoadOptions);
} else {
throw new StateError("Failed to load audio.");
Expand Down
4 changes: 2 additions & 2 deletions lib/src/media/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Video {
StreamSubscription onCanPlaySubscription = null;
StreamSubscription onErrorSubscription = null;

void onCanPlay(e) {
void onCanPlay(html.Event e) {
var video = new Video._(videoElement);
video.volume = this.volume;
video.muted = this.muted;
Expand All @@ -113,7 +113,7 @@ class Video {
completer.complete(video);
}

void onError(e) {
void onError(html.Event e) {
onCanPlaySubscription.cancel();
onErrorSubscription.cancel();
completer.completeError(e);
Expand Down
17 changes: 8 additions & 9 deletions lib/src/resources/resource_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ class ResourceManager {
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------

Future<ResourceManager> load() {
Future<ResourceManager> load() async {

var futures = this.pendingResources.map((r) => r.complete);

return Future.wait(futures).then((value) {
var errors = this.failedResources.length;
if (errors > 0) {
throw new StateError("Failed to load $errors resource(s).");
} else {
return this;
}
});
await Future.wait(futures);
var errors = this.failedResources.length;
if (errors > 0) {
throw new StateError("Failed to load $errors resource(s).");
} else {
return this;
}
}

//-----------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/src/resources/texture_atlas_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _TextureAtlasLoaderTextureAtlas extends TextureAtlasLoader {
Future<RenderTextureQuad> getRenderTextureQuad(String filename) async {
var name = this.namePrefix + getFilenameWithoutExtension(filename);
var bitmapData = this.textureAtlas.getBitmapData(name);
return new Future.value(bitmapData.renderTextureQuad);
return bitmapData.renderTextureQuad;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/text/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class TextField extends InteractiveObject {
var startIndex = 0;
var checkLine = '';
var validLine = '';
var lineWidth = 0;
var lineWidth = 0.0;
var lineIndent = 0;

var textFormat = _defaultTextFormat;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/toolkit/movie_clip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ part of stagexl.toolkit;
* OTHER DEALINGS IN THE SOFTWARE.
*/

/// **Note:** This class is not intended to be used directly. It is needed by
/// **Note:** This class is not intended to be used directly. It is needed by
/// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL.
class MovieClip extends Sprite {

Expand Down Expand Up @@ -135,7 +135,8 @@ class MovieClip extends Sprite {
* @param loop Initial value for the loop property.
* @param labels A hash of labels to pass to the timeline instance associated with this MovieClip.
**/
MovieClip([String mode, int startPosition, bool loop, Map<String, num> labels])
MovieClip(
[String mode, int startPosition, bool loop, Map<String, int> labels])
: super() {

this.mode = mode != null ? mode : MovieClip.INDEPENDENT;
Expand Down
9 changes: 5 additions & 4 deletions lib/src/toolkit/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ part of stagexl.toolkit;

typedef void ChangeHandler(dynamic sender); // Tween or Timeline

/// **Note:** This class is not intended to be used directly. It is needed by
/// **Note:** This class is not intended to be used directly. It is needed by
/// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL.
class TimelineAction {
int t;
Expand All @@ -42,7 +42,7 @@ class TimelineAction {
}
}

/// **Note:** This class is not intended to be used directly. It is needed by
/// **Note:** This class is not intended to be used directly. It is needed by
/// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL.
class TimelineStep {
num d;
Expand All @@ -60,7 +60,7 @@ class TimelineStep {
}
}

/// **Note:** This class is not intended to be used directly. It is needed by
/// **Note:** This class is not intended to be used directly. It is needed by
/// the 'Toolkit for Dart' to export from Flash Professional to Dart/StageXL.
class Timeline {
/**
Expand Down Expand Up @@ -116,7 +116,8 @@ class Timeline {
* </UL>
* @constructor
**/
Timeline(List<TimelineTween> tweens, Map<String, num> labels, Map<String, dynamic> props) {
Timeline(List<TimelineTween> tweens, Map<String, int> labels, Map<String, dynamic> props) {

if (props != null) {
loop = props.containsKey("loop") ? props["loop"] : false;
ignoreGlobalPause = props.containsKey("ignoreGlobalPause") ? props["ignoreGlobalPause"] : false;
Expand Down

0 comments on commit 37a4ec9

Please sign in to comment.