1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-28 01:55:24 +00:00

Apply some more object animation settings (#549)

* Init torches with random start mode

* Apply more object animation settings

Also add ability to start object animation on random frame
This commit is contained in:
Ziemas 2020-07-07 02:12:53 +02:00 committed by GitHub
parent 321a353461
commit e473dc2cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 4 deletions

View File

@ -152,12 +152,43 @@ func (c *Composite) GetPlayedCount() int {
return c.mode.playedCount return c.mode.playedCount
} }
// SetPlayLoop turns on or off animation looping
func (c *Composite) SetPlayLoop(loop bool) {
for layerIdx := range c.mode.layers {
layer := c.mode.layers[layerIdx]
if layer != nil {
layer.SetPlayLoop(loop)
}
}
}
// SetSubLoop sets a loop to be between the specified frame indices
func (c *Composite) SetSubLoop(startFrame, endFrame int) {
for layerIdx := range c.mode.layers {
layer := c.mode.layers[layerIdx]
if layer != nil {
layer.SetSubLoop(startFrame, endFrame)
}
}
}
// SetCurrentFrame sets the current frame index of the animation
func (c *Composite) SetCurrentFrame(frame int) {
for layerIdx := range c.mode.layers {
layer := c.mode.layers[layerIdx]
if layer != nil {
layer.SetCurrentFrame(frame)
}
}
}
func (c *Composite) resetPlayedCount() { func (c *Composite) resetPlayedCount() {
if c.mode != nil { if c.mode != nil {
c.mode.playedCount = 0 c.mode.playedCount = 0
} }
} }
type compositeMode struct { type compositeMode struct {
cof *d2cof.COF cof *d2cof.COF
animationMode string animationMode string

View File

@ -1,6 +1,8 @@
package d2object package d2object
import ( import (
"math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
) )
@ -10,6 +12,7 @@ func initObject(ob *Object) bool {
8: initTorch, 8: initTorch,
14: initTorch, 14: initTorch,
17: initWaypoint, 17: initWaypoint,
34: initTorchRnd,
} }
fun, ok := funcs[ob.objectRecord.InitFn] fun, ok := funcs[ob.objectRecord.InitFn]
@ -25,13 +28,24 @@ func initObject(ob *Object) bool {
// Initializes torch/brazier type objects // Initializes torch/brazier type objects
func initTorch(ob *Object) { func initTorch(ob *Object) {
if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] { if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] {
ob.setMode("ON", 0) ob.setMode("ON", 0, true)
} }
} }
func initWaypoint(ob *Object) { func initWaypoint(ob *Object) {
// Turn these on unconditionally for now, they look nice :) // Turn these on unconditionally for now, they look nice :)
if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] { if ob.objectRecord.HasAnimationMode[d2enum.AnimationModeObjectOperating] {
ob.setMode("ON", 0) ob.setMode("ON", 0, true)
}
}
// Randomly spawns in either NU or OP
func initTorchRnd(ob *Object) {
n := rand.Intn(2)
if n > 0 {
ob.setMode("NU", 0, true)
} else {
ob.setMode("OP", 0, true)
} }
} }

View File

@ -3,6 +3,7 @@ package d2object
import ( import (
"math" "math"
"math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common" "github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
@ -49,7 +50,7 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
entity.composite = composite entity.composite = composite
entity.setMode("NU", 0) entity.setMode("NU", 0, false)
initObject(entity) initObject(entity)
@ -57,7 +58,7 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
} }
// setMode changes the graphical mode of this animated entity // setMode changes the graphical mode of this animated entity
func (ob *Object) setMode(animationMode string, direction int) error { func (ob *Object) setMode(animationMode string, direction int, randomFrame bool) error {
err := ob.composite.SetMode(animationMode, "HTH") err := ob.composite.SetMode(animationMode, "HTH")
if err != nil { if err != nil {
return err return err
@ -74,6 +75,20 @@ func (ob *Object) setMode(animationMode string, direction int) error {
ob.composite.SetAnimSpeed(speed) ob.composite.SetAnimSpeed(speed)
} }
frameCount := ob.objectRecord.FrameCount[mode]
if frameCount != 0 {
ob.composite.SetSubLoop(0, frameCount)
}
ob.composite.SetPlayLoop(ob.objectRecord.CycleAnimation[mode])
ob.composite.SetCurrentFrame(ob.objectRecord.StartFrame[mode])
if randomFrame {
n := rand.Intn(frameCount)
ob.composite.SetCurrentFrame(n)
}
return err return err
} }