Composite work (#536)

* Quit using ObjectLookupRecord in composite

* Unexport SetMode in map entities

* Get rid of weaponClass from MapEntity

* Pass ObjectType to composite instead of string

* Use layer weaponclass from cof

* Manage more stuff directly in composite

* Explicitly index when picking equipment
This commit is contained in:
Ziemas 2020-07-04 04:52:50 +02:00 committed by GitHub
parent 4c3ff12cba
commit 6269726316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 153 additions and 190 deletions

View File

@ -4,6 +4,7 @@ package d2enum
type ObjectType int
const (
ObjectTypeCharacter ObjectType = iota + 1
ObjectTypePlayer ObjectType = iota
ObjectTypeCharacter
ObjectTypeItem
)

View File

@ -6,7 +6,6 @@ import (
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2cof"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
@ -14,14 +13,19 @@ import (
// Composite is a composite entity animation
type Composite struct {
object *d2datadict.ObjectLookupRecord
baseType d2enum.ObjectType
basePath string
token string
palettePath string
direction int
equipment [d2enum.CompositeTypeMax]string
mode *compositeMode
}
// CreateComposite creates a Composite from a given ObjectLookupRecord and palettePath.
func CreateComposite(object *d2datadict.ObjectLookupRecord, palettePath string) *Composite {
return &Composite{object: object, palettePath: palettePath}
func CreateComposite(baseType d2enum.ObjectType, token, palettePath string) *Composite {
return &Composite{baseType: baseType, basePath: baseString(baseType),
token: token, palettePath: palettePath}
}
// Advance moves the composite animation forward for a given elapsed time in nanoseconds.
@ -54,7 +58,8 @@ func (c *Composite) Render(target d2interface.Surface) error {
return nil
}
for _, layerIndex := range c.mode.drawOrder[c.mode.frameIndex] {
direction := d2cof.Dir64ToCof(c.direction, c.mode.cof.NumberOfDirections)
for _, layerIndex := range c.mode.cof.Priority[direction][c.mode.frameIndex] {
layer := c.mode.layers[layerIndex]
if layer != nil {
if err := layer.RenderFromOrigin(target); err != nil {
@ -67,17 +72,22 @@ func (c *Composite) Render(target d2interface.Surface) error {
}
// GetAnimationMode returns the animation mode the Composite should render with.
func (c Composite) GetAnimationMode() string {
func (c *Composite) GetAnimationMode() string {
return c.mode.animationMode
}
// GetWeaponClass returns the currently loaded weapon class
func (c *Composite) GetWeaponClass() string {
return c.mode.weaponClass
}
// SetMode sets the Composite's animation mode weapon class and direction
func (c *Composite) SetMode(animationMode, weaponClass string, direction int) error {
if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass && c.mode.cofDirection == direction {
func (c *Composite) SetMode(animationMode, weaponClass string) error {
if c.mode != nil && c.mode.animationMode == animationMode && c.mode.weaponClass == weaponClass {
return nil
}
mode, err := c.createMode(animationMode, weaponClass, direction)
mode, err := c.createMode(animationMode, weaponClass)
if err != nil {
return err
}
@ -88,8 +98,26 @@ func (c *Composite) SetMode(animationMode, weaponClass string, direction int) er
return nil
}
// SetSpeed sets the speed at which the Composite's animation should advance through its frames
func (c *Composite) SetSpeed(speed int) {
// Equip changes the current layer configuration
func (c *Composite) Equip(equipment *[d2enum.CompositeTypeMax]string) error {
c.equipment = *equipment
if c.mode == nil {
return nil
}
mode, err := c.createMode(c.mode.animationMode, c.mode.weaponClass)
if err != nil {
return err
}
c.mode = mode
return nil
}
// SetAnimSpeed sets the speed at which the Composite's animation should advance through its frames
func (c *Composite) SetAnimSpeed(speed int) {
c.mode.animationSpeed = 1.0 / ((float64(speed) * 25.0) / 256.0)
for layerIdx := range c.mode.layers {
layer := c.mode.layers[layerIdx]
@ -99,13 +127,20 @@ func (c *Composite) SetSpeed(speed int) {
}
}
// GetDirectionCount returns the Composites number of available animated directions
func (c *Composite) GetDirectionCount() int {
if c.mode == nil {
return 0
// SetDirection sets the direction of the composite and its layers
func (c *Composite) SetDirection(direction int) {
c.direction = direction
for layerIdx := range c.mode.layers {
layer := c.mode.layers[layerIdx]
if layer != nil {
layer.SetDirection(c.direction)
}
}
}
return c.mode.directionCount
// Direction returns the current direction the composite is facing
func (c *Composite) GetDirection() int {
return c.direction
}
// GetPlayedCount returns the number of times the current animation mode has completed all its distinct frames
@ -124,14 +159,12 @@ func (c *Composite) resetPlayedCount() {
}
type compositeMode struct {
animationMode string
weaponClass string
cofDirection int
directionCount int
playedCount int
cof *d2cof.COF
animationMode string
weaponClass string
playedCount int
layers []*Animation
drawOrder [][]d2enum.CompositeType
layers []*Animation
frameCount int
frameIndex int
@ -139,8 +172,8 @@ type compositeMode struct {
lastFrameTime float64
}
func (c *Composite) createMode(animationMode, weaponClass string, direction int) (*compositeMode, error) {
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.object.Base, c.object.Token, c.object.Token, animationMode, weaponClass)
func (c *Composite) createMode(animationMode, weaponClass string) (*compositeMode, error) {
cofPath := fmt.Sprintf("%s/%s/COF/%s%s%s.COF", c.basePath, c.token, c.token, animationMode, weaponClass)
if exists, _ := FileExists(cofPath); !exists {
return nil, errors.New("composite not found")
}
@ -150,7 +183,7 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
return nil, err
}
animationKey := strings.ToLower(c.object.Token + animationMode + weaponClass)
animationKey := strings.ToLower(c.token + animationMode + weaponClass)
animationData := d2data.AnimationData[animationKey]
if len(animationData) == 0 {
@ -158,62 +191,23 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
}
mode := &compositeMode{
cof: cof,
animationMode: animationMode,
weaponClass: weaponClass,
directionCount: cof.NumberOfDirections,
cofDirection: d2cof.Dir64ToCof(direction, cof.NumberOfDirections),
layers: make([]*Animation, d2enum.CompositeTypeMax),
frameCount: animationData[0].FramesPerDirection,
animationSpeed: 1.0 / ((float64(animationData[0].AnimationSpeed) * 25.0) / 256.0),
}
mode.drawOrder = make([][]d2enum.CompositeType, mode.frameCount)
for frame := 0; frame < mode.frameCount; frame++ {
mode.drawOrder[frame] = cof.Priority[mode.cofDirection][frame]
}
for _, cofLayer := range cof.CofLayers {
var layerValue string
switch cofLayer.Type {
case d2enum.CompositeTypeHead:
layerValue = c.object.HD
case d2enum.CompositeTypeTorso:
layerValue = c.object.TR
case d2enum.CompositeTypeLegs:
layerValue = c.object.LG
case d2enum.CompositeTypeRightArm:
layerValue = c.object.RA
case d2enum.CompositeTypeLeftArm:
layerValue = c.object.LA
case d2enum.CompositeTypeRightHand:
layerValue = c.object.RH
case d2enum.CompositeTypeLeftHand:
layerValue = c.object.LH
case d2enum.CompositeTypeShield:
layerValue = c.object.SH
case d2enum.CompositeTypeSpecial1:
layerValue = c.object.S1
case d2enum.CompositeTypeSpecial2:
layerValue = c.object.S2
case d2enum.CompositeTypeSpecial3:
layerValue = c.object.S3
case d2enum.CompositeTypeSpecial4:
layerValue = c.object.S4
case d2enum.CompositeTypeSpecial5:
layerValue = c.object.S5
case d2enum.CompositeTypeSpecial6:
layerValue = c.object.S6
case d2enum.CompositeTypeSpecial7:
layerValue = c.object.S7
case d2enum.CompositeTypeSpecial8:
layerValue = c.object.S8
default:
return nil, errors.New("unknown layer type")
layerValue := c.equipment[cofLayer.Type]
if layerValue == "" {
layerValue = "lit"
}
blend := false
transparency := 255
if cofLayer.Transparent {
switch cofLayer.DrawEffect {
case d2enum.DrawEffectPctTransparency25:
@ -227,14 +221,17 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
}
}
layer, err := loadCompositeLayer(c.object, cofLayer.Type.String(), layerValue, animationMode, weaponClass, c.palettePath, transparency)
layer, err := c.loadCompositeLayer(cofLayer.Type.String(), layerValue, animationMode,
cofLayer.WeaponClass.String(), c.palettePath, transparency)
if err == nil {
layer.SetPlaySpeed(mode.animationSpeed)
layer.PlayForward()
layer.SetBlend(blend)
if err := layer.SetDirection(direction); err != nil {
if err := layer.SetDirection(c.direction); err != nil {
return nil, err
}
mode.layers[cofLayer.Type] = layer
}
}
@ -242,12 +239,11 @@ func (c *Composite) createMode(animationMode, weaponClass string, direction int)
return mode, nil
}
func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerValue, animationMode, weaponClass, palettePath string, transparency int) (*Animation, error) {
func (c *Composite) loadCompositeLayer(layerKey, layerValue, animationMode, weaponClass,
palettePath string, transparency int) (*Animation, error) {
animationPaths := []string{
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, weaponClass),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, "HTH"),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, weaponClass),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", object.Base, object.Token, layerKey, object.Token, layerKey, layerValue, animationMode, "HTH"),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dcc", c.basePath, c.token, layerKey, c.token, layerKey, layerValue, animationMode, weaponClass),
fmt.Sprintf("%s/%s/%s/%s%s%s%s%s.dc6", c.basePath, c.token, layerKey, c.token, layerKey, layerValue, animationMode, weaponClass),
}
for _, animationPath := range animationPaths {
@ -261,3 +257,16 @@ func loadCompositeLayer(object *d2datadict.ObjectLookupRecord, layerKey, layerVa
return nil, errors.New("animation not found")
}
func baseString(baseType d2enum.ObjectType) string {
switch baseType {
case d2enum.ObjectTypePlayer:
return "/data/global/chars"
case d2enum.ObjectTypeCharacter:
return "/data/global/monsters"
case d2enum.ObjectTypeItem:
return "/data/global/objects"
default:
return ""
}
}

View File

@ -3,7 +3,7 @@ package d2asset
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2dat"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2mpq"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
@ -121,8 +121,8 @@ func LoadAnimationWithTransparency(animationPath, palettePath string, transparen
}
// LoadComposite creates a composite object from a ObjectLookupRecord and palettePath describing it
func LoadComposite(object *d2datadict.ObjectLookupRecord, palettePath string) (*Composite, error) {
return CreateComposite(object, palettePath), nil
func LoadComposite(baseType d2enum.ObjectType, token, palettePath string) (*Composite, error) {
return CreateComposite(baseType, token, palettePath), nil
}
// LoadFont loads a font the resource files

View File

@ -26,7 +26,6 @@ type mapEntity struct {
LocationY float64
TileX, TileY int // Coordinates of the tile the unit is within
subcellX, subcellY float64 // Subcell coordinates within the current tile
weaponClass string
offsetX, offsetY int
TargetX float64
TargetY float64

View File

@ -21,8 +21,6 @@ type NPC struct {
path int
isDone bool
repetitions int
direction int
objectLookup *d2datadict.ObjectLookupRecord
monstatRecord *d2datadict.MonStatsRecord
monstatEx *d2datadict.MonStats2Record
name string
@ -36,29 +34,32 @@ func CreateNPC(x, y int, monstat *d2datadict.MonStatsRecord, direction int) *NPC
monstatEx: d2datadict.MonStats2[monstat.ExtraDataKey],
}
object := &d2datadict.ObjectLookupRecord{
Base: "/Data/Global/Monsters",
Token: monstat.AnimationDirectoryToken,
Mode: result.monstatEx.ResurrectMode.String(),
Class: result.monstatEx.BaseWeaponClass,
TR: selectEquip(result.monstatEx.TRv),
LG: selectEquip(result.monstatEx.LGv),
RH: selectEquip(result.monstatEx.RHv),
SH: selectEquip(result.monstatEx.SHv),
RA: selectEquip(result.monstatEx.Rav),
LA: selectEquip(result.monstatEx.Lav),
LH: selectEquip(result.monstatEx.LHv),
HD: selectEquip(result.monstatEx.HDv),
equipment := &[d2enum.CompositeTypeMax]string{
d2enum.CompositeTypeHead: selectEquip(result.monstatEx.HDv),
d2enum.CompositeTypeTorso: selectEquip(result.monstatEx.TRv),
d2enum.CompositeTypeLegs: selectEquip(result.monstatEx.LGv),
d2enum.CompositeTypeRightArm: selectEquip(result.monstatEx.Rav),
d2enum.CompositeTypeLeftArm: selectEquip(result.monstatEx.Lav),
d2enum.CompositeTypeRightHand: selectEquip(result.monstatEx.RHv),
d2enum.CompositeTypeLeftHand: selectEquip(result.monstatEx.LHv),
d2enum.CompositeTypeShield: selectEquip(result.monstatEx.SHv),
d2enum.CompositeTypeSpecial1: selectEquip(result.monstatEx.S1v),
d2enum.CompositeTypeSpecial2: selectEquip(result.monstatEx.S2v),
d2enum.CompositeTypeSpecial3: selectEquip(result.monstatEx.S3v),
d2enum.CompositeTypeSpecial4: selectEquip(result.monstatEx.S4v),
d2enum.CompositeTypeSpecial5: selectEquip(result.monstatEx.S5v),
d2enum.CompositeTypeSpecial6: selectEquip(result.monstatEx.S6v),
d2enum.CompositeTypeSpecial7: selectEquip(result.monstatEx.S7v),
d2enum.CompositeTypeSpecial8: selectEquip(result.monstatEx.S8v),
}
result.objectLookup = object
composite, err := d2asset.LoadComposite(object, d2resource.PaletteUnits)
composite, _ := d2asset.LoadComposite(d2enum.ObjectTypeCharacter, monstat.AnimationDirectoryToken,
d2resource.PaletteUnits)
result.composite = composite
if err != nil {
panic(err)
}
composite.SetMode("NU", result.monstatEx.BaseWeaponClass)
composite.Equip(equipment)
result.SetMode(object.Mode, object.Class, direction)
result.mapEntity.directioner = result.rotate
if result.monstatRecord != nil && result.monstatRecord.IsInteractable {
@ -76,7 +77,6 @@ func selectEquip(slice []string) string {
return ""
}
func (v *NPC) Render(target d2interface.Surface) {
target.PushTranslation(
v.offsetX+int((v.subcellX-v.subcellY)*16),
@ -148,7 +148,7 @@ func (v *NPC) next() {
}
if v.composite.GetAnimationMode() != newAnimationMode.String() {
v.SetMode(newAnimationMode.String(), v.weaponClass, v.direction)
v.composite.SetMode(newAnimationMode.String(), v.composite.GetWeaponClass())
}
}
@ -160,23 +160,14 @@ func (v *NPC) rotate(direction int) {
} else {
newMode = d2enum.AnimationModeMonsterNeutral
}
if newMode.String() != v.composite.GetAnimationMode() || direction != v.direction {
v.SetMode(newMode.String(), v.weaponClass, direction)
}
}
// SetMode changes the graphical mode of this animated entity
func (v *NPC) SetMode(animationMode, weaponClass string, direction int) error {
v.direction = direction
v.weaponClass = weaponClass
err := v.composite.SetMode(animationMode, weaponClass, direction)
if err != nil {
err = v.composite.SetMode(animationMode, "HTH", direction)
v.weaponClass = "HTH"
if newMode.String() != v.composite.GetAnimationMode() {
v.composite.SetMode(newMode.String(), v.composite.GetWeaponClass())
}
return err
if v.composite.GetDirection() != direction {
v.composite.SetDirection(direction)
}
}
func (m *NPC) Selectable() bool {

View File

@ -4,6 +4,7 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
)
@ -28,32 +29,8 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
// nameLabel: d2ui.CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteStatic),
}
object := &d2datadict.ObjectLookupRecord{
Base: "/Data/Global/Objects",
Token: entity.objectType.Token,
Mode: "NU",
Class: "HTH",
HD: "LIT",
TR: "LIT",
LG: "LIT",
RA: "LIT",
LA: "LIT",
RH: "LIT",
LH: "LIT",
SH: "LIT",
S1: "LIT",
S2: "LIT",
S3: "LIT",
S4: "LIT",
S5: "LIT",
S6: "LIT",
S7: "LIT",
S8: "LIT",
}
entity.objectLookup = object
composite, err := d2asset.LoadComposite(object, palettePath)
composite, err := d2asset.LoadComposite(d2enum.ObjectTypeItem, entity.objectType.Token,
d2resource.PaletteUnits)
if err != nil {
return nil, err
}
@ -63,36 +40,35 @@ func CreateObject(x, y int, objectRec *d2datadict.ObjectRecord, palettePath stri
entity.mapEntity.directioner = entity.rotate
entity.drawLayer = entity.objectRecord.OrderFlag[d2enum.AnimationModeObjectNeutral]
entity.SetMode(object.Mode, object.Class, 0)
entity.setMode("NU", 0)
// stop torches going crazy for now
// need initFunc handling to set objects up properly
if objectRec.HasAnimationMode[d2enum.AnimationModeObjectOpened] {
entity.SetMode("ON", "HTH", 0)
entity.setMode("ON", 0)
}
return entity, nil
}
// SetMode changes the graphical mode of this animated entity
func (ob *Object) SetMode(animationMode, weaponClass string, direction int) error {
ob.composite.SetMode(animationMode, weaponClass, direction)
// setMode changes the graphical mode of this animated entity
func (ob *Object) setMode(animationMode string, direction int) error {
ob.direction = direction
ob.weaponClass = weaponClass
err := ob.composite.SetMode(animationMode, weaponClass, direction)
err := ob.composite.SetMode(animationMode, "HTH")
if err != nil {
err = ob.composite.SetMode(animationMode, "HTH", direction)
ob.weaponClass = "HTH"
return err
}
ob.composite.SetDirection(direction)
mode := d2enum.ObjectAnimationModeFromString(animationMode)
ob.mapEntity.drawLayer = ob.objectRecord.OrderFlag[mode]
// For objects their txt record entry overrides animationdata
speed := ob.objectRecord.FrameDelta[mode]
if speed != 0 {
ob.composite.SetSpeed(speed)
ob.composite.SetAnimSpeed(speed)
}
return err

View File

@ -18,7 +18,6 @@ type Player struct {
Stats d2hero.HeroStatsState
Class d2enum.Hero
Id string
direction int
name string
// nameLabel d2ui.Label
lastPathSize int
@ -34,23 +33,19 @@ var baseWalkSpeed = 6.0
var baseRunSpeed = 9.0
func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero, stats d2hero.HeroStatsState, equipment d2inventory.CharacterEquipment) *Player {
object := &d2datadict.ObjectLookupRecord{
Mode: d2enum.AnimationModePlayerTownNeutral.String(),
Base: "/data/global/chars",
Token: heroType.GetToken(),
Class: equipment.RightHand.GetWeaponClass(),
SH: equipment.Shield.GetItemCode(),
// TODO: Offhand class?
HD: equipment.Head.GetArmorClass(),
TR: equipment.Torso.GetArmorClass(),
LG: equipment.Legs.GetArmorClass(),
RA: equipment.RightArm.GetArmorClass(),
LA: equipment.LeftArm.GetArmorClass(),
RH: equipment.RightHand.GetItemCode(),
LH: equipment.LeftHand.GetItemCode(),
layerEquipment := &[d2enum.CompositeTypeMax]string{
d2enum.CompositeTypeHead: equipment.Head.GetArmorClass(),
d2enum.CompositeTypeTorso: equipment.Torso.GetArmorClass(),
d2enum.CompositeTypeLegs: equipment.Legs.GetArmorClass(),
d2enum.CompositeTypeRightArm: equipment.RightArm.GetArmorClass(),
d2enum.CompositeTypeLeftArm: equipment.LeftArm.GetArmorClass(),
d2enum.CompositeTypeRightHand: equipment.RightHand.GetItemCode(),
d2enum.CompositeTypeLeftHand: equipment.LeftHand.GetItemCode(),
d2enum.CompositeTypeShield: equipment.Shield.GetItemCode(),
}
composite, err := d2asset.LoadComposite(object, d2resource.PaletteUnits)
composite, err := d2asset.LoadComposite(d2enum.ObjectTypePlayer, heroType.GetToken(),
d2resource.PaletteUnits)
if err != nil {
panic(err)
}
@ -64,7 +59,6 @@ func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero
composite: composite,
Equipment: equipment,
Stats: stats,
direction: direction,
name: name,
Class: heroType,
//nameLabel: d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic),
@ -77,10 +71,13 @@ func CreatePlayer(id, name string, x, y int, direction int, heroType d2enum.Hero
//result.nameLabel.Alignment = d2ui.LabelAlignCenter
//result.nameLabel.SetText(name)
//result.nameLabel.Color = color.White
err = result.SetMode(d2enum.AnimationModePlayerTownNeutral.String(), equipment.RightHand.GetWeaponClass(), direction)
err = composite.SetMode(d2enum.AnimationModePlayerTownNeutral.String(), equipment.RightHand.GetWeaponClass())
if err != nil {
panic(err)
}
composite.SetDirection(direction)
composite.Equip(layerEquipment)
return result
}
@ -142,20 +139,6 @@ func (v *Player) Render(target d2interface.Surface) {
//v.nameLabel.Render(target)
}
func (v *Player) SetMode(animationMode, weaponClass string, direction int) error {
v.composite.SetMode(animationMode, weaponClass, direction)
v.direction = direction
v.weaponClass = weaponClass
err := v.composite.SetMode(animationMode, weaponClass, direction)
if err != nil {
err = v.composite.SetMode(animationMode, "HTH", direction)
v.weaponClass = "HTH"
}
return err
}
func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
if v.IsRunning() && !v.IsAtTarget() {
return d2enum.AnimationModePlayerRun
@ -181,15 +164,19 @@ func (v *Player) GetAnimationMode() d2enum.PlayerAnimationMode {
}
func (v *Player) SetAnimationMode(animationMode string) error {
return v.composite.SetMode(animationMode, v.weaponClass, v.direction)
return v.composite.SetMode(animationMode, v.composite.GetWeaponClass())
}
// rotate sets direction and changes animation
func (v *Player) rotate(direction int) {
newAnimationMode := v.GetAnimationMode().String()
if newAnimationMode != v.composite.GetAnimationMode() || direction != v.direction {
v.SetMode(newAnimationMode, v.weaponClass, direction)
if newAnimationMode != v.composite.GetAnimationMode() {
v.composite.SetMode(newAnimationMode, v.composite.GetWeaponClass())
}
if direction != v.composite.GetDirection() {
v.composite.SetDirection(direction)
}
}