module States ( MState(..) , TipTile(..) , Table(..) , DState(..) , KState(..) , TileType(..) , mStateTransTipTiles , tipTilePositionChange , EButton(..) , ButtonType(..) , mStateTransRandGen , kStateChangePos , EventType(..) , Eventx(..) , EventKey(..) , changeEventx , mStateChangeEvents , mStateGetEventFlag , kStateChangeDownKey , kStateChangeDownKP , mStateTransKey , KeyInMState(..) , TexObjGrp , TexObjKey(..) , getTextureObj , Counter(..) , ValuesInMState(..) , mStateChangeValueM , mStateChangeMaxValue , mStateChangeCounterValue , changeCounterValue , CounterKey(..) , dStateChangeCounterV , getMStateCounterValueM , getMStateMaxValueM , PMState(..) , pMStateChangeCPosition , rdivTileNum , fdivTileNum , dStateGetCounterV , mStateChangeDivTileNum ) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import System.Random import qualified Data.Map as Map data TileType = NormalTile | EmptyTile deriving (Show) data TipTile = TipTile {tilePosition :: (Vector2 GLint) ,texPosition :: (Vector2 GLint) ,tileType :: TileType ,tileID :: GLint }deriving (Show) type KeyInMState = ((Maybe Key) , (Maybe Key)) data MState = MState { tipTiles :: [TipTile] ,randGen :: StdGen ,keyInM :: KeyInMState ,events :: (Map.Map EventKey Eventx) , valueM :: ValuesInMState ,divTileNum :: GLint } deriving (Show) fdivTileNum :: MState -> GLfloat fdivTileNum mst = (fromIntegral (divTileNum mst)) rdivTileNum :: MState -> GLfloat rdivTileNum mst = 1 / (fromIntegral (divTileNum mst)) data ValuesInMState = ValuesInMState { counterValueM ::GLint ,maxCvalueM ::GLint } deriving (Show) vInMChangeCounterValueM :: ValuesInMState -> GLint -> ValuesInMState vInMChangeCounterValueM (ValuesInMState _ y ) i = (ValuesInMState i y ) vInMChangeMaxValueM :: ValuesInMState -> GLint -> ValuesInMState vInMChangeMaxValueM (ValuesInMState x _ ) mi = (ValuesInMState x mi ) mStateTransTipTiles :: MState -> [TipTile] -> MState mStateTransTipTiles (MState _ rGen x y z d) tiles = (MState tiles rGen x y z d) mStateTransRandGen :: MState -> StdGen -> MState mStateTransRandGen (MState tiles _ x y z d) rGen = (MState tiles rGen x y z d) mStateTransKey :: MState -> KeyInMState -> MState mStateTransKey (MState tiles rGen _ y z d) key = (MState tiles rGen key y z d) mStateChangeEvents :: MState -> (Map.Map EventKey Eventx) -> MState mStateChangeEvents (MState tiles rGen key _ z d) exs = (MState tiles rGen key exs z d) mStateGetEventFlag :: MState -> EventKey -> (Maybe Bool) mStateGetEventFlag mst ekey = fmap eventFlag (Map.lookup ekey (events mst)) mStateChangeValueM :: MState -> ValuesInMState -> MState mStateChangeValueM (MState tiles rGen key y _ d) vM = (MState tiles rGen key y vM d) mStateChangeCounterValue :: MState -> GLint -> MState mStateChangeCounterValue mst i = mStateChangeValueM mst (vInMChangeCounterValueM (valueM mst) i) mStateChangeMaxValue :: MState -> GLint -> MState mStateChangeMaxValue mst i = mStateChangeValueM mst (vInMChangeMaxValueM (valueM mst) i) getMStateCounterValueM :: MState -> GLint getMStateCounterValueM mst = counterValueM (valueM mst) getMStateMaxValueM :: MState -> GLint getMStateMaxValueM mst = maxCvalueM (valueM mst) mStateChangeDivTileNum :: MState -> GLint -> MState mStateChangeDivTileNum (MState tiles rGen key y z _) i = (MState tiles rGen key y z i) data EventKey = EReset | EFrame | EDivPlus | EDivMinus deriving (Show , Eq , Ord) data Eventx = Eventx { eventID :: Int ,eventFlag :: Bool ,eventType :: EventType } deriving (Show) data EventType = Continue | AppOnce deriving (Show ,Eq) changeEventx :: Eventx -> Bool -> Eventx changeEventx (Eventx i _ etype) b = (Eventx i b etype) data CounterKey = CTileMove | CTileMoveRest | CCursorPosX | CCursorPosY | CDivTileNum deriving (Show , Eq , Ord) data DState = DState { windowWidth :: GLint ,windowHeight :: GLint ,mainTable :: Table ,eButtons :: (Map.Map EventKey EButton) ,eCounter :: (Map.Map CounterKey Counter) } deriving (Show) dStateChangeCounterV :: DState -> (CounterKey , GLint) -> DState dStateChangeCounterV (DState w h tb eb ec) (ckey , cv) = let eco = ((\(Just x) -> x) (Map.lookup ckey ec)) in (DState w h tb eb (Map.insert ckey (changeCounterValue eco cv) ec)) dStateGetCounterV :: DState -> CounterKey -> GLint dStateGetCounterV (DState w h tb eb ec) ckey = let eco = ((\(Just x) -> x) (Map.lookup ckey ec)) in counterValue eco data Counter = Counter { counterID :: Int ,counterValue :: GLint ,counterNumDegit :: Int ,counterContainer :: Table ,counterMargin :: GLfloat ,counterTexKey :: TexObjKey } deriving (Show) changeCounterValue :: Counter -> GLint -> Counter changeCounterValue (Counter x _ di container cmargin t) i = (Counter x i di container cmargin t) data KState = KState { downKey :: (Maybe Key) ,clickPos :: (Maybe Position) } deriving (Show) kStateChangeDownKey :: KState -> (Maybe Key) -> KState kStateChangeDownKey (KState _ b ) mkey = (KState mkey b) kStateChangePos :: KState -> (Maybe Position) -> KState kStateChangePos (KState a _ ) mp = (KState a mp) kStateChangeDownKP :: KState -> (Maybe Key) -> (Maybe Position) -> KState kStateChangeDownKP kst key pos = kStateChangeDownKey (kStateChangePos kst pos) key data Table = Table { tableX :: GLfloat ,tableY :: GLfloat ,tableWidth :: GLfloat ,tableHeight :: GLfloat } deriving (Show) tipTilePositionChange :: TipTile -> (Vector2 GLint) -> TipTile tipTilePositionChange (TipTile tpos texpos ttype tID) v = (TipTile v texpos ttype tID) data EButton = EButton {buttonPosition :: (Vector2 GLfloat) ,buttonWidth :: GLfloat ,buttonHeight :: GLfloat ,buttonType :: (ButtonType) ,continuous :: Bool ----連続入力を認めるか ,texObjKey :: TexObjKey } deriving (Show) data ButtonType = ResetButton | FrameButton | EndButton | DivPlusButton | DivMinusButton deriving (Show , Eq) data TexObjKey = KeyTexTiles | KeyTexReset | KeyTexLine | KeyTexNum | KeyTexAdd deriving (Show , Ord , Eq) type TexObjGrp = Map.Map TexObjKey [TextureObject] getTextureObj :: TexObjKey -> TexObjGrp -> Int -> TextureObject getTextureObj texObjKey tObGp i = let mtexObjs = Map.lookup texObjKey tObGp mtexObjKey = Map.keys tObGp mtexObjKey0 = (mtexObjKey !! 0) in case mtexObjs of Nothing -> getTextureObj mtexObjKey0 tObGp i Just mtObs -> if (length mtObs) >= i then (mtObs !! i) else (mtObs !! 0) data PMState = PMState { cPosition :: (Maybe Position) } deriving (Show) pMStateChangeCPosition :: PMState -> (Maybe Position) -> PMState pMStateChangeCPosition (PMState _) mpos = (PMState mpos)