1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-20 10:15:55 -04:00
OpenDiablo2/d2core/d2config/d2config.go
dk fe47e51351
Refactor d2map (#468)
* WIP refactor of d2map stuff

* more d2map refactor

adding realm init to game client
passing map engine from client and server into realm at init
change `generate map packet` to have act and level index as data

* client explodes, but getting there

* realm now initializes, networking works, but map generators dont currently do anything

* changed the way that level type records are loaded

* fixed funcs for level data lookups

* started implementing level generator, currently crashing

* client no longer exploding

* d2networking refactor

put exports into d2client.go and d2server.go
kept GameClient and GameServer methods into their respective files
made methods for packet handlers instead of the giant switch statements

* bugfix: getting first level id by act

* minor refactor of gamescreen for readability

* towns now generate on server start, create player takes act and level id as args, levels have their own map engine
2020-06-26 16:50:24 -04:00

68 lines
1.3 KiB
Go

package d2config
import (
"log"
)
// Configuration defines the configuration for the engine, loaded from config.json
type Configuration struct {
MpqLoadOrder []string
Language string
MpqPath string
TicksPerSecond int
FpsCap int
SfxVolume float64
BgmVolume float64
FullScreen bool
RunInBackground bool
VsyncEnabled bool
MaxConnections int
}
var singleton = getDefaultConfig()
func Load() error {
configPaths := []string{
getLocalConfigPath(),
getDefaultConfigPath(),
}
var loaded bool
for _, configPath := range configPaths {
log.Printf("loading configuration file from %s...", configPath)
if err := load(configPath); err == nil {
loaded = true
break
}
}
if !loaded {
log.Println("failed to load configuration file, saving default configuration...")
if err := Save(); err != nil {
return err
}
}
return nil
}
func Save() error {
configPath := getDefaultConfigPath()
log.Printf("saving configuration file to %s...", configPath)
var err error
if err = save(configPath); err != nil {
log.Printf("failed to write configuration file (%s)", err)
}
return err
}
func Get() Configuration {
if singleton == nil {
panic("configuration is not initialized")
}
return *singleton
}