Skip to content

Commit

Permalink
Merged branch 'master' of github.com:jtakakura/spine_core
Browse files Browse the repository at this point in the history
Resolved conflicts:
#	lib/src/animation.dart
#	lib/src/animation_state.dart
#	lib/src/transform_constraint.dart
  • Loading branch information
dev-hann committed Jan 17, 2022
2 parents d00c54d + 3c34056 commit e47da9b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 34 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Dart

on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: "0 7 * * 0"

jobs:
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/[email protected]
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

test:
needs: analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [stable, dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/[email protected]
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

## 0.3.0

- Nullsafety support
- Nullsafety support(thanks to @signmotion)

## 0.3.1

- More support for null safety(thanks to @signmotion)
42 changes: 26 additions & 16 deletions lib/src/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Animation {

void apply(Skeleton skeleton, double lastTime, double time, bool loop,
List<Event?> events, double alpha, MixPose pose, MixDirection direction) {

if (loop && duration != 0) {
time %= duration;
if (lastTime > 0) lastTime %= duration;
Expand Down Expand Up @@ -605,8 +604,11 @@ class TwoColorTimeline extends CurveTimeline {
(setupLight.g - light.g) * alpha,
(setupLight.b - light.b) * alpha,
(setupLight.a - light.a) * alpha);
dark!.add((setupDark!.r - dark.r) * alpha, (setupDark.g - dark.g) * alpha,
(setupDark.b - dark.b) * alpha, 0.0);
dark!.add(
(setupDark!.r - dark.r) * alpha,
(setupDark.g - dark.g) * alpha,
(setupDark.b - dark.b) * alpha,
0.0);
}
return;
}
Expand Down Expand Up @@ -673,7 +675,8 @@ class AttachmentTimeline implements Timeline {
AttachmentTimeline(int frameCount, this.slotIndex)
: assert(slotIndex >= 0),
frames = Float32List(frameCount),
attachmentNames = List<String?>.filled(frameCount, null, growable: false);
attachmentNames =
List<String?>.filled(frameCount, null, growable: false);

@override
int getPropertyId() => (TimelineType.Attachment.index << 24) + slotIndex;
Expand Down Expand Up @@ -730,7 +733,8 @@ class DeformTimeline extends CurveTimeline {
DeformTimeline(int frameCount, this.slotIndex, this.attachment)
: assert(slotIndex >= 0),
frames = Float32List(frameCount),
frameVertices = List<Float32List?>.filled(frameCount, null, growable: false),
frameVertices =
List<Float32List?>.filled(frameCount, null, growable: false),
super(frameCount);

@override
Expand Down Expand Up @@ -770,7 +774,8 @@ class DeformTimeline extends CurveTimeline {
return;
}
final Float32List vertices = Float32List.fromList(
ArrayUtils.copyWithNewArraySize(verticesArray, vertexCount, double.infinity));
ArrayUtils.copyWithNewArraySize(
verticesArray, vertexCount, double.infinity));
if (vertexAttachment.bones == null) {
// Unweighted vertex positions.
final Float32List setupVertices = vertexAttachment.vertices!;
Expand All @@ -785,14 +790,15 @@ class DeformTimeline extends CurveTimeline {
return;
}

Float32List vertices = Float32List.fromList(
ArrayUtils.copyWithNewArraySize(verticesArray, vertexCount, double.infinity));
Float32List vertices = Float32List.fromList(ArrayUtils.copyWithNewArraySize(
verticesArray, vertexCount, double.infinity));
if (time >= frames[frames.length - 1]) {
// Time is after last frame.
final Float32List lastVertices = frameVertices[frames.length - 1]!;
if (alpha == 1) {
vertices = ArrayUtils.arrayCopyWithGrowth(
lastVertices, 0, vertices, 0, vertexCount, double.infinity) as Float32List;
lastVertices, 0, vertices, 0, vertexCount, double.infinity)
as Float32List;
} else if (pose == MixPose.Setup) {
if (vertexAttachment.bones == null) {
// Unweighted vertex positions, with alpha.
Expand Down Expand Up @@ -1029,7 +1035,8 @@ class IkConstraintTimeline extends CurveTimeline {
alpha
..bendDirection = direction == MixDirection.Out
? constraint.data.bendDirection
: frames[frames.length + IkConstraintTimeline.prevBendDirection] as int;
: frames[frames.length + IkConstraintTimeline.prevBendDirection]
as int;
} else {
constraint.mix = constraint.mix +
(frames[frames.length + IkConstraintTimeline.prevMix] -
Expand Down Expand Up @@ -1065,10 +1072,11 @@ class IkConstraintTimeline extends CurveTimeline {
? constraint.data.bendDirection
: frames[frame + IkConstraintTimeline.prevBendDirection] as int;
} else {
constraint.mix = constraint.mix + (mix +
(frames[frame + IkConstraintTimeline.mix] - mix) * percent -
constraint.mix) *
alpha;
constraint.mix = constraint.mix +
(mix +
(frames[frame + IkConstraintTimeline.mix] - mix) * percent -
constraint.mix) *
alpha;
if (direction == MixDirection.In)
constraint.bendDirection =
frames[frame + IkConstraintTimeline.prevBendDirection].toInt();
Expand Down Expand Up @@ -1261,7 +1269,8 @@ class PathConstraintPositionTimeline extends CurveTimeline {
constraint.position = constraint.data.position +
(position - constraint.data.position) * alpha;
else
constraint.position = constraint.position + (position - constraint.position) * alpha;
constraint.position =
constraint.position + (position - constraint.position) * alpha;
}
}

Expand Down Expand Up @@ -1320,7 +1329,8 @@ class PathConstraintSpacingTimeline extends PathConstraintPositionTimeline {
constraint.spacing =
constraint.data.spacing + (spacing - constraint.data.spacing) * alpha;
else
constraint.spacing = constraint.spacing + (spacing - constraint.spacing) * alpha;
constraint.spacing =
constraint.spacing + (spacing - constraint.spacing) * alpha;
}
}

Expand Down
41 changes: 29 additions & 12 deletions lib/src/animation_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ class AnimationState {
if (mix > 1) mix = 1.0;
}

final List<Event?> events = mix < from.eventThreshold ? this.events : <Event?>[];
final List<Event?> events =
mix < from.eventThreshold ? this.events : <Event?>[];
final bool attachments = mix < from.attachmentThreshold;
final bool drawOrder = mix < from.drawOrderThreshold;
final double animationLast = from.animationLast;
Expand Down Expand Up @@ -307,7 +308,8 @@ class AnimationState {
if (firstFrame) timelinesRotation[i] = 0.0;

if (alpha == 1) {
timeline.apply(skeleton, 0.0, time, <Event?>[], 1.0, pose, MixDirection.In);
timeline.apply(
skeleton, 0.0, time, <Event?>[], 1.0, pose, MixDirection.In);
return;
}

Expand Down Expand Up @@ -464,7 +466,8 @@ class AnimationState {

// Store the interrupted mix percentage.
if (from.mixingFrom != null && from.mixDuration > 0)
current!.interruptAlpha = current.interruptAlpha * math.min(1, from.mixTime / from.mixDuration);
current!.interruptAlpha = current.interruptAlpha *
math.min(1, from.mixTime / from.mixDuration);

// Reset rotation for mixing out, in case entry was mixed in.
from.timelinesRotation.length = 0;
Expand Down Expand Up @@ -575,8 +578,8 @@ class AnimationState {

TrackEntry? expandToIndex(int index) {
if (index < tracks.length) return tracks[index];
tracks = ArrayUtils.ensureArrayCapacity(
tracks, index - tracks.length + 1, null);
tracks =
ArrayUtils.ensureArrayCapacity(tracks, index - tracks.length + 1, null);
tracks.length = index + 1;
return null;
}
Expand Down Expand Up @@ -827,29 +830,42 @@ class EventQueue {
EventQueue(this.animState);

void start(TrackEntry? entry) {
objects..add(EventType.Start)..add(entry);
objects
..add(EventType.Start)
..add(entry);
animState.animationsChanged = true;
}

void interrupt(TrackEntry entry) {
objects..add(EventType.Interrupt)..add(entry);
objects
..add(EventType.Interrupt)
..add(entry);
}

void end(TrackEntry entry) {
objects..add(EventType.End)..add(entry);
objects
..add(EventType.End)
..add(entry);
animState.animationsChanged = true;
}

void dispose(TrackEntry entry) {
objects..add(EventType.Dispose)..add(entry);
objects
..add(EventType.Dispose)
..add(entry);
}

void complete(TrackEntry entry) {
objects..add(EventType.Complete)..add(entry);
objects
..add(EventType.Complete)
..add(entry);
}

void event(TrackEntry entry, Event? event) {
objects..add(EventType.Event)..add(entry)..add(event);
objects
..add(EventType.Event)
..add(entry)
..add(event);
}

void drain() {
Expand Down Expand Up @@ -898,7 +914,8 @@ class EventQueue {
animState.trackEntryPool.free(entry);
break;
case EventType.Complete:
if (entry!.onCompleteCallback != null) entry.onCompleteCallback!(entry);
if (entry!.onCompleteCallback != null)
entry.onCompleteCallback!(entry);
onCompleteCallbacks
.forEach((TrackEntryCallback callback) => callback(entry));
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/texture_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class TextureAtlasPage {
int width = 0;
int height = 0;

TextureAtlasPage(this.name): assert(name.isNotEmpty);
TextureAtlasPage(this.name) : assert(name.isNotEmpty);
}

class TextureAtlasRegion extends TextureRegion {
Expand All @@ -231,5 +231,5 @@ class TextureAtlasRegion extends TextureRegion {
int index = -1;
Texture? texture;

TextureAtlasRegion(this.name): assert(name.isNotEmpty);
TextureAtlasRegion(this.name) : assert(name.isNotEmpty);
}
3 changes: 2 additions & 1 deletion lib/src/transform_constraint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ class TransformConstraint extends Constraint {

double rotation = bone.arotation;
if (rotateMix != 0)
rotation = rotation + (target.arotation + data.offsetRotation) * rotateMix;
rotation =
rotation + (target.arotation + data.offsetRotation) * rotateMix;

double x = bone.ax, y = bone.ay;
if (translateMix != 0) {
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

name: spine_core
description: The spine-core runtime provides functionality to load and manipulate Spine skeletal animation data using Dart.
version: 0.3.0
version: 0.3.1
homepage: https://github.com/jtakakura/spine_core/

environment:
sdk: ">=2.15.1 <3.0.0"
flutter: ">=2.8.1"

dev_dependencies:
test: ^1.20.1

0 comments on commit e47da9b

Please sign in to comment.