Skip to content

Commit

Permalink
chore(config): Change config.NewDefault() return type to a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Aug 24, 2024
1 parent 5d9688d commit b7699f9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/gones/cmd_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Command struct{}
func (c *Command) Execute() error {
slog.Info("Loaded config")
conf := config.NewDefault()
return run(nil, &conf, "")
return run(nil, conf, "")
}

func New(_ ...options.Option) *Command {
Expand Down
4 changes: 2 additions & 2 deletions internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/hajimehoshi/ebiten/v2"
)

func NewDefault() Config {
return Config{
func NewDefault() *Config {
return &Config{
UI: UI{
Fullscreen: false,
Scale: 3,
Expand Down
6 changes: 3 additions & 3 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Load(cmd *cobra.Command) (*Config, error) {
return nil, err
}

if err := k.UnmarshalWithConf("", &conf, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
if err := k.UnmarshalWithConf("", conf, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
return nil, err
}

Expand Down Expand Up @@ -108,7 +108,7 @@ func Load(cmd *cobra.Command) (*Config, error) {
return nil, err
}

if err := k.UnmarshalWithConf("", &conf, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
if err := k.UnmarshalWithConf("", conf, koanf.UnmarshalConf{Tag: "toml"}); err != nil {
return nil, err
}

Expand All @@ -122,7 +122,7 @@ func Load(cmd *cobra.Command) (*Config, error) {
}

logger.Info("Loaded config")
return &conf, err
return conf, err
}

func fixConfig(k *koanf.Koanf) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func New(conf *config.Config, cart *cartridge.Cartridge) (*Console, error) {
return &console, err
}

console.PPU = ppu.New(conf.UI.Overscan, console.Mapper)
console.PPU = ppu.New(conf, console.Mapper)
console.APU = apu.New(conf)
console.Bus = bus.New(conf, console.Mapper, console.PPU, console.APU)
console.CPU = cpu.New(console.Bus)
Expand Down
8 changes: 4 additions & 4 deletions internal/console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func stubConsole(r io.ReadSeeker) (*Console, error) {

conf := config.NewDefault()
console := Console{
config: &conf,
config: conf,
Cartridge: cart,
Mapper: mapper,
}

console.PPU = ppu.New(config.Overscan{}, console.Mapper)
console.APU = apu.New(&conf)
console.Bus = bus.New(&conf, console.Mapper, console.PPU, console.APU)
console.PPU = ppu.New(config.NewDefault(), console.Mapper)
console.APU = apu.New(conf)
console.Bus = bus.New(conf, console.Mapper, console.PPU, console.APU)
console.CPU = cpu.New(console.Bus)

console.PPU.SetCPU(console.CPU)
Expand Down
6 changes: 3 additions & 3 deletions internal/cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
func stubCPU(program []byte) *CPU {
cart := cartridge.FromBytes(program)
mapper := cartridge.NewMapper2(cart)
ppu := ppu.New(config.Overscan{}, mapper)
ppu := ppu.New(config.NewDefault(), mapper)
conf := config.NewDefault()
apu := apu.New(&conf)
bus := bus.New(&conf, mapper, ppu, apu)
apu := apu.New(conf)
bus := bus.New(conf, mapper, ppu, apu)
cpu := New(bus)
apu.SetCPU(cpu)
return cpu
Expand Down
4 changes: 2 additions & 2 deletions internal/ppu/ppu.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type CPU interface {
interrupt.Stall
}

func New(t config.Overscan, mapper cartridge.Mapper) *PPU {
rect := t.Rect()
func New(conf *config.Config, mapper cartridge.Mapper) *PPU {
rect := conf.UI.Overscan.Rect()
return &PPU{
offsets: rect.Min,
mapper: mapper,
Expand Down

0 comments on commit b7699f9

Please sign in to comment.