fixes #767, implemented deepCopy for the dcc_animation and dc6_animation (#852)

This commit is contained in:
Gürkan Kaymak 2020-10-26 16:13:08 +03:00 committed by GitHub
parent 7f19f7e970
commit ec9c0c3d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 7 deletions

View File

@ -124,3 +124,18 @@ func scanlineType(b int) scanlineState {
return runOfOpaquePixels
}
// Clone creates a copy of the DC6
func (d *DC6) Clone() *DC6 {
clone := *d
copy(clone.Termination, d.Termination)
copy(clone.FramePointers, d.FramePointers)
clone.Frames = make([]*DC6Frame, len(d.Frames))
for i := range d.Frames {
cloneFrame := *d.Frames[i]
clone.Frames = append(clone.Frames, &cloneFrame)
}
return &clone
}

View File

@ -57,7 +57,22 @@ func Load(fileData []byte) (*DCC, error) {
}
// decodeDirection decodes and returns the given direction
func (dcc *DCC) decodeDirection(direction int) *DCCDirection {
return CreateDCCDirection(d2datautils.CreateBitMuncher(dcc.fileData,
dcc.directionOffsets[direction]*directionOffsetMultiplier), dcc)
func (d *DCC) decodeDirection(direction int) *DCCDirection {
return CreateDCCDirection(d2datautils.CreateBitMuncher(d.fileData,
d.directionOffsets[direction]*directionOffsetMultiplier), d)
}
// Clone creates a copy of the DCC
func (d *DCC) Clone() *DCC {
clone := *d
copy(clone.directionOffsets, d.directionOffsets)
copy(clone.fileData, d.fileData)
clone.Directions = make([]*DCCDirection, len(d.Directions))
for i := range d.Directions {
cloneDirection := *d.Directions[i]
clone.Directions = append(clone.Directions, &cloneDirection)
}
return &clone
}

View File

@ -396,3 +396,11 @@ func (a *Animation) SetEffect(e d2enum.DrawEffect) {
func (a *Animation) SetShadow(shadow bool) {
a.hasShadow = shadow
}
// Clone creates a copy of the Animation
func (a *Animation) Clone() Animation {
clone := *a
copy(clone.directions, a.directions)
return clone
}

View File

@ -188,6 +188,10 @@ func (a *DC6Animation) createFrameSurface(directionIndex, frameIndex int) (d2int
// Clone creates a copy of the animation
func (a *DC6Animation) Clone() d2interface.Animation {
animation := *a
return &animation
clone := &DC6Animation{}
clone.Animation = a.Animation.Clone()
clone.dc6 = a.dc6.Clone()
clone.palette = a.palette
return clone
}

View File

@ -72,8 +72,12 @@ func (a *DCCAnimation) init() error {
// Clone creates a copy of the animation
func (a *DCCAnimation) Clone() d2interface.Animation {
animation := *a
return &animation
clone := &DCCAnimation{}
clone.Animation = a.Animation.Clone()
clone.dcc = a.dcc.Clone()
clone.palette = a.palette
return clone
}
// SetDirection places the animation in the direction of an animation