diff --git a/d2core/d2asset/composite.go b/d2core/d2asset/composite.go index 23047bb4..ce2b7b45 100644 --- a/d2core/d2asset/composite.go +++ b/d2core/d2asset/composite.go @@ -311,15 +311,15 @@ func (c *Composite) loadCompositeLayer(layerKey, layerValue, animationMode, weap } for _, animationPath := range animationPaths { - - if exists, err := c.FileExists(animationPath); exists && err == nil { - animation, err := c.LoadAnimationWithEffect(animationPath, palettePath, drawEffect) - if err == nil { - return animation, nil - } - } else { + exists, err := c.FileExists(animationPath) + if !exists || err != nil { return nil, fmt.Errorf("animation path '%s' not found: %v", animationPath, err) } + + animation, err := c.LoadAnimationWithEffect(animationPath, palettePath, drawEffect) + if err == nil { + return animation, nil + } } return nil, errors.New("animation not found") diff --git a/d2core/d2ui/button.go b/d2core/d2ui/button.go index 0cb8487c..9d4674d5 100644 --- a/d2core/d2ui/button.go +++ b/d2core/d2ui/button.go @@ -62,18 +62,18 @@ type ButtonLayout struct { ResourceName string PaletteName string FontPath string + ClickableRect *image.Rectangle XSegments int YSegments int BaseFrame int DisabledFrame int - ClickableRect *image.Rectangle TextOffset int - Toggleable bool - AllowFrameChange bool - HasImage bool FixedWidth int FixedHeight int LabelColor uint32 + Toggleable bool + AllowFrameChange bool + HasImage bool } const ( @@ -276,13 +276,14 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button { log.Print(err) return nil } + if buttonLayout.FixedWidth > 0 { btn.width = buttonLayout.FixedWidth } else { for i := 0; i < buttonLayout.XSegments; i++ { - w, _, err := buttonSprite.GetFrameSize(i) - if err != nil { - log.Print(err) + w, _, frameSizeErr := buttonSprite.GetFrameSize(i) + if frameSizeErr != nil { + log.Print(frameSizeErr) return nil } @@ -294,9 +295,9 @@ func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button { btn.height = buttonLayout.FixedHeight } else { for i := 0; i < buttonLayout.YSegments; i++ { - _, h, err := buttonSprite.GetFrameSize(i * buttonLayout.YSegments) - if err != nil { - log.Print(err) + _, h, frameSizeErr := buttonSprite.GetFrameSize(i * buttonLayout.YSegments) + if frameSizeErr != nil { + log.Print(frameSizeErr) return nil } diff --git a/d2game/d2gamescreen/select_hero_class.go b/d2game/d2gamescreen/select_hero_class.go index 133984e1..a969450c 100644 --- a/d2game/d2gamescreen/select_hero_class.go +++ b/d2game/d2gamescreen/select_hero_class.go @@ -21,6 +21,10 @@ import ( "github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype" ) +const ( + millisecondsPerSecond = 1000.0 +) + type heroRenderConfig struct { idleAnimationPath string idleSelectedAnimationPath string @@ -486,18 +490,19 @@ func (v *SelectHeroClass) onExitButtonClicked() { } func (v *SelectHeroClass) onOkButtonClicked() { - heroName := v.heroNameTextbox.GetText() defaultStats := v.asset.Records.Character.Stats[v.selectedHero] statsState := v.CreateHeroStatsState(v.selectedHero, defaultStats) playerState, err := v.CreateHeroState(heroName, v.selectedHero, statsState) - - if err := v.Save(playerState); err != nil { - fmt.Printf("failed to save game state!, err: %v\n", err) + if err != nil { + fmt.Printf("failed to create hero state!, err: %v\n", err) + return } + err = v.Save(playerState) if err != nil { + fmt.Printf("failed to save game state!, err: %v\n", err) return } @@ -776,7 +781,7 @@ func (v *SelectHeroClass) loadSprite(animationPath string, position image.Point, } if playLength != 0 { - sprite.SetPlayLength(float64(playLength) / 1000.0) + sprite.SetPlayLength(float64(playLength) / millisecondsPerSecond) } sprite.SetPosition(position.X, position.Y)