make loading script a method of window
This commit is contained in:
parent
9e8aff813e
commit
dbbbceaa49
|
@ -49,25 +49,35 @@ type script struct {
|
|||
Times []float64
|
||||
}
|
||||
|
||||
func readScript(scriptPath string) (*script, error) {
|
||||
func (m *milkDropWindow) loadScript(scriptPath string) error {
|
||||
if scriptPath == "" {
|
||||
return nil, errors.New("no script given")
|
||||
return errors.New("no script given")
|
||||
}
|
||||
|
||||
f, err := os.Open(scriptPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
var s script
|
||||
err = json.Unmarshal(data, &s)
|
||||
return &s, err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.preset = ring.New(len(s.Presets))
|
||||
for _, preset := range s.Presets {
|
||||
m.preset.Value = preset
|
||||
m.preset = m.preset.Next()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *milkDropWindow) nextPreset() {
|
||||
|
@ -82,19 +92,12 @@ func (m *milkDropWindow) prevPreset() {
|
|||
|
||||
func newMilkDropWindow(width, height int32, scriptPath string) (*milkDropWindow, error) {
|
||||
var m milkDropWindow
|
||||
var err error
|
||||
|
||||
s, err := readScript(scriptPath)
|
||||
err := m.loadScript(scriptPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.preset = ring.New(len(s.Presets))
|
||||
for _, preset := range s.Presets {
|
||||
m.preset.Value = preset
|
||||
m.preset = m.preset.Next()
|
||||
}
|
||||
|
||||
m.window, err = sdl.CreateWindow("milkbucket", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, width, height, sdl.WINDOW_OPENGL|sdl.WINDOW_RESIZABLE)
|
||||
if err != nil {
|
||||
return &m, err
|
||||
|
|
Loading…
Reference in New Issue