134 lines
No EOL
3.8 KiB
Haskell
134 lines
No EOL
3.8 KiB
Haskell
-- 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 --------------------------------
|
|
|
|
-- A game is the base data container.
|
|
data Game = Game {
|
|
state :: State
|
|
} deriving (Eq, Show)
|
|
|
|
------------------------------- State --------------------------------
|
|
|
|
-- Main menu
|
|
data State = Menu
|
|
-- Select the level you want to play
|
|
| LevelSelection { levelList :: [FilePath],
|
|
selector :: ListSelector }
|
|
-- Playing a level
|
|
| Playing { levels :: [Level],
|
|
count :: Int,
|
|
level :: Level,
|
|
player :: Player,
|
|
restart :: State }
|
|
-- Selecting an action
|
|
| ActionSelection { actionList :: [Action],
|
|
selector :: ListSelector,
|
|
-- The player of this state will be used to interact
|
|
continue :: State }
|
|
-- Paused while playing a level
|
|
| Paused { continue :: State }
|
|
-- Won a level
|
|
| Win
|
|
-- Lost a level
|
|
| Lose { restart :: State }
|
|
| Error Message
|
|
deriving (Eq, Show)
|
|
|
|
type Message = String
|
|
|
|
------------------------------- Level --------------------------------
|
|
|
|
data Level = Level {
|
|
layout :: Layout,
|
|
-- All Physical pieces but with their coordinates
|
|
index :: [(X, Y, Physical)],
|
|
items :: [Item],
|
|
entities :: [Entity]
|
|
} deriving (Eq, Show)
|
|
|
|
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
|
|
| Entrance
|
|
| Exit
|
|
deriving (Eq, Show)
|
|
|
|
-------------------------------- Item --------------------------------
|
|
|
|
data Item = Item {
|
|
itemId :: ItemId,
|
|
itemX :: X,
|
|
itemY :: Y,
|
|
itemName :: String,
|
|
itemDescription :: String,
|
|
itemActions :: [([Condition], Action)],
|
|
itemValue :: Maybe Int,
|
|
useTimes :: Maybe Int
|
|
} deriving (Eq, Show)
|
|
|
|
type ItemId = String
|
|
|
|
------------------------------- Entity -------------------------------
|
|
|
|
data Entity = Entity {
|
|
entityId :: EntityId,
|
|
entityX :: X,
|
|
entityY :: Y,
|
|
entityName :: String,
|
|
entityDescription :: String,
|
|
entityActions :: [([Condition], Action)],
|
|
entityValue :: Maybe Int,
|
|
entityHp :: HP,
|
|
direction :: Direction
|
|
} deriving (Eq, Show)
|
|
|
|
type EntityId = 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),
|
|
showHp :: Bool,
|
|
showInventory :: Bool
|
|
} deriving (Eq, Show)
|
|
|
|
------------------------------ Condition -----------------------------
|
|
|
|
data Condition = InventoryFull
|
|
| InventoryContains ItemId
|
|
| Not Condition
|
|
| AlwaysFalse
|
|
deriving (Eq, Show)
|
|
|
|
------------------------------- Action -------------------------------
|
|
|
|
data Action = Leave
|
|
| RetrieveItem ItemId
|
|
| UseItem ItemId
|
|
| DecreaseHp EntityId ItemId
|
|
| IncreasePlayerHp ItemId
|
|
| DoNothing
|
|
deriving (Eq, Show) |