module Dodge.Default.World where
import Dodge.Data
import Dodge.Zone.Size
import Dodge.Zone.Object
import Dodge.Base
import Geometry.Vector3D
import Geometry.Zone
--import Dodge.Config.KeyConfig
--import Dodge.Menu
--import Picture
import Geometry.Data
import Geometry.Polygon
--import Picture.Texture
--import Data.Preload

import Control.Lens
import System.Random
import qualified Data.IntMap.Strict as IM
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Graph.Inductive.Graph hiding ((&))
--import Data.Graph.Inductive.NodeMap
defaultWorld :: World
defaultWorld = World
    { _keys = S.empty
    , _magnets = IM.empty
    , _mouseButtons = mempty
    , _cameraCenter = V2 0 0
    , _cameraRot = 0
    , _cameraZoom = 1
    , _itemZoom     = 1
    , _defaultZoom = 1
    , _cameraViewFrom = V2 0 0
    , _viewDistance = 1000
    , _modifications    = IM.empty
    , _creatures        = IM.empty
    , _crZoning         = Zoning IM.empty crZoneSize zoneOfCreature
    , _creatureGroups   = IM.empty
    , _clouds           = mempty
    , _clZoning         = Zoning IM.empty clZoneSize (zonePos (stripZ . _clPos))
    , _gusts = IM.empty
    , _gsZoning         = Zoning IM.empty clZoneSize (zonePos _guPos)
    , _itemPositions = IM.empty
    , _props = IM.empty
    , _instantParticles = []
    , _particles = []
    , _newBeams = WorldBeams [] [] [] []
    , _beams = WorldBeams [] [] [] []
    , _walls = IM.empty
    , _wallDamages = IM.empty
    , _blocks = IM.empty
    , _machines = IM.empty
    , _terminals = IM.empty
    , _doors = IM.empty
    , _coordinates  = IM.empty
    , _triggers     = IM.empty
    , _wlZoning     = Zoning IM.empty wlZoneSize zoneOfWall
    , _floorItems = IM.empty
    , _floorTiles = []
    , _randGen = mkStdGen 2
    , _mousePos = V2 0 0
    , _testString = const . const []
    , _yourID = 0
    , _worldEvents = id
    , _delayedEvents = []
    , _pressPlates = IM.empty
    , _buttons = IM.empty
    , _toPlaySounds = M.empty
    , _playingSounds = M.empty
    , _corpses = IM.empty
    , _decorations = IM.empty
    --, _savedWorlds = M.empty
--    , _menuLayers = []
    , _clickMousePos = V2 0 0
    , _pathGraph = Data.Graph.Inductive.Graph.empty
    , _pathGraphP   = mempty
    , _pnZoning     = Zoning mempty wlZoneSize (zonePos snd)
    , _peZoning     = Zoning mempty wlZoneSize (\x (_,_,e) -> zoneOfSeg x (_peStart e) (_peEnd e))
    , _hud = HUD
        { _hudElement = DisplayInventory NoSubInventory
        , _carteCenter = V2 0 0
        , _carteZoom = 0.5
        , _carteRot  = 0
        }
    , _lightSources = IM.empty
    , _tempLightSources = [youLight]
    , _closeObjects     = []
    , _rbOptions        = NoRightButtonOptions
    , _seenLocations        = IM.fromList 
        [(0, (_crPos . you, "CURRENT POSITION"))
        ,(1, (const (V2 0 0) , "START POSITION"))
        ]
    , _selLocation = 0
    --, _keyConfig = defaultKeyConfigSDL
--    , _config       = defaultConfig
    , _sideEffects  = return
    , _shapes = mempty
    , _distortions     = []
    , _gameRooms = []
    , _roomClipping = []
    , _worldClock = 0
    , _worldBounds = defaultBounds
    , _maybeWorld = Nothing'
    , _rewindWorlds = []
    , _timeFlow = NormalTimeFlow
    , _hammers = defaultWorldHammers
    , _backspaceTimer = 0
    , _genParams = GenParams M.empty
    , _genPlacements = IM.empty
    , _genRooms = IM.empty
    , _deathDelay = Nothing
    , _testFloat = 0
    , _boundBox = square 100
    , _boundDist = (100,-100,100,-100)
    , _lLine  = (0,0)
    , _rLine  = (0,0)
    , _lSelect   = 0
    , _rSelect   = 0
    }
defaultWorldHammers :: M.Map WorldHammer HammerPosition
defaultWorldHammers = M.fromSet (const HammerUp) $ S.fromList [minBound.. maxBound]
youLight :: TempLightSource
youLight = TLS 
    { _tlsParam = LSParam
        {_lsPos = V3 0 0 0
        ,_lsRad = 300
        ,_lsCol = 0.1
        }
    ,_tlsUpdate = \w _ -> Just (youLight & tlsParam . lsPos .~ f (_crPos $ you w))
    ,_tlsTime = 0
    }
  where
    f (V2 x y) = V3 x y 100
