2020-11-22 16:02:42 -05:00
|
|
|
//nolint:dupl,golint,stylecheck // component declarations are supposed to look the same
|
2020-10-10 22:49:17 -04:00
|
|
|
package d2components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/user"
|
|
|
|
"path"
|
|
|
|
"runtime"
|
|
|
|
|
2020-10-12 17:35:11 -04:00
|
|
|
"github.com/gravestench/akara"
|
2020-10-10 22:49:17 -04:00
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
|
|
|
)
|
2020-10-10 22:49:17 -04:00
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// static check that GameConfig implements Component
|
|
|
|
var _ akara.Component = &GameConfig{}
|
2020-10-10 22:49:17 -04:00
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// GameConfig represents an OpenDiablo2 game configuration
|
|
|
|
type GameConfig struct {
|
2020-10-10 22:49:17 -04:00
|
|
|
MpqLoadOrder []string
|
|
|
|
MpqPath string
|
|
|
|
TicksPerSecond int
|
|
|
|
FpsCap int
|
|
|
|
SfxVolume float64
|
|
|
|
BgmVolume float64
|
|
|
|
FullScreen bool
|
|
|
|
RunInBackground bool
|
|
|
|
VsyncEnabled bool
|
|
|
|
Backend string
|
2020-11-14 12:50:47 -05:00
|
|
|
LogLevel d2util.LogLevel
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
// New creates the default GameConfig
|
|
|
|
func (*GameConfig) New() akara.Component {
|
2020-10-10 22:49:17 -04:00
|
|
|
const (
|
|
|
|
defaultSfxVolume = 1.0
|
|
|
|
defaultBgmVolume = 0.3
|
|
|
|
)
|
|
|
|
|
2020-11-28 00:45:58 -05:00
|
|
|
config := &GameConfig{}
|
|
|
|
|
2020-11-22 16:02:42 -05:00
|
|
|
config.FullScreen = false
|
|
|
|
config.TicksPerSecond = -1
|
|
|
|
config.RunInBackground = true
|
|
|
|
config.VsyncEnabled = true
|
|
|
|
config.SfxVolume = defaultSfxVolume
|
|
|
|
config.BgmVolume = defaultBgmVolume
|
|
|
|
config.MpqPath = "C:/Program Files (x86)/Diablo II"
|
|
|
|
config.Backend = "Ebiten"
|
|
|
|
config.MpqLoadOrder = []string{
|
|
|
|
"Patch_D2.mpq",
|
|
|
|
"d2exp.mpq",
|
|
|
|
"d2xmusic.mpq",
|
|
|
|
"d2xtalk.mpq",
|
|
|
|
"d2xvideo.mpq",
|
|
|
|
"d2data.mpq",
|
|
|
|
"d2char.mpq",
|
|
|
|
"d2music.mpq",
|
|
|
|
"d2sfx.mpq",
|
|
|
|
"d2video.mpq",
|
|
|
|
"d2speech.mpq",
|
2020-10-10 22:49:17 -04:00
|
|
|
}
|
2020-11-22 16:02:42 -05:00
|
|
|
config.LogLevel = d2util.LogLevelDefault
|
2020-10-10 22:49:17 -04:00
|
|
|
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "windows":
|
|
|
|
if runtime.GOARCH == "386" {
|
|
|
|
config.MpqPath = "C:/Program Files/Diablo II"
|
|
|
|
}
|
|
|
|
case "darwin":
|
|
|
|
config.MpqPath = "/Applications/Diablo II/"
|
|
|
|
config.MpqLoadOrder = []string{
|
|
|
|
"Diablo II Patch",
|
|
|
|
"Diablo II Expansion Data",
|
|
|
|
"Diablo II Expansion Movies",
|
|
|
|
"Diablo II Expansion Music",
|
|
|
|
"Diablo II Expansion Speech",
|
|
|
|
"Diablo II Game Data",
|
|
|
|
"Diablo II Graphics",
|
|
|
|
"Diablo II Movies",
|
|
|
|
"Diablo II Music",
|
|
|
|
"Diablo II Sounds",
|
|
|
|
"Diablo II Speech",
|
|
|
|
}
|
|
|
|
case "linux":
|
|
|
|
if usr, err := user.Current(); err == nil {
|
|
|
|
config.MpqPath = path.Join(usr.HomeDir, ".wine/drive_c/Program Files (x86)/Diablo II")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|
2020-11-28 00:45:58 -05:00
|
|
|
|
|
|
|
// GameConfigFactory is a wrapper for the generic component factory that returns GameConfig component instances.
|
|
|
|
// This can be embedded inside of a system to give them the methods for adding, retrieving, and removing a GameConfig.
|
|
|
|
type GameConfigFactory struct {
|
|
|
|
GameConfig *akara.ComponentFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddGameConfig adds a GameConfig component to the given entity and returns it
|
|
|
|
func (m *GameConfigFactory) AddGameConfig(id akara.EID) *GameConfig {
|
|
|
|
return m.GameConfig.Add(id).(*GameConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetGameConfig returns the GameConfig component for the given entity, and a bool for whether or not it exists
|
|
|
|
func (m *GameConfigFactory) GetGameConfig(id akara.EID) (*GameConfig, bool) {
|
|
|
|
component, found := m.GameConfig.Get(id)
|
|
|
|
if !found {
|
|
|
|
return nil, found
|
|
|
|
}
|
|
|
|
|
|
|
|
return component.(*GameConfig), found
|
|
|
|
}
|