module Dodge.Item.Draw
    where
import Dodge.Data
import Dodge.Item.Data
--import Dodge.Picture.Layer
import Dodge.Creature.Stance.Data
--import Picture
--import Shape
import ShapePicture

import qualified Data.IntMap.Strict as IM
import Control.Lens
{- | Places an item picture onto a creature when the item is selected. -}
pictureWeaponOnAim
    :: SPic 
    -> Creature 
    -> Int  -- ^ Position of item in inventory
    -> SPic
pictureWeaponOnAim p cr posInInv 
    | isSelected && _posture (_crStance cr) == Aiming && isTwisting
                = shoulderD twistWep
    | isSelected && _posture (_crStance cr) == Aiming && isOneHand
                = shoulderD oneHandWep
    | isSelected && _posture (_crStance cr) == Aiming
                = shoulderD drawnWep
    | isSelected && isOneHand
                = handD holsteredOneHandWep
    | isSelected 
                = handD holsteredWep
    | otherwise = emptyBlank
  where 
    shoulderD = translateSPz 20.5
    handD = translateSPz 15
    isSelected = _crInvSel cr == posInInv 
    drawnWep        = translateSPf (_crRad cr) 0 p
    twistWep        = translateSPf (0.5 * _crRad cr) 0 p
    oneHandWep      = translateSPf (1.5 * _crRad cr) 0 p
    holsteredWep    = translateSPf (_crRad cr) 0 (rotateSP (sRot + 1.2) p)
    holsteredOneHandWep = translateSPf (_crRad cr * 0.7 + handPos) (_crRad cr * negate 0.7) p
    handPos = case cr^? crStance . carriage of
        Just (Walking x LeftForward) -> f x * 50
        _ -> 0
    theIt = _crInv cr IM.! posInInv
    isTwisting = _itAimStance theIt == TwoHandTwist
    isOneHand = _itAimStance theIt == OneHand
    sRot = case cr ^? crStance . carriage of
        Just (Walking x LeftForward)  -> f x
        Just (Walking x RightForward) -> - f x
        _ -> 0
    f i = 0.1 * fromIntegral (sLen - i) / fromIntegral sLen
    sLen = _strideLength $ _crStance cr

pictureItem
    :: SPic 
    -> Creature 
    -> Int  -- ^ Position of item in inventory
    -> SPic
pictureItem p cr posInInv 
    | _crInvSel cr == posInInv = drawnWep
    | otherwise                = emptyBlank
  where 
    drawnWep = translateSPf (_crRad cr) 0 p
