Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1:1 typescript migration of the core #4

Merged
merged 2 commits into from
Sep 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@
*.war
*.ear

*.iml
*.ipr
*.iws

.gradle
.idea

/build
/out
/classes
/target

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DragonBonesJAVA

coming soon...
```
./gradlew check
```
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
allprojects {
group 'com.dragonbones'
version '0.1'

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
jcenter()
mavenCentral()
}

dependencies {
compile "org.jetbrains:annotations:13.0"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
4 changes: 4 additions & 0 deletions dragonbones-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
/out
/classes
/target
2 changes: 2 additions & 0 deletions dragonbones-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
package com.dragonbones.animation;

import com.dragonbones.armature.Armature;
import com.dragonbones.armature.Slot;
import com.dragonbones.core.ActionType;
import com.dragonbones.core.BaseObject;
import com.dragonbones.core.BinaryOffset;
import com.dragonbones.event.EventObject;
import com.dragonbones.event.EventStringType;
import com.dragonbones.event.IEventDispatcher;
import com.dragonbones.model.ActionData;
import com.dragonbones.model.TimelineData;
import com.dragonbones.util.Array;

/**
* @internal
* @private
*/
public class ActionTimelineState extends TimelineState {
private void _onCrossFrame(int frameIndex) {
IEventDispatcher eventDispatcher = this._armature.getEventDispatcher();
if (this._animationState.actionEnabled) {
int frameOffset = this._animationData.frameOffset + this._timelineArray.get(this._timelineData.offset + BinaryOffset.TimelineFrameOffset.v + frameIndex);
int actionCount = this._frameArray.get(frameOffset + 1);
Array<ActionData> actions = this._armature.armatureData.actions;
for (int i = 0; i < actionCount; ++i) {
int actionIndex = this._frameArray.get(frameOffset + 2 + i);
ActionData action = actions.get(actionIndex);
if (action.type == ActionType.Play) {
if (action.slot != null) {
Slot slot = this._armature.getSlot(action.slot.name);
if (slot != null) {
Armature childArmature = slot.getChildArmature();
if (childArmature != null) {
childArmature._bufferAction(action, true);
}
}
} else if (action.bone != null) {
for (Slot slot : this._armature.getSlots()) {
Armature childArmature = slot.getChildArmature();
if (childArmature != null && slot.getParent().boneData == action.bone) {
childArmature._bufferAction(action, true);
}
}
} else {
this._armature._bufferAction(action, true);
}
} else {
EventStringType eventType = action.type == ActionType.Frame ? EventObject.FRAME_EVENT : EventObject.SOUND_EVENT;
if (action.type == ActionType.Sound || eventDispatcher.hasEvent(eventType)) {
EventObject eventObject = BaseObject.borrowObject(EventObject.class);
// eventObject.time = this._frameArray[frameOffset] * this._frameRateR; // Precision problem
eventObject.time = this._frameArray.get(frameOffset) / this._frameRate;
eventObject.type = eventType;
eventObject.name = action.name;
eventObject.data = action.data;
eventObject.armature = this._armature;
eventObject.animationState = this._animationState;

if (action.bone != null) {
eventObject.bone = this._armature.getBone(action.bone.name);
}

if (action.slot != null) {
eventObject.slot = this._armature.getSlot(action.slot.name);
}

this._armature._dragonBones.bufferEvent(eventObject);
}
}
}
}
}

protected void _onArriveAtFrame() {
}

protected void _onUpdateFrame() {
}

public void update(float passedTime) {
int prevState = this.playState;
float prevPlayTimes = this.currentPlayTimes;
float prevTime = this.currentTime;

if (this.playState <= 0 && this._setCurrentTime(passedTime)) {
IEventDispatcher eventDispatcher = this._armature.getEventDispatcher();
if (prevState < 0) {
if (this.playState != prevState) {
if (this._animationState.displayControl && this._animationState.resetToPose) { // Reset zorder to pose.
this._armature._sortZOrder(null, 0);
}

prevPlayTimes = this.currentPlayTimes;

if (eventDispatcher.hasEvent(EventObject.START)) {
EventObject eventObject = BaseObject.borrowObject(EventObject.class);
eventObject.type = EventObject.START;
eventObject.armature = this._armature;
eventObject.animationState = this._animationState;
this._armature._dragonBones.bufferEvent(eventObject);
}
} else {
return;
}
}

boolean isReverse = this._animationState.timeScale < 0f;
EventObject loopCompleteEvent = null;
EventObject completeEvent = null;
if (this.currentPlayTimes != prevPlayTimes) {
if (eventDispatcher.hasEvent(EventObject.LOOP_COMPLETE)) {
loopCompleteEvent = BaseObject.borrowObject(EventObject.class);
loopCompleteEvent.type = EventObject.LOOP_COMPLETE;
loopCompleteEvent.armature = this._armature;
loopCompleteEvent.animationState = this._animationState;
}

if (this.playState > 0) {
if (eventDispatcher.hasEvent(EventObject.COMPLETE)) {
completeEvent = BaseObject.borrowObject(EventObject.class);
completeEvent.type = EventObject.COMPLETE;
completeEvent.armature = this._armature;
completeEvent.animationState = this._animationState;
}

}
}

if (this._frameCount > 1) {
TimelineData timelineData = this._timelineData;
int timelineFrameIndex = (int) Math.floor(this.currentTime * this._frameRate); // uint
int frameIndex = this._frameIndices.get(timelineData.frameIndicesOffset + timelineFrameIndex);
if (this._frameIndex != frameIndex) { // Arrive at frame.
int crossedFrameIndex = this._frameIndex;
this._frameIndex = frameIndex;
if (this._timelineArray != null) {
this._frameOffset = this._animationData.frameOffset + this._timelineArray.get(timelineData.offset + BinaryOffset.TimelineFrameOffset.v + this._frameIndex);
if (isReverse) {
if (crossedFrameIndex < 0) {
int prevFrameIndex = (int) Math.floor(prevTime * this._frameRate);
crossedFrameIndex = this._frameIndices.get(timelineData.frameIndicesOffset + prevFrameIndex);
if (this.currentPlayTimes == prevPlayTimes) { // Start.
if (crossedFrameIndex == frameIndex) { // Uncrossed.
crossedFrameIndex = -1;
}
}
}

while (crossedFrameIndex >= 0) {
int frameOffset = this._animationData.frameOffset + this._timelineArray.get(timelineData.offset + BinaryOffset.TimelineFrameOffset.v + crossedFrameIndex);
// const framePosition = this._frameArray[frameOffset] * this._frameRateR; // Precision problem
float framePosition = this._frameArray.get(frameOffset) / this._frameRate;
if (
this._position <= framePosition &&
framePosition <= this._position + this._duration
) { // Support interval play.
this._onCrossFrame(crossedFrameIndex);
}

if (loopCompleteEvent != null && crossedFrameIndex == 0) { // Add loop complete event after first frame.
this._armature._dragonBones.bufferEvent(loopCompleteEvent);
loopCompleteEvent = null;
}

if (crossedFrameIndex > 0) {
crossedFrameIndex--;
} else {
crossedFrameIndex = this._frameCount - 1;
}

if (crossedFrameIndex == frameIndex) {
break;
}
}
} else {
if (crossedFrameIndex < 0) {
int prevFrameIndex = (int) Math.floor(prevTime * this._frameRate);
crossedFrameIndex = this._frameIndices.get(timelineData.frameIndicesOffset + prevFrameIndex);
int frameOffset = this._animationData.frameOffset + this._timelineArray.get(timelineData.offset + BinaryOffset.TimelineFrameOffset.v + crossedFrameIndex);
// const framePosition = this._frameArray[frameOffset] * this._frameRateR; // Precision problem
float framePosition = this._frameArray.get(frameOffset) / this._frameRate;
if (this.currentPlayTimes == prevPlayTimes) { // Start.
if (prevTime <= framePosition) { // Crossed.
if (crossedFrameIndex > 0) {
crossedFrameIndex--;
} else {
crossedFrameIndex = this._frameCount - 1;
}
} else if (crossedFrameIndex == frameIndex) { // Uncrossed.
crossedFrameIndex = -1;
}
}
}

while (crossedFrameIndex >= 0) {
if (crossedFrameIndex < this._frameCount - 1) {
crossedFrameIndex++;
} else {
crossedFrameIndex = 0;
}

int frameOffset = this._animationData.frameOffset + this._timelineArray.get(timelineData.offset + BinaryOffset.TimelineFrameOffset.v + crossedFrameIndex);
// const framePosition = this._frameArray[frameOffset] * this._frameRateR; // Precision problem
float framePosition = this._frameArray.get(frameOffset) / this._frameRate;
if (
this._position <= framePosition &&
framePosition <= this._position + this._duration
) { // Support interval play.
this._onCrossFrame(crossedFrameIndex);
}

if (loopCompleteEvent != null && crossedFrameIndex == 0) { // Add loop complete event before first frame.
this._armature._dragonBones.bufferEvent(loopCompleteEvent);
loopCompleteEvent = null;
}

if (crossedFrameIndex == frameIndex) {
break;
}
}
}
}
}
} else if (this._frameIndex < 0) {
this._frameIndex = 0;
if (this._timelineData != null) {
this._frameOffset = this._animationData.frameOffset + this._timelineArray.get(this._timelineData.offset + BinaryOffset.TimelineFrameOffset.v);
// Arrive at frame.
float framePosition = this._frameArray.get(this._frameOffset) / this._frameRate;
if (this.currentPlayTimes == prevPlayTimes) { // Start.
if (prevTime <= framePosition) {
this._onCrossFrame(this._frameIndex);
}
} else if (this._position <= framePosition) { // Loop complete.
if (!isReverse && loopCompleteEvent != null) { // Add loop complete event before first frame.
this._armature._dragonBones.bufferEvent(loopCompleteEvent);
loopCompleteEvent = null;
}

this._onCrossFrame(this._frameIndex);
}
}
}

if (loopCompleteEvent != null) {
this._armature._dragonBones.bufferEvent(loopCompleteEvent);
}

if (completeEvent != null) {
this._armature._dragonBones.bufferEvent(completeEvent);
}
}
}

public void setCurrentTime(float value) {
this._setCurrentTime(value);
this._frameIndex = -1;
}
}
Loading