mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 07:27:19 -05:00
More linting (#500)
This commit is contained in:
parent
4938ec1f44
commit
e2572b8745
@ -1,11 +1,21 @@
|
||||
package d2enum
|
||||
|
||||
// AnimationFrame represents a single frame of animation.
|
||||
type AnimationFrame int
|
||||
|
||||
const (
|
||||
AnimationFrameNoEvent AnimationFrame = 0
|
||||
AnimationFrameAttack AnimationFrame = 1
|
||||
AnimationFrameMissile AnimationFrame = 2
|
||||
AnimationFrameSound AnimationFrame = 3
|
||||
AnimationFrameSkill AnimationFrame = 4
|
||||
// AnimationFrameNoEvent represents an animation frame with no event
|
||||
AnimationFrameNoEvent AnimationFrame = iota
|
||||
|
||||
// AnimationFrameAttack represents an animation frame with an attack event
|
||||
AnimationFrameAttack
|
||||
|
||||
// AnimationFrameMissile represents an animation frame with a missile event
|
||||
AnimationFrameMissile
|
||||
|
||||
// AnimationFrameSound represents an animation frame with a sound event
|
||||
AnimationFrameSound
|
||||
|
||||
// AnimationFrameSkill represents an animation frame with a skill event
|
||||
AnimationFrameSkill
|
||||
)
|
||||
|
@ -1,58 +1,150 @@
|
||||
package d2enum
|
||||
|
||||
// PlayerAnimationMode represents player animation modes
|
||||
type PlayerAnimationMode int
|
||||
|
||||
// MonsterAnimationMode represents monster animation modes
|
||||
type MonsterAnimationMode int
|
||||
|
||||
// ObjectAnimationMode represents object animation modes
|
||||
type ObjectAnimationMode int
|
||||
|
||||
const (
|
||||
AnimationModePlayerDeath PlayerAnimationMode = iota // DT
|
||||
AnimationModePlayerNeutral // NU
|
||||
AnimationModePlayerWalk // WL
|
||||
AnimationModePlayerRun // RN
|
||||
AnimationModePlayerGetHit // GH
|
||||
AnimationModePlayerTownNeutral // TN
|
||||
AnimationModePlayerTownWalk // TW
|
||||
AnimationModePlayerAttack1 // A1
|
||||
AnimationModePlayerAttack2 // A2
|
||||
AnimationModePlayerBlock // BL
|
||||
AnimationModePlayerCast // SC
|
||||
AnimationModePlayerThrow // TH
|
||||
AnimationModePlayerKick // KK
|
||||
AnimationModePlayerSkill1 // S1
|
||||
AnimationModePlayerSkill2 // S2
|
||||
AnimationModePlayerSkill3 // S3
|
||||
AnimationModePlayerSkill4 // S4
|
||||
AnimationModePlayerDead // DD
|
||||
AnimationModePlayerSequence // GH
|
||||
AnimationModePlayerKnockBack // GH
|
||||
// AnimationModePlayerDeath represents DT
|
||||
AnimationModePlayerDeath PlayerAnimationMode = iota
|
||||
|
||||
// AnimationModePlayerNeutral represents NU
|
||||
AnimationModePlayerNeutral
|
||||
|
||||
// AnimationModePlayerWalk represents WL
|
||||
AnimationModePlayerWalk
|
||||
|
||||
// AnimationModePlayerRun represents RN
|
||||
AnimationModePlayerRun
|
||||
|
||||
// AnimationModePlayerGetHit represents GH
|
||||
AnimationModePlayerGetHit
|
||||
|
||||
// AnimationModePlayerTownNeutral represents TN
|
||||
AnimationModePlayerTownNeutral
|
||||
|
||||
// AnimationModePlayerTownWalk represents TW
|
||||
AnimationModePlayerTownWalk
|
||||
|
||||
// AnimationModePlayerAttack1 represents A1
|
||||
AnimationModePlayerAttack1
|
||||
|
||||
// AnimationModePlayerAttack2 represents A2
|
||||
AnimationModePlayerAttack2
|
||||
|
||||
// AnimationModePlayerBlock represents BL
|
||||
AnimationModePlayerBlock
|
||||
|
||||
// AnimationModePlayerCast represents SC
|
||||
AnimationModePlayerCast
|
||||
|
||||
// AnimationModePlayerThrow represents TH
|
||||
AnimationModePlayerThrow
|
||||
|
||||
// AnimationModePlayerKick represents KK
|
||||
AnimationModePlayerKick
|
||||
|
||||
// AnimationModePlayerSkill1 represents S1
|
||||
AnimationModePlayerSkill1
|
||||
|
||||
// AnimationModePlayerSkill2 represents S2
|
||||
AnimationModePlayerSkill2
|
||||
|
||||
// AnimationModePlayerSkill3 represents S3
|
||||
AnimationModePlayerSkill3
|
||||
|
||||
// AnimationModePlayerSkill4 represents S4
|
||||
AnimationModePlayerSkill4
|
||||
|
||||
// AnimationModePlayerDead represents DD
|
||||
AnimationModePlayerDead
|
||||
|
||||
// AnimationModePlayerSequence represents GH
|
||||
AnimationModePlayerSequence
|
||||
|
||||
// AnimationModePlayerKnockBack represents GH
|
||||
AnimationModePlayerKnockBack
|
||||
)
|
||||
const (
|
||||
AnimationModeMonsterDeath MonsterAnimationMode = iota // DT
|
||||
AnimationModeMonsterNeutral // NU
|
||||
AnimationModeMonsterWalk // WL
|
||||
AnimationModeMonsterGetHit // GH
|
||||
AnimationModeMonsterAttack1 // A1
|
||||
AnimationModeMonsterAttack2 // A2
|
||||
AnimationModeMonsterBlock // BL
|
||||
AnimationModeMonsterCast // SC
|
||||
AnimationModeMonsterSkill1 // S1
|
||||
AnimationModeMonsterSkill2 // S2
|
||||
AnimationModeMonsterSkill3 // S3
|
||||
AnimationModeMonsterSkill4 // S4
|
||||
AnimationModeMonsterDead // DD
|
||||
AnimationModeMonsterKnockback // GH
|
||||
AnimationModeMonsterSequence // xx
|
||||
AnimationModeMonsterRun // RN
|
||||
|
||||
// AnimationModeMonsterDeath represents DT
|
||||
AnimationModeMonsterDeath MonsterAnimationMode = iota
|
||||
|
||||
// AnimationModeMonsterNeutral represents NU
|
||||
AnimationModeMonsterNeutral
|
||||
|
||||
// AnimationModeMonsterWalk represents WL
|
||||
AnimationModeMonsterWalk
|
||||
|
||||
// AnimationModeMonsterGetHit represents GH
|
||||
AnimationModeMonsterGetHit
|
||||
|
||||
// AnimationModeMonsterAttack1 represents A1
|
||||
AnimationModeMonsterAttack1
|
||||
|
||||
// AnimationModeMonsterAttack2 represents A2
|
||||
AnimationModeMonsterAttack2
|
||||
|
||||
// AnimationModeMonsterBlock represents BL
|
||||
AnimationModeMonsterBlock
|
||||
|
||||
// AnimationModeMonsterCast represents SC
|
||||
AnimationModeMonsterCast
|
||||
|
||||
// AnimationModeMonsterSkill1 represents S1
|
||||
AnimationModeMonsterSkill1
|
||||
|
||||
// AnimationModeMonsterSkill2 represents S2
|
||||
AnimationModeMonsterSkill2
|
||||
|
||||
// AnimationModeMonsterSkill3 represents S3
|
||||
AnimationModeMonsterSkill3
|
||||
|
||||
// AnimationModeMonsterSkill4 represents S4
|
||||
AnimationModeMonsterSkill4
|
||||
|
||||
// AnimationModeMonsterDead represents DD
|
||||
AnimationModeMonsterDead
|
||||
|
||||
// AnimationModeMonsterKnockback represents GH
|
||||
AnimationModeMonsterKnockback
|
||||
|
||||
// AnimationModeMonsterSequence represents xx
|
||||
AnimationModeMonsterSequence
|
||||
|
||||
// AnimationModeMonsterRun represents RN
|
||||
AnimationModeMonsterRun
|
||||
)
|
||||
const (
|
||||
AnimationModeObjectNeutral ObjectAnimationMode = iota // NU
|
||||
AnimationModeObjectOperating // OP
|
||||
AnimationModeObjectOpened // ON
|
||||
AnimationModeObjectSpecial1 // S1
|
||||
AnimationModeObjectSpecial2 // S2
|
||||
AnimationModeObjectSpecial3 // S3
|
||||
AnimationModeObjectSpecial4 // S4
|
||||
AnimationModeObjectSpecial5 // S5
|
||||
|
||||
// AnimationModeObjectNeutral represents NU
|
||||
AnimationModeObjectNeutral ObjectAnimationMode = iota
|
||||
|
||||
// AnimationModeObjectOperating represents OP
|
||||
AnimationModeObjectOperating
|
||||
|
||||
// AnimationModeObjectOpened represents ON
|
||||
AnimationModeObjectOpened
|
||||
|
||||
// AnimationModeObjectSpecial1 represents S1
|
||||
AnimationModeObjectSpecial1
|
||||
|
||||
// AnimationModeObjectSpecial2 represents S2
|
||||
AnimationModeObjectSpecial2
|
||||
|
||||
// AnimationModeObjectSpecial3 represents S3
|
||||
AnimationModeObjectSpecial3
|
||||
|
||||
// AnimationModeObjectSpecial4 represents S4
|
||||
AnimationModeObjectSpecial4
|
||||
|
||||
// AnimationModeObjectSpecial5 represents S5
|
||||
AnimationModeObjectSpecial5
|
||||
)
|
||||
|
||||
//go:generate stringer -linecomment -type PlayerAnimationMode
|
||||
|
47
d2common/d2enum/composite_mode.go
Normal file
47
d2common/d2enum/composite_mode.go
Normal file
@ -0,0 +1,47 @@
|
||||
package d2enum
|
||||
|
||||
// CompositeMode defines the composite mode
|
||||
type CompositeMode int
|
||||
|
||||
const (
|
||||
// CompositeModeSourceOver applies a composite based on:
|
||||
// c_out = c_src + c_dst × (1 - α_src) (Regular alpha blending)
|
||||
CompositeModeSourceOver CompositeMode = iota + 1
|
||||
|
||||
// CompositeModeClear applies a composite based on: c_out = 0
|
||||
CompositeModeClear
|
||||
|
||||
// CompositeModeCopy applies a composite based on: c_out = c_src
|
||||
CompositeModeCopy
|
||||
|
||||
// CompositeModeDestination applies a composite based on: c_out = c_dst
|
||||
CompositeModeDestination
|
||||
|
||||
// CompositeModeDestinationOver applies a composite based on: c_out = c_src × (1 - α_dst) + c_dst
|
||||
CompositeModeDestinationOver
|
||||
|
||||
// CompositeModeSourceIn applies a composite based on: c_out = c_src × α_dst
|
||||
CompositeModeSourceIn
|
||||
|
||||
// CompositeModeDestinationIn applies a composite based on: c_out = c_dst × α_src
|
||||
CompositeModeDestinationIn
|
||||
|
||||
// CompositeModeSourceOut applies a composite based on: c_out = c_src × (1 - α_dst)
|
||||
CompositeModeSourceOut
|
||||
|
||||
// CompositeModeDestinationOut applies a composite based on: c_out = c_dst × (1 - α_src)
|
||||
CompositeModeDestinationOut
|
||||
|
||||
// CompositeModeSourceAtop applies a composite based on: c_out = c_src × α_dst + c_dst × (1 - α_src)
|
||||
CompositeModeSourceAtop
|
||||
|
||||
// CompositeModeDestinationAtop applies a composite based on: c_out = c_src × (1 - α_dst) + c_dst × α_src
|
||||
CompositeModeDestinationAtop
|
||||
|
||||
// CompositeModeXor applies a composite based on: c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
||||
CompositeModeXor
|
||||
|
||||
// CompositeModeLighter applies a composite based on:
|
||||
// c_out = c_src + c_dst Sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
CompositeModeLighter
|
||||
)
|
@ -1,23 +1,58 @@
|
||||
package d2enum
|
||||
|
||||
// CompositeType represents a composite type
|
||||
type CompositeType int
|
||||
|
||||
const (
|
||||
CompositeTypeHead CompositeType = 0
|
||||
CompositeTypeTorso CompositeType = 1
|
||||
CompositeTypeLegs CompositeType = 2
|
||||
CompositeTypeRightArm CompositeType = 3
|
||||
CompositeTypeLeftArm CompositeType = 4
|
||||
CompositeTypeRightHand CompositeType = 5
|
||||
CompositeTypeLeftHand CompositeType = 6
|
||||
CompositeTypeShield CompositeType = 7
|
||||
CompositeTypeSpecial1 CompositeType = 8
|
||||
CompositeTypeSpecial2 CompositeType = 9
|
||||
CompositeTypeSpecial3 CompositeType = 10
|
||||
CompositeTypeSpecial4 CompositeType = 11
|
||||
CompositeTypeSpecial5 CompositeType = 12
|
||||
CompositeTypeSpecial6 CompositeType = 13
|
||||
CompositeTypeSpecial7 CompositeType = 14
|
||||
CompositeTypeSpecial8 CompositeType = 15
|
||||
CompositeTypeMax CompositeType = 16
|
||||
|
||||
// CompositeTypeHead is a composite type for heads
|
||||
CompositeTypeHead CompositeType = iota
|
||||
|
||||
// CompositeTypeTorso is a composite type for torsos
|
||||
CompositeTypeTorso
|
||||
|
||||
// CompositeTypeLegs is a composite type for legs
|
||||
CompositeTypeLegs
|
||||
|
||||
// CompositeTypeRightArm is a composite type for right arms
|
||||
CompositeTypeRightArm
|
||||
|
||||
// CompositeTypeLeftArm is a composite type for left arms
|
||||
CompositeTypeLeftArm
|
||||
|
||||
// CompositeTypeRightHand is a composite type for right hands
|
||||
CompositeTypeRightHand
|
||||
|
||||
// CompositeTypeLeftHand is a composite type for left hands
|
||||
CompositeTypeLeftHand
|
||||
|
||||
// CompositeTypeShield is a composite type for shields
|
||||
CompositeTypeShield
|
||||
|
||||
// CompositeTypeSpecial1 is a composite type for special type 1s
|
||||
CompositeTypeSpecial1
|
||||
|
||||
// CompositeTypeSpecial2 is a composite type for special type 2s
|
||||
CompositeTypeSpecial2
|
||||
|
||||
// CompositeTypeSpecial3 is a composite type for special type 3s
|
||||
CompositeTypeSpecial3
|
||||
|
||||
// CompositeTypeSpecial4 is a composite type for special type 4s
|
||||
CompositeTypeSpecial4
|
||||
|
||||
// CompositeTypeSpecial5 is a composite type for special type 5s
|
||||
CompositeTypeSpecial5
|
||||
|
||||
// CompositeTypeSpecial6 is a composite type for special type 6s
|
||||
CompositeTypeSpecial6
|
||||
|
||||
// CompositeTypeSpecial7 is a composite type for special type 7s
|
||||
CompositeTypeSpecial7
|
||||
|
||||
// CompositeTypeSpecial8 is a composite type for special type 8s
|
||||
CompositeTypeSpecial8
|
||||
|
||||
// CompositeTypeMax is used to determine the max number of composite types
|
||||
CompositeTypeMax
|
||||
)
|
||||
|
@ -1,15 +1,40 @@
|
||||
package d2enum
|
||||
|
||||
// DrawEffect is a draw effect
|
||||
type DrawEffect int
|
||||
|
||||
// Names courtesy of Necrolis
|
||||
const (
|
||||
DrawEffectPctTransparency25 = 0 //GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 25 % transparency (colormaps 49-304 in a .pl2)
|
||||
DrawEffectPctTransparency50 = 1 //GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 50 % transparency (colormaps 305-560 in a .pl2)
|
||||
DrawEffectPctTransparency75 = 2 //GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 75 % transparency (colormaps 561-816 in a .pl2)
|
||||
DrawEffectModulate = 3 //GL_MODULATE; GL_SRC_ALPHA, GL_DST_ALPHA (colormaps 817-1072 in a .pl2)
|
||||
DrawEffectBurn = 4 //GL_MODULATE; GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA (colormaps 1073-1328 in a .pl2)
|
||||
DrawEffectNormal = 5 //GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
DrawEffectMod2XTrans = 6 //GL_MODULATE; GL_SRC_COLOR, GL_DST_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
DrawEffectMod2X = 7 //GL_COMBINE_ARB; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
|
||||
// DrawEffectPctTransparency25 is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 25 % transparency (colormaps 49-304 in a .pl2)
|
||||
DrawEffectPctTransparency25 = iota
|
||||
|
||||
// DrawEffectPctTransparency50 is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 50 % transparency (colormaps 305-560 in a .pl2)
|
||||
DrawEffectPctTransparency50
|
||||
|
||||
// DrawEffectPctTransparency75 is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA 75 % transparency (colormaps 561-816 in a .pl2)
|
||||
DrawEffectPctTransparency75
|
||||
|
||||
// DrawEffectModulate is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_ALPHA, GL_DST_ALPHA (colormaps 817-1072 in a .pl2)
|
||||
DrawEffectModulate
|
||||
|
||||
// DrawEffectBurn is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA (colormaps 1073-1328 in a .pl2)
|
||||
DrawEffectBurn
|
||||
|
||||
// DrawEffectNormal is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
DrawEffectNormal
|
||||
|
||||
// DrawEffectMod2XTrans is a draw effect that implements the following function:
|
||||
// GL_MODULATE; GL_SRC_COLOR, GL_DST_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
DrawEffectMod2XTrans
|
||||
|
||||
// DrawEffectMod2X is a draw effect that implements the following function:
|
||||
// GL_COMBINE_ARB; GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA (colormaps 1457-1712 in a .pl2)
|
||||
DrawEffectMod2X
|
||||
)
|
||||
|
@ -1,9 +1,10 @@
|
||||
package d2enum
|
||||
|
||||
// EquippedTypeSlot represents the type of equipment slot
|
||||
type EquippedSlotType int
|
||||
|
||||
const (
|
||||
Head EquippedSlotType = 1
|
||||
Head EquippedSlotType = iota + 1
|
||||
Torso EquippedSlotType = 2
|
||||
Legs EquippedSlotType = 3
|
||||
RightArm EquippedSlotType = 4
|
||||
|
@ -1,46 +0,0 @@
|
||||
package d2interface
|
||||
|
||||
type CompositeMode int
|
||||
|
||||
const (
|
||||
// Regular alpha blending
|
||||
// c_out = c_src + c_dst × (1 - α_src)
|
||||
CompositeModeSourceOver = CompositeMode(1)
|
||||
|
||||
// c_out = 0
|
||||
CompositeModeClear = CompositeMode(2)
|
||||
|
||||
// c_out = c_src
|
||||
CompositeModeCopy = CompositeMode(3)
|
||||
|
||||
// c_out = c_dst
|
||||
CompositeModeDestination = CompositeMode(4)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst
|
||||
CompositeModeDestinationOver = CompositeMode(5)
|
||||
|
||||
// c_out = c_src × α_dst
|
||||
CompositeModeSourceIn = CompositeMode(6)
|
||||
|
||||
// c_out = c_dst × α_src
|
||||
CompositeModeDestinationIn = CompositeMode(7)
|
||||
|
||||
// c_out = c_src × (1 - α_dst)
|
||||
CompositeModeSourceOut = CompositeMode(8)
|
||||
|
||||
// c_out = c_dst × (1 - α_src)
|
||||
CompositeModeDestinationOut = CompositeMode(9)
|
||||
|
||||
// c_out = c_src × α_dst + c_dst × (1 - α_src)
|
||||
CompositeModeSourceAtop = CompositeMode(10)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × α_src
|
||||
CompositeModeDestinationAtop = CompositeMode(11)
|
||||
|
||||
// c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src)
|
||||
CompositeModeXor = CompositeMode(12)
|
||||
|
||||
// Sum of source and destination (a.k.a. 'plus' or 'additive')
|
||||
// c_out = c_src + c_dst
|
||||
CompositeModeLighter = CompositeMode(13)
|
||||
)
|
@ -3,8 +3,11 @@ package d2interface
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
)
|
||||
|
||||
// Surface represents a renderable surface.
|
||||
type Surface interface {
|
||||
Clear(color color.Color) error
|
||||
DrawRect(width, height int, color color.Color)
|
||||
@ -15,7 +18,7 @@ type Surface interface {
|
||||
Pop()
|
||||
PopN(n int)
|
||||
PushColor(color color.Color)
|
||||
PushCompositeMode(mode CompositeMode)
|
||||
PushCompositeMode(mode d2enum.CompositeMode)
|
||||
PushFilter(filter Filter)
|
||||
PushTranslation(x, y int)
|
||||
PushBrightness(brightness float64)
|
||||
|
@ -14,17 +14,6 @@ const (
|
||||
TermCategoryError
|
||||
)
|
||||
|
||||
// TermVis is an enumeration of the Terminal's visibility states
|
||||
type termVis int
|
||||
|
||||
// Terminal visibility state
|
||||
const (
|
||||
termVisHidden termVis = iota
|
||||
termVisShowing
|
||||
termVisShown
|
||||
termVisHiding
|
||||
)
|
||||
|
||||
// Terminal is a drop-down terminal and shell
|
||||
// It is used throughout the codebase, most parts of the engine will
|
||||
// `bind` commands, which are available for use in the shell
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||
@ -43,7 +45,7 @@ type Animation struct {
|
||||
lastFrameTime float64
|
||||
playedCount int
|
||||
|
||||
compositeMode d2interface.CompositeMode
|
||||
compositeMode d2enum.CompositeMode
|
||||
colorMod color.Color
|
||||
originAtBottom bool
|
||||
|
||||
@ -399,8 +401,8 @@ func (a *Animation) ResetPlayedCount() {
|
||||
|
||||
func (a *Animation) SetBlend(blend bool) {
|
||||
if blend {
|
||||
a.compositeMode = d2interface.CompositeModeLighter
|
||||
a.compositeMode = d2enum.CompositeModeLighter
|
||||
} else {
|
||||
a.compositeMode = d2interface.CompositeModeSourceOver
|
||||
a.compositeMode = d2enum.CompositeModeSourceOver
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Package ebiten contains ebiten's implementation of the audio interface
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
@ -11,6 +12,9 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/audio"
|
||||
)
|
||||
|
||||
const sampleRate = 44100
|
||||
|
||||
// AudioProvider represents a provider capable of playing audio
|
||||
type AudioProvider struct {
|
||||
audioContext *audio.Context // The Audio context
|
||||
bgmAudio *audio.Player // The audio player
|
||||
@ -19,63 +23,86 @@ type AudioProvider struct {
|
||||
bgmVolume float64
|
||||
}
|
||||
|
||||
// CreateAudio creates an instance of ebiten's audio provider
|
||||
func CreateAudio() (*AudioProvider, error) {
|
||||
result := &AudioProvider{}
|
||||
|
||||
var err error
|
||||
result.audioContext, err = audio.NewContext(44100)
|
||||
result.audioContext, err = audio.NewContext(sampleRate)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PlayBGM loads an audio stream and plays it in the background
|
||||
func (eap *AudioProvider) PlayBGM(song string) {
|
||||
if eap.lastBgm == song {
|
||||
return
|
||||
}
|
||||
|
||||
eap.lastBgm = song
|
||||
|
||||
if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() {
|
||||
_ = eap.bgmAudio.Pause()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if eap.bgmAudio != nil {
|
||||
err := eap.bgmAudio.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
audioStream, err := d2asset.LoadFileStream(song)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d, err := wav.Decode(eap.audioContext, audioStream)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
s := audio.NewInfiniteLoop(d, d.Length())
|
||||
eap.bgmAudio, err = audio.NewPlayer(eap.audioContext, s)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
eap.bgmAudio.SetVolume(eap.bgmVolume)
|
||||
|
||||
// Play the infinite-length stream. This never ends.
|
||||
err = eap.bgmAudio.Rewind()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = eap.bgmAudio.Play()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadSoundEffect loads a sound affect so that it canb e played
|
||||
func (eap *AudioProvider) LoadSoundEffect(sfx string) (d2interface.SoundEffect, error) {
|
||||
result := CreateSoundEffect(sfx, eap.audioContext, eap.sfxVolume) // TODO: Split
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SetVolumes sets the volumes of the audio provider
|
||||
func (eap *AudioProvider) SetVolumes(bgmVolume, sfxVolume float64) {
|
||||
eap.sfxVolume = sfxVolume
|
||||
eap.bgmVolume = bgmVolume
|
||||
|
@ -9,13 +9,17 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/audio/wav"
|
||||
)
|
||||
|
||||
// SoundEffect represents an ebiten implementation of a sound effect
|
||||
type SoundEffect struct {
|
||||
player *audio.Player
|
||||
}
|
||||
|
||||
// CreateSoundEffect creates a new instance of ebiten's sound effect implementation.
|
||||
func CreateSoundEffect(sfx string, context *audio.Context, volume float64) *SoundEffect {
|
||||
result := &SoundEffect{}
|
||||
|
||||
var soundFile string
|
||||
|
||||
if _, exists := d2datadict.Sounds[sfx]; exists {
|
||||
soundEntry := d2datadict.Sounds[sfx]
|
||||
soundFile = soundEntry.FileName
|
||||
@ -24,29 +28,50 @@ func CreateSoundEffect(sfx string, context *audio.Context, volume float64) *Soun
|
||||
}
|
||||
|
||||
audioData, err := d2asset.LoadFile(soundFile)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d, err := wav.Decode(context, audio.BytesReadSeekCloser(audioData))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
player, err := audio.NewPlayer(context, d)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
player.SetVolume(volume)
|
||||
|
||||
result.player = player
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Play plays the sound effect
|
||||
func (v *SoundEffect) Play() {
|
||||
v.player.Rewind()
|
||||
v.player.Play()
|
||||
err := v.player.Rewind()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = v.player.Play()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Stop stops the sound effect
|
||||
func (v *SoundEffect) Stop() {
|
||||
v.player.Pause()
|
||||
err := v.player.Pause()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Package d2config contains configuration objects and functions
|
||||
package d2config
|
||||
|
||||
import (
|
||||
@ -9,6 +10,9 @@ import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const defaultSfxVolume = 1.0
|
||||
const defaultBgmVolume = 0.3
|
||||
|
||||
func getDefaultConfig() *Configuration {
|
||||
config := &Configuration{
|
||||
Language: "ENG",
|
||||
@ -16,8 +20,8 @@ func getDefaultConfig() *Configuration {
|
||||
TicksPerSecond: -1,
|
||||
RunInBackground: true,
|
||||
VsyncEnabled: true,
|
||||
SfxVolume: 1.0,
|
||||
BgmVolume: 0.3,
|
||||
SfxVolume: defaultSfxVolume,
|
||||
BgmVolume: defaultBgmVolume,
|
||||
MpqPath: "C:/Program Files (x86)/Diablo II",
|
||||
MpqLoadOrder: []string{
|
||||
"Patch_D2.mpq",
|
||||
@ -36,8 +40,7 @@ func getDefaultConfig() *Configuration {
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
switch runtime.GOARCH {
|
||||
case "386":
|
||||
if runtime.GOARCH == "386" {
|
||||
config.MpqPath = "C:/Program Files/Diablo II"
|
||||
}
|
||||
case "darwin":
|
||||
@ -77,17 +80,25 @@ func getLocalConfigPath() string {
|
||||
}
|
||||
|
||||
func load(configPath string) error {
|
||||
configFile, err := os.Open(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer configFile.Close()
|
||||
data, err := ioutil.ReadAll(configFile)
|
||||
configFile, err := os.Open(configPath) //nolint:gosec will fix the security error later
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &singleton); err != nil {
|
||||
data, err := ioutil.ReadAll(configFile)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &singleton); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = configFile.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -96,17 +107,19 @@ func load(configPath string) error {
|
||||
|
||||
func save(configPath string) error {
|
||||
configDir := path.Dir(configPath)
|
||||
if err := os.MkdirAll(configDir, 0755); err != nil {
|
||||
|
||||
if err := os.MkdirAll(configDir, 0750); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configFile, err := os.Create(configPath)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer configFile.Close()
|
||||
|
||||
data, err := json.MarshalIndent(singleton, "", " ")
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -115,5 +128,11 @@ func save(configPath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = configFile.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1,72 +1,72 @@
|
||||
package ebiten
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
)
|
||||
|
||||
func d2ToEbitenCompositeMode(comp d2interface.CompositeMode) ebiten.CompositeMode {
|
||||
func d2ToEbitenCompositeMode(comp d2enum.CompositeMode) ebiten.CompositeMode {
|
||||
switch comp {
|
||||
case d2interface.CompositeModeSourceOver:
|
||||
case d2enum.CompositeModeSourceOver:
|
||||
return ebiten.CompositeModeSourceOver
|
||||
case d2interface.CompositeModeClear:
|
||||
case d2enum.CompositeModeClear:
|
||||
return ebiten.CompositeModeClear
|
||||
case d2interface.CompositeModeCopy:
|
||||
case d2enum.CompositeModeCopy:
|
||||
return ebiten.CompositeModeCopy
|
||||
case d2interface.CompositeModeDestination:
|
||||
case d2enum.CompositeModeDestination:
|
||||
return ebiten.CompositeModeDestination
|
||||
case d2interface.CompositeModeDestinationOver:
|
||||
case d2enum.CompositeModeDestinationOver:
|
||||
return ebiten.CompositeModeDestinationOver
|
||||
case d2interface.CompositeModeSourceIn:
|
||||
case d2enum.CompositeModeSourceIn:
|
||||
return ebiten.CompositeModeSourceIn
|
||||
case d2interface.CompositeModeDestinationIn:
|
||||
case d2enum.CompositeModeDestinationIn:
|
||||
return ebiten.CompositeModeDestinationIn
|
||||
case d2interface.CompositeModeSourceOut:
|
||||
case d2enum.CompositeModeSourceOut:
|
||||
return ebiten.CompositeModeSourceOut
|
||||
case d2interface.CompositeModeDestinationOut:
|
||||
case d2enum.CompositeModeDestinationOut:
|
||||
return ebiten.CompositeModeDestinationOut
|
||||
case d2interface.CompositeModeSourceAtop:
|
||||
case d2enum.CompositeModeSourceAtop:
|
||||
return ebiten.CompositeModeSourceAtop
|
||||
case d2interface.CompositeModeDestinationAtop:
|
||||
case d2enum.CompositeModeDestinationAtop:
|
||||
return ebiten.CompositeModeDestinationAtop
|
||||
case d2interface.CompositeModeXor:
|
||||
case d2enum.CompositeModeXor:
|
||||
return ebiten.CompositeModeXor
|
||||
case d2interface.CompositeModeLighter:
|
||||
case d2enum.CompositeModeLighter:
|
||||
return ebiten.CompositeModeLighter
|
||||
}
|
||||
|
||||
return ebiten.CompositeModeSourceOver
|
||||
}
|
||||
|
||||
func ebitenToD2CompositeMode(comp ebiten.CompositeMode) d2interface.CompositeMode {
|
||||
func ebitenToD2CompositeMode(comp ebiten.CompositeMode) d2enum.CompositeMode {
|
||||
switch comp {
|
||||
case ebiten.CompositeModeSourceOver:
|
||||
return d2interface.CompositeModeSourceOver
|
||||
return d2enum.CompositeModeSourceOver
|
||||
case ebiten.CompositeModeClear:
|
||||
return d2interface.CompositeModeClear
|
||||
return d2enum.CompositeModeClear
|
||||
case ebiten.CompositeModeCopy:
|
||||
return d2interface.CompositeModeCopy
|
||||
return d2enum.CompositeModeCopy
|
||||
case ebiten.CompositeModeDestination:
|
||||
return d2interface.CompositeModeDestination
|
||||
return d2enum.CompositeModeDestination
|
||||
case ebiten.CompositeModeDestinationOver:
|
||||
return d2interface.CompositeModeDestinationOver
|
||||
return d2enum.CompositeModeDestinationOver
|
||||
case ebiten.CompositeModeSourceIn:
|
||||
return d2interface.CompositeModeSourceIn
|
||||
return d2enum.CompositeModeSourceIn
|
||||
case ebiten.CompositeModeDestinationIn:
|
||||
return d2interface.CompositeModeDestinationIn
|
||||
return d2enum.CompositeModeDestinationIn
|
||||
case ebiten.CompositeModeSourceOut:
|
||||
return d2interface.CompositeModeSourceOut
|
||||
return d2enum.CompositeModeSourceOut
|
||||
case ebiten.CompositeModeDestinationOut:
|
||||
return d2interface.CompositeModeDestinationOut
|
||||
return d2enum.CompositeModeDestinationOut
|
||||
case ebiten.CompositeModeSourceAtop:
|
||||
return d2interface.CompositeModeSourceAtop
|
||||
return d2enum.CompositeModeSourceAtop
|
||||
case ebiten.CompositeModeDestinationAtop:
|
||||
return d2interface.CompositeModeDestinationAtop
|
||||
return d2enum.CompositeModeDestinationAtop
|
||||
case ebiten.CompositeModeXor:
|
||||
return d2interface.CompositeModeXor
|
||||
return d2enum.CompositeModeXor
|
||||
case ebiten.CompositeModeLighter:
|
||||
return d2interface.CompositeModeLighter
|
||||
return d2enum.CompositeModeLighter
|
||||
}
|
||||
|
||||
return d2interface.CompositeModeSourceOver
|
||||
return d2enum.CompositeModeSourceOver
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
@ -23,7 +25,7 @@ func (s *ebitenSurface) PushTranslation(x, y int) {
|
||||
s.stateCurrent.y += y
|
||||
}
|
||||
|
||||
func (s *ebitenSurface) PushCompositeMode(mode d2interface.CompositeMode) {
|
||||
func (s *ebitenSurface) PushCompositeMode(mode d2enum.CompositeMode) {
|
||||
s.stateStack = append(s.stateStack, s.stateCurrent)
|
||||
s.stateCurrent.mode = d2ToEbitenCompositeMode(mode)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
// Package d2screen contains the interface for screens
|
||||
package d2screen
|
||||
|
||||
import (
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
@ -177,7 +179,7 @@ func (v *Button) Activate() {
|
||||
|
||||
// Render renders the button
|
||||
func (v *Button) Render(target d2interface.Surface) {
|
||||
target.PushCompositeMode(d2interface.CompositeModeSourceAtop)
|
||||
target.PushCompositeMode(d2enum.CompositeModeSourceAtop)
|
||||
target.PushFilter(d2interface.FilterNearest)
|
||||
target.PushTranslation(v.x, v.y)
|
||||
defer target.PopN(3)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package d2ui
|
||||
|
||||
import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
||||
@ -41,7 +42,7 @@ func CreateCheckbox(checkState bool) Checkbox {
|
||||
}
|
||||
|
||||
func (v *Checkbox) Render(target d2interface.Surface) {
|
||||
target.PushCompositeMode(d2interface.CompositeModeSourceAtop)
|
||||
target.PushCompositeMode(d2enum.CompositeModeSourceAtop)
|
||||
target.PushTranslation(v.x, v.y)
|
||||
target.PushFilter(d2interface.FilterNearest)
|
||||
defer target.PopN(3)
|
||||
|
@ -3,6 +3,8 @@ package d2ui
|
||||
import (
|
||||
"image/color"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
||||
@ -60,7 +62,7 @@ func (v *Label) Render(target d2interface.Surface) {
|
||||
}
|
||||
|
||||
target.PushFilter(d2interface.FilterNearest)
|
||||
target.PushCompositeMode(d2interface.CompositeModeSourceAtop)
|
||||
target.PushCompositeMode(d2enum.CompositeModeSourceAtop)
|
||||
target.PushTranslation(x, y)
|
||||
defer target.PopN(3)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
// Package d2player contains the information necessary for managing players
|
||||
package d2player
|
||||
|
||||
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
// EquipmentSlot represents an equipment slot for a player
|
||||
type EquipmentSlot struct {
|
||||
item InventoryItem
|
||||
x int
|
||||
@ -10,6 +12,7 @@ type EquipmentSlot struct {
|
||||
height int
|
||||
}
|
||||
|
||||
//nolint:gomnd Magic numbers are necessary for this file
|
||||
func genEquipmentSlotsMap() map[d2enum.EquippedSlotType]EquipmentSlot {
|
||||
return map[d2enum.EquippedSlotType]EquipmentSlot{
|
||||
d2enum.LeftArm: {
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
||||
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
||||
@ -414,7 +416,7 @@ func (g *GameControls) Render(target d2interface.Surface) {
|
||||
|
||||
// Stamina status bar
|
||||
target.PushTranslation(273, 572)
|
||||
target.PushCompositeMode(d2interface.CompositeModeLighter)
|
||||
target.PushCompositeMode(d2enum.CompositeModeLighter)
|
||||
staminaPercent := float64(g.hero.Stats.Stamina) / float64(g.hero.Stats.MaxStamina)
|
||||
target.DrawRect(int(staminaPercent*staminaBarWidth), 19, color.RGBA{R: 175, G: 136, B: 72, A: 200})
|
||||
target.PopN(2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user