mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
JSON and binary loading for two color tinting.
This commit is contained in:
parent
626a734940
commit
38d925d1a7
@ -57,6 +57,7 @@ import com.esotericsoftware.spine.Animation.ShearTimeline;
|
|||||||
import com.esotericsoftware.spine.Animation.Timeline;
|
import com.esotericsoftware.spine.Animation.Timeline;
|
||||||
import com.esotericsoftware.spine.Animation.TransformConstraintTimeline;
|
import com.esotericsoftware.spine.Animation.TransformConstraintTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
||||||
|
import com.esotericsoftware.spine.Animation.TwoColorTimeline;
|
||||||
import com.esotericsoftware.spine.BoneData.TransformMode;
|
import com.esotericsoftware.spine.BoneData.TransformMode;
|
||||||
import com.esotericsoftware.spine.PathConstraintData.PositionMode;
|
import com.esotericsoftware.spine.PathConstraintData.PositionMode;
|
||||||
import com.esotericsoftware.spine.PathConstraintData.RotateMode;
|
import com.esotericsoftware.spine.PathConstraintData.RotateMode;
|
||||||
@ -85,6 +86,7 @@ public class SkeletonBinary {
|
|||||||
|
|
||||||
static public final int SLOT_ATTACHMENT = 0;
|
static public final int SLOT_ATTACHMENT = 0;
|
||||||
static public final int SLOT_COLOR = 1;
|
static public final int SLOT_COLOR = 1;
|
||||||
|
static public final int SLOT_TWO_COLOR = 2;
|
||||||
|
|
||||||
static public final int PATH_POSITION = 0;
|
static public final int PATH_POSITION = 0;
|
||||||
static public final int PATH_SPACING = 1;
|
static public final int PATH_SPACING = 1;
|
||||||
@ -94,7 +96,7 @@ public class SkeletonBinary {
|
|||||||
static public final int CURVE_STEPPED = 1;
|
static public final int CURVE_STEPPED = 1;
|
||||||
static public final int CURVE_BEZIER = 2;
|
static public final int CURVE_BEZIER = 2;
|
||||||
|
|
||||||
static private final Color tempColor = new Color();
|
static private final Color tempColor1 = new Color(), tempColor2 = new Color();
|
||||||
|
|
||||||
private final AttachmentLoader attachmentLoader;
|
private final AttachmentLoader attachmentLoader;
|
||||||
private float scale = 1;
|
private float scale = 1;
|
||||||
@ -206,6 +208,10 @@ public class SkeletonBinary {
|
|||||||
BoneData boneData = skeletonData.bones.get(input.readInt(true));
|
BoneData boneData = skeletonData.bones.get(input.readInt(true));
|
||||||
SlotData data = new SlotData(i, slotName, boneData);
|
SlotData data = new SlotData(i, slotName, boneData);
|
||||||
Color.rgba8888ToColor(data.color, input.readInt());
|
Color.rgba8888ToColor(data.color, input.readInt());
|
||||||
|
|
||||||
|
int darkColor = input.readInt();
|
||||||
|
if (darkColor != -1) Color.rgb888ToColor(data.darkColor = new Color(), darkColor);
|
||||||
|
|
||||||
data.attachmentName = input.readString();
|
data.attachmentName = input.readString();
|
||||||
data.blendMode = BlendMode.values[input.readInt(true)];
|
data.blendMode = BlendMode.values[input.readInt(true)];
|
||||||
skeletonData.slots.add(data);
|
skeletonData.slots.add(data);
|
||||||
@ -523,20 +529,7 @@ public class SkeletonBinary {
|
|||||||
int timelineType = input.readByte();
|
int timelineType = input.readByte();
|
||||||
int frameCount = input.readInt(true);
|
int frameCount = input.readInt(true);
|
||||||
switch (timelineType) {
|
switch (timelineType) {
|
||||||
case SLOT_COLOR: {
|
case SLOT_ATTACHMENT: {
|
||||||
ColorTimeline timeline = new ColorTimeline(frameCount);
|
|
||||||
timeline.slotIndex = slotIndex;
|
|
||||||
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
|
||||||
float time = input.readFloat();
|
|
||||||
Color.rgba8888ToColor(tempColor, input.readInt());
|
|
||||||
timeline.setFrame(frameIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
|
|
||||||
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
|
|
||||||
}
|
|
||||||
timelines.add(timeline);
|
|
||||||
duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * ColorTimeline.ENTRIES]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SLOT_ATTACHMENT:
|
|
||||||
AttachmentTimeline timeline = new AttachmentTimeline(frameCount);
|
AttachmentTimeline timeline = new AttachmentTimeline(frameCount);
|
||||||
timeline.slotIndex = slotIndex;
|
timeline.slotIndex = slotIndex;
|
||||||
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
|
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
|
||||||
@ -545,6 +538,35 @@ public class SkeletonBinary {
|
|||||||
duration = Math.max(duration, timeline.getFrames()[frameCount - 1]);
|
duration = Math.max(duration, timeline.getFrames()[frameCount - 1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SLOT_COLOR: {
|
||||||
|
ColorTimeline timeline = new ColorTimeline(frameCount);
|
||||||
|
timeline.slotIndex = slotIndex;
|
||||||
|
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
||||||
|
float time = input.readFloat();
|
||||||
|
Color.rgba8888ToColor(tempColor1, input.readInt());
|
||||||
|
timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a);
|
||||||
|
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
|
||||||
|
}
|
||||||
|
timelines.add(timeline);
|
||||||
|
duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * ColorTimeline.ENTRIES]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SLOT_TWO_COLOR: {
|
||||||
|
TwoColorTimeline timeline = new TwoColorTimeline(frameCount);
|
||||||
|
timeline.slotIndex = slotIndex;
|
||||||
|
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++) {
|
||||||
|
float time = input.readFloat();
|
||||||
|
Color.rgba8888ToColor(tempColor1, input.readInt());
|
||||||
|
Color.rgb888ToColor(tempColor2, input.readInt());
|
||||||
|
timeline.setFrame(frameIndex, time, tempColor1.r, tempColor1.g, tempColor1.b, tempColor1.a, tempColor2.r,
|
||||||
|
tempColor2.g, tempColor2.b);
|
||||||
|
if (frameIndex < frameCount - 1) readCurve(input, frameIndex, timeline);
|
||||||
|
}
|
||||||
|
timelines.add(timeline);
|
||||||
|
duration = Math.max(duration, timeline.getFrames()[(frameCount - 1) * TwoColorTimeline.ENTRIES]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,7 @@ import com.esotericsoftware.spine.Animation.ShearTimeline;
|
|||||||
import com.esotericsoftware.spine.Animation.Timeline;
|
import com.esotericsoftware.spine.Animation.Timeline;
|
||||||
import com.esotericsoftware.spine.Animation.TransformConstraintTimeline;
|
import com.esotericsoftware.spine.Animation.TransformConstraintTimeline;
|
||||||
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
import com.esotericsoftware.spine.Animation.TranslateTimeline;
|
||||||
|
import com.esotericsoftware.spine.Animation.TwoColorTimeline;
|
||||||
import com.esotericsoftware.spine.BoneData.TransformMode;
|
import com.esotericsoftware.spine.BoneData.TransformMode;
|
||||||
import com.esotericsoftware.spine.PathConstraintData.PositionMode;
|
import com.esotericsoftware.spine.PathConstraintData.PositionMode;
|
||||||
import com.esotericsoftware.spine.PathConstraintData.RotateMode;
|
import com.esotericsoftware.spine.PathConstraintData.RotateMode;
|
||||||
@ -157,6 +158,9 @@ public class SkeletonJson {
|
|||||||
String color = slotMap.getString("color", null);
|
String color = slotMap.getString("color", null);
|
||||||
if (color != null) data.getColor().set(Color.valueOf(color));
|
if (color != null) data.getColor().set(Color.valueOf(color));
|
||||||
|
|
||||||
|
String dark = slotMap.getString("dark", null);
|
||||||
|
if (dark != null) data.setDarkColor(Color.valueOf(dark));
|
||||||
|
|
||||||
data.attachmentName = slotMap.getString("attachment", null);
|
data.attachmentName = slotMap.getString("attachment", null);
|
||||||
data.blendMode = BlendMode.valueOf(slotMap.getString("blend", BlendMode.normal.name()));
|
data.blendMode = BlendMode.valueOf(slotMap.getString("blend", BlendMode.normal.name()));
|
||||||
skeletonData.slots.add(data);
|
skeletonData.slots.add(data);
|
||||||
@ -429,7 +433,17 @@ public class SkeletonJson {
|
|||||||
if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
|
if (slot == null) throw new SerializationException("Slot not found: " + slotMap.name);
|
||||||
for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
for (JsonValue timelineMap = slotMap.child; timelineMap != null; timelineMap = timelineMap.next) {
|
||||||
String timelineName = timelineMap.name;
|
String timelineName = timelineMap.name;
|
||||||
if (timelineName.equals("color")) {
|
if (timelineName.equals("attachment")) {
|
||||||
|
AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
|
||||||
|
timeline.slotIndex = slot.index;
|
||||||
|
|
||||||
|
int frameIndex = 0;
|
||||||
|
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
|
||||||
|
timeline.setFrame(frameIndex++, valueMap.getFloat("time"), valueMap.getString("name"));
|
||||||
|
timelines.add(timeline);
|
||||||
|
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
|
||||||
|
|
||||||
|
} else if (timelineName.equals("color")) {
|
||||||
ColorTimeline timeline = new ColorTimeline(timelineMap.size);
|
ColorTimeline timeline = new ColorTimeline(timelineMap.size);
|
||||||
timeline.slotIndex = slot.index;
|
timeline.slotIndex = slot.index;
|
||||||
|
|
||||||
@ -443,15 +457,22 @@ public class SkeletonJson {
|
|||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[(timeline.getFrameCount() - 1) * ColorTimeline.ENTRIES]);
|
duration = Math.max(duration, timeline.getFrames()[(timeline.getFrameCount() - 1) * ColorTimeline.ENTRIES]);
|
||||||
|
|
||||||
} else if (timelineName.equals("attachment")) {
|
} else if (timelineName.equals("twoColor")) {
|
||||||
AttachmentTimeline timeline = new AttachmentTimeline(timelineMap.size);
|
TwoColorTimeline timeline = new TwoColorTimeline(timelineMap.size);
|
||||||
timeline.slotIndex = slot.index;
|
timeline.slotIndex = slot.index;
|
||||||
|
|
||||||
int frameIndex = 0;
|
int frameIndex = 0;
|
||||||
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next)
|
for (JsonValue valueMap = timelineMap.child; valueMap != null; valueMap = valueMap.next) {
|
||||||
timeline.setFrame(frameIndex++, valueMap.getFloat("time"), valueMap.getString("name"));
|
Color light = Color.valueOf(valueMap.getString("light"));
|
||||||
|
Color dark = Color.valueOf(valueMap.getString("dark"));
|
||||||
|
timeline.setFrame(frameIndex, valueMap.getFloat("time"), light.r, light.g, light.b, light.a, dark.r, dark.g,
|
||||||
|
dark.b);
|
||||||
|
readCurve(valueMap, timeline, frameIndex);
|
||||||
|
frameIndex++;
|
||||||
|
}
|
||||||
timelines.add(timeline);
|
timelines.add(timeline);
|
||||||
duration = Math.max(duration, timeline.getFrames()[timeline.getFrameCount() - 1]);
|
duration = Math.max(duration, timeline.getFrames()[(timeline.getFrameCount() - 1) * TwoColorTimeline.ENTRIES]);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name + ")");
|
throw new RuntimeException("Invalid timeline type for a slot: " + timelineName + " (" + slotMap.name + ")");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user