Restructuring, #9
This commit is contained in:
parent
2055ef234e
commit
dab6fadad4
41 changed files with 941 additions and 680 deletions
|
@ -1,28 +1,64 @@
|
|||
module RPGEngine.Data where
|
||||
-- Contains all the data containers of the game.
|
||||
-- Submodules contain accessors for these data containers.
|
||||
module RPGEngine.Data
|
||||
-- All data types are exported
|
||||
where
|
||||
|
||||
import RPGEngine.Input.Core
|
||||
import RPGEngine.Render.Core ( Renderer )
|
||||
|
||||
-------------------------------- Game --------------------------------
|
||||
|
||||
-- TODO Add more
|
||||
-- A game is the base data container.
|
||||
data Game = Game {
|
||||
-- Current state of the game
|
||||
state :: State,
|
||||
playing :: Level,
|
||||
levels :: [Level],
|
||||
player :: Player
|
||||
state :: State,
|
||||
levels :: [Level],
|
||||
player :: Player
|
||||
}
|
||||
|
||||
------------------------------- State --------------------------------
|
||||
|
||||
-- Code reusability
|
||||
data StateBase = StateBase {
|
||||
renderer :: Renderer Game,
|
||||
inputHandler :: InputHandler Game
|
||||
}
|
||||
|
||||
-- Main menu
|
||||
data State = Menu { base :: StateBase }
|
||||
-- Select the level you want to play
|
||||
| LevelSelection { base :: StateBase,
|
||||
levelList :: [FilePath],
|
||||
selector :: ListSelector }
|
||||
-- Playing a level
|
||||
| Playing { base :: StateBase,
|
||||
level :: Level }
|
||||
-- Paused while playing a level
|
||||
| Paused { base :: StateBase,
|
||||
level :: Level }
|
||||
-- Won a level
|
||||
| Win { base :: StateBase }
|
||||
-- Lost a level
|
||||
| Lose { base :: StateBase }
|
||||
|
||||
------------------------------- Level --------------------------------
|
||||
|
||||
data Level = Level {
|
||||
layout :: Layout,
|
||||
coordlayout :: [(X, Y, Physical)],
|
||||
items :: [Item],
|
||||
entities :: [Entity]
|
||||
layout :: Layout,
|
||||
-- All Physical pieces but with their coordinates
|
||||
index :: [(X, Y, Physical)],
|
||||
items :: [Item],
|
||||
entities :: [Entity]
|
||||
} deriving (Eq, Show)
|
||||
|
||||
type Layout = [Strip]
|
||||
type Strip = [Physical]
|
||||
type X = Int
|
||||
type Y = Int
|
||||
|
||||
type Layout = [Strip]
|
||||
type Strip = [Physical]
|
||||
|
||||
-- A Physical part of the world. A single tile of the world. A block
|
||||
-- with stuff on it.
|
||||
data Physical = Void
|
||||
| Walkable
|
||||
| Blocked
|
||||
|
@ -30,48 +66,12 @@ data Physical = Void
|
|||
| Exit
|
||||
deriving (Eq, Show)
|
||||
|
||||
------------------------------- Player -------------------------------
|
||||
|
||||
type X = Int
|
||||
type Y = Int
|
||||
|
||||
data Player = Player {
|
||||
playerHp :: Maybe Int,
|
||||
inventory :: [Item],
|
||||
position :: (X, Y)
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance Living Player where
|
||||
hp = playerHp
|
||||
|
||||
------------------------------- State --------------------------------
|
||||
|
||||
-- Current state of the game.
|
||||
data State = Menu
|
||||
| LvlSelect
|
||||
| Playing
|
||||
| Pause
|
||||
| Win
|
||||
| Lose
|
||||
|
||||
------------------------------- Object -------------------------------
|
||||
|
||||
class Object a where
|
||||
id :: a -> String
|
||||
x :: a -> Int
|
||||
y :: a -> Int
|
||||
name :: a -> String
|
||||
description :: a -> String
|
||||
actions :: a -> [([Condition], Action)]
|
||||
value :: a -> Maybe Int
|
||||
|
||||
class Living a where
|
||||
hp :: a -> Maybe Int
|
||||
-------------------------------- Item --------------------------------
|
||||
|
||||
data Item = Item {
|
||||
itemId :: ItemId,
|
||||
itemX :: Int,
|
||||
itemY :: Int,
|
||||
itemX :: X,
|
||||
itemY :: Y,
|
||||
itemName :: String,
|
||||
itemDescription :: String,
|
||||
itemActions :: [([Condition], Action)],
|
||||
|
@ -79,41 +79,37 @@ data Item = Item {
|
|||
useTimes :: Maybe Int
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance Object Item where
|
||||
id = itemId
|
||||
x = itemX
|
||||
y = itemY
|
||||
name = itemName
|
||||
description = itemDescription
|
||||
actions = itemActions
|
||||
value = itemValue
|
||||
type ItemId = String
|
||||
|
||||
------------------------------- Entity -------------------------------
|
||||
|
||||
data Entity = Entity {
|
||||
entityId :: EntityId,
|
||||
entityX :: Int,
|
||||
entityY :: Int,
|
||||
entityX :: X,
|
||||
entityY :: Y,
|
||||
entityName :: String,
|
||||
entityDescription :: String,
|
||||
entityActions :: [([Condition], Action)],
|
||||
entityValue :: Maybe Int,
|
||||
entityHp :: Maybe Int,
|
||||
entityHp :: HP,
|
||||
direction :: Direction
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance Object Entity where
|
||||
id = entityId
|
||||
x = entityX
|
||||
y = entityY
|
||||
name = entityName
|
||||
description = entityDescription
|
||||
actions = entityActions
|
||||
value = entityValue
|
||||
|
||||
instance Living Entity where
|
||||
hp = entityHp
|
||||
|
||||
type EntityId = String
|
||||
type ItemId = String
|
||||
type HP = Maybe Int
|
||||
|
||||
data Direction = North
|
||||
| East
|
||||
| South
|
||||
| West
|
||||
| Stay -- No direction
|
||||
deriving (Eq, Show)
|
||||
|
||||
data Player = Player {
|
||||
playerHp :: HP,
|
||||
inventory :: [Item],
|
||||
position :: (X, Y)
|
||||
} deriving (Eq, Show)
|
||||
|
||||
------------------------------ Condition -----------------------------
|
||||
|
||||
|
@ -121,7 +117,7 @@ data Condition = InventoryFull
|
|||
| InventoryContains ItemId
|
||||
| Not Condition
|
||||
| AlwaysFalse
|
||||
deriving (Show, Eq)
|
||||
deriving (Eq, Show)
|
||||
|
||||
------------------------------- Action -------------------------------
|
||||
|
||||
|
@ -130,14 +126,5 @@ data Action = Leave
|
|||
| UseItem ItemId
|
||||
| DecreaseHp EntityId ItemId
|
||||
| IncreasePlayerHp ItemId
|
||||
| Nothing
|
||||
deriving (Show, Eq)
|
||||
|
||||
------------------------------ Direction -----------------------------
|
||||
|
||||
data Direction = North
|
||||
| East
|
||||
| South
|
||||
| West
|
||||
| Center -- Equal to 'stay where you are'
|
||||
deriving (Show, Eq)
|
||||
| DoNothing
|
||||
deriving (Eq, Show)
|
Reference in a new issue