package game

import (
	"openquell/assets"

	"github.com/hajimehoshi/ebiten/v2"
)

type LevelScene struct {
	CurrentLevel int
	Levels       []*Level
	Next         int
	Whoami       int
	UseCache     bool
}

// Implements the actual playing Scene
func NewLevelScene(game *Game, startlevel int) Scene {
	scene := &LevelScene{CurrentLevel: startlevel, Whoami: Play}

	scene.GenerateLevels(game)
	scene.Levels[game.CurrentLevel].SetupGrid(game)

	return scene
}

func (scene *LevelScene) GenerateLevels(game *Game) {
	for _, level := range assets.Levels {
		scene.Levels = append(scene.Levels, NewLevel(game, 32, &level))
	}
}

// Interface methods
func (scene *LevelScene) SetNext() int {
	if scene.Whoami != scene.Next {
		return scene.Next
	}

	return 0
}

func (scene *LevelScene) Update() error {
	scene.Levels[scene.CurrentLevel].Update()
	return nil
}

func (scene *LevelScene) Draw(screen *ebiten.Image) {
	screen.Clear()
	scene.Levels[scene.CurrentLevel].Draw(screen)
}
