refactor preset loading

This commit is contained in:
filifa 2024-09-02 23:33:35 -05:00
parent 75ba1e8134
commit 4a9b17f4ed
1 changed files with 18 additions and 12 deletions

View File

@ -44,6 +44,22 @@ func (s *script) load(path string) error {
return err return err
} }
func getPresets() []string {
var presets []string
if preset != "" {
presets = []string{preset}
}
if scriptPath != "" {
var s script
s.load(scriptPath)
presets = s.Presets
}
return presets
}
func handleWindowEvent(event *sdl.WindowEvent, m *milkDropWindow) { func handleWindowEvent(event *sdl.WindowEvent, m *milkDropWindow) {
switch event.Event { switch event.Event {
case sdl.WINDOWEVENT_RESIZED: case sdl.WINDOWEVENT_RESIZED:
@ -84,24 +100,14 @@ func milkbucket(cmd *cobra.Command, args []string) {
log.Fatal("nothing to read from stdin") log.Fatal("nothing to read from stdin")
} }
var presets []string
if preset != "" {
presets = []string{preset}
}
if scriptPath != "" {
var s script
s.load(scriptPath)
presets = s.Presets
}
err = sdl.Init(sdl.INIT_VIDEO) err = sdl.Init(sdl.INIT_VIDEO)
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer sdl.Quit() defer sdl.Quit()
presets := getPresets()
m, err := newMilkDropWindow(800, 600, presets) m, err := newMilkDropWindow(800, 600, presets)
if err != nil { if err != nil {
panic(err) panic(err)