@@ -37,7 +37,7 @@ type Ase struct {
3737 Slices []Slice
3838
3939 // Timeline animation tags
40- Tags []Tag
40+ Tags []* Tag
4141
4242 // Tilesets used in Tilemap layers
4343 Tilesets []* Tileset
@@ -63,6 +63,18 @@ func (a *Ase) GetLayerByName(name string) *Layer {
6363 return a .Layers [idx ]
6464}
6565
66+ // GetTagByName returns the first Tag with the given name.
67+ // Returns nil if no layer is found with that name.
68+ func (a * Ase ) GetTagByName (tagName string ) * Tag {
69+ idx := slices .IndexFunc (a .Tags , func (t * Tag ) bool {
70+ return t .Name == tagName
71+ })
72+ if idx == - 1 {
73+ return nil
74+ }
75+ return a .Tags [idx ]
76+ }
77+
6678// GetLayerByUUID returns the layer with the given UUID.
6779// Returns nil if no layer is found with that UUID.
6880func (a * Ase ) GetLayerByUUID (id uuid.UUID ) * Layer {
@@ -218,7 +230,7 @@ func (a *Ase) parse(r io.Reader, onlyVisible bool) (filesize int64, err error) {
218230 startIdx := len (a .Tags )
219231 a .Tags = append (a .Tags , newTags ... )
220232 for k := range newTags {
221- tagQueue = append (tagQueue , & a .Tags [startIdx + k ])
233+ tagQueue = append (tagQueue , a .Tags [startIdx + k ])
222234 }
223235 lastUserDataTarget = nil
224236 case 0x2022 :
@@ -357,18 +369,21 @@ func (a *Ase) parseSlice(raw []byte, totalFrames int) Slice {
357369}
358370
359371// Chunk0x2018
360- func (a * Ase ) parseTags (raw []byte ) []Tag {
372+ func (a * Ase ) parseTags (raw []byte ) []* Tag {
361373 ntags := int (binary .LittleEndian .Uint16 (raw ))
362- tags := make ([]Tag , ntags )
374+ tags := make ([]* Tag , 0 , ntags )
363375 ptr := raw [10 :]
364- for i := range ntags {
365- t := & tags [i ]
376+
377+ for range ntags {
378+ t := & Tag {}
366379 t .Start = int (binary .LittleEndian .Uint16 (ptr ))
367380 t .End = int (binary .LittleEndian .Uint16 (ptr [2 :]))
368381 t .LoopDirection = LoopDirection (ptr [4 ])
369382 t .Repeat = binary .LittleEndian .Uint16 (ptr [5 :])
370383 nameLen := binary .LittleEndian .Uint16 (ptr [17 :])
371384 t .Name = string (ptr [19 : 19 + nameLen ])
385+
386+ tags = append (tags , t )
372387 ptr = ptr [19 + nameLen :]
373388 }
374389
0 commit comments