{-# LANGUAGE MultiParamTypeClasses #-}

module StateMachine where

import Affection

import Types

import Load
import Menu.Connect
import Menu.Adjust
import MainGame.WorldMap
import MainGame.MindMap
import Util

instance StateMachine State UserData where
  smLoad Load = loadLoad
  smLoad (Menu Connect) = loadMenu
  -- smLoad (Menu (Adjust _)) = loadAdjust
  smLoad (Main _) = loadMap

  smUpdate Load = updateLoad
  smUpdate (Menu Connect) = updateMenu
  smUpdate (Menu (Adjust _)) = const (return ())
  smUpdate (Main WorldMap) = updateMap
  smUpdate (Main MindMap) = updateMind

  smDraw Load = drawLoad
  smDraw (Menu Connect) = drawMenu
  smDraw (Menu (Adjust _)) = drawMenu >> drawAdjust
  smDraw (Main WorldMap) = drawMap
  smDraw (Main MindMap) = drawMind

  smEvent _ evs = do
    Subsystems w m k j _ <- subsystems <$> getAffection
    _ <- consumeSDLEvents j =<<
      consumeSDLEvents k =<<
      consumeSDLEvents w =<<
      consumeSDLEvents m evs
    return ()

  smClean _ = fullClean
