Skip to content

Commit 195d61a

Browse files
committed
Add AseLayer details to ASEInfo in Korge-Gradle-plugin
1 parent 1042cf7 commit 195d61a

File tree

1 file changed

+69
-0
lines changed
  • korge-gradle-plugin/src/main/kotlin/korlibs/korge/gradle/util

1 file changed

+69
-0
lines changed

korge-gradle-plugin/src/main/kotlin/korlibs/korge/gradle/util/ASEInfo.kt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package korlibs.korge.gradle.util
33
data class ASEInfo(
44
val slices: List<AseSlice> = emptyList(),
55
val tags: List<AseTag> = emptyList(),
6+
val layers: List<AseLayer> = emptyList(),
67
) {
78
data class AseSlice(
89
val sliceName: String,
@@ -18,6 +19,52 @@ data class ASEInfo(
1819
val tagName: String
1920
)
2021

22+
data class AseLayer(
23+
val layerName: String,
24+
val visible: Boolean,
25+
val type: AseLayerType,
26+
val blendMode: AseBlendMode,
27+
val opacity: Int
28+
) {
29+
enum class AseLayerType(val value: Int) {
30+
NORMAL(0),
31+
GROUP(1),
32+
TILEMAP(2);
33+
34+
companion object {
35+
private val map = values().associateBy(AseLayerType::value)
36+
fun fromInt(value: Int): AseLayerType = map[value] ?: NORMAL
37+
}
38+
}
39+
40+
enum class AseBlendMode(val value: Int) {
41+
NORMAL(0),
42+
MULTIPLY(1),
43+
SCREEN(2),
44+
OVERLAY(3),
45+
DARKEN(4),
46+
LIGHTEN(5),
47+
COLOR_DODGE(6),
48+
COLOR_BURN(7),
49+
HARD_LIGHT(8),
50+
SOFT_LIGHT(9),
51+
DIFFERENCE(10),
52+
EXCLUSION(11),
53+
HUE(12),
54+
SATURATION(13),
55+
COLOR(14),
56+
LUMINOSITY(15),
57+
ADDITION(16),
58+
SUBTRACT(17),
59+
DIVIDE(18);
60+
61+
companion object {
62+
private val map = values().associateBy(AseBlendMode::value)
63+
fun fromInt(value: Int): AseBlendMode = map[value] ?: NORMAL
64+
}
65+
}
66+
}
67+
2168
companion object {
2269
fun getAseInfo(file: SFile): ASEInfo {
2370
return getAseInfo(file.readBytes())
@@ -32,6 +79,7 @@ data class ASEInfo(
3279

3380
val slices = arrayListOf<AseSlice>()
3481
val tags = arrayListOf<AseTag>()
82+
val layers = arrayListOf<AseLayer>()
3583

3684
val fileSize = s.readS32LE()
3785
if (s.length < fileSize) error("File too short s.length=${s.length} < fileSize=${fileSize}")
@@ -81,6 +129,26 @@ data class ASEInfo(
81129
//println(" chunkType=$chunkType, chunkSize=$chunkSize")
82130

83131
when (chunkType) {
132+
0x2004 -> { // LAYER
133+
// Layer chunk
134+
val flags = cs.readU16LE()
135+
val type = cs.readU16LE()
136+
val layerChildLevel = cs.readU16LE()
137+
cs.skip(2)
138+
val blendMode = cs.readU16LE()
139+
val opacity = cs.readU8()
140+
cs.skip(3)
141+
val layerName = cs.readAseString()
142+
layers += AseLayer(
143+
layerName = layerName,
144+
visible = !flags.hasBitSet(0),
145+
type = AseLayer.AseLayerType.fromInt(type),
146+
blendMode = AseLayer.AseBlendMode.fromInt(blendMode),
147+
opacity = opacity
148+
)
149+
150+
//println(" Layer: name='$layerName', type=$type, blendMode=$blendMode, opacity=$opacity, flags=$flags")
151+
}
84152
0x2022 -> { // SLICE KEYS
85153
val numSliceKeys = cs.readS32LE()
86154
val sliceFlags = cs.readS32LE()
@@ -120,6 +188,7 @@ data class ASEInfo(
120188
return ASEInfo(
121189
slices = slices,
122190
tags = tags,
191+
layers = layers
123192
)
124193
}
125194

0 commit comments

Comments
 (0)