diff --git a/lib/RPGEngine.hs b/lib/RPGEngine.hs index 1ab1fa5..ee52fc9 100644 --- a/lib/RPGEngine.hs +++ b/lib/RPGEngine.hs @@ -5,7 +5,7 @@ module RPGEngine ( playRPGEngine ) where -import RPGEngine.Internals.Data.Game +import RPGEngine.Data.Game import RPGEngine.Render import RPGEngine.Input diff --git a/lib/RPGEngine/Data/Game.hs b/lib/RPGEngine/Data/Game.hs new file mode 100644 index 0000000..9f5bd8a --- /dev/null +++ b/lib/RPGEngine/Data/Game.hs @@ -0,0 +1,17 @@ +-- Representation of all the game's data + +module RPGEngine.Data.Game +( Game(..) + ,initGame +) where + +import RPGEngine.Data.Types +import RPGEngine.Data.State + +---------------------------------------------------------------------- + +-- Initialize the game +initGame :: Game +initGame = Game { + state = defaultState +} diff --git a/lib/RPGEngine/Internals/Data/State.hs b/lib/RPGEngine/Data/State.hs similarity index 80% rename from lib/RPGEngine/Internals/Data/State.hs rename to lib/RPGEngine/Data/State.hs index b567517..1953d73 100644 --- a/lib/RPGEngine/Internals/Data/State.hs +++ b/lib/RPGEngine/Data/State.hs @@ -2,21 +2,16 @@ -- e.g. Main menu, game, pause, win or lose -- Allows to easily go to a next state and change rendering accordingly -module RPGEngine.Internals.Data.State +module RPGEngine.Data.State ( State(..) , defaultState , nextState ) where ------------------------------ Constants ------------------------------ +import RPGEngine.Data.Types --- Current state of the game. -data State = Menu - | Playing - | Pause - | Win - | Lose +----------------------------- Constants ------------------------------ -- Default state of the game, Menu defaultState :: State diff --git a/lib/RPGEngine/Data/Types.hs b/lib/RPGEngine/Data/Types.hs new file mode 100644 index 0000000..af812bd --- /dev/null +++ b/lib/RPGEngine/Data/Types.hs @@ -0,0 +1,115 @@ +module RPGEngine.Data.Types where + +-------------------------------- Game -------------------------------- + +-- TODO Add more +data Game = Game { + -- Current state of the game + state :: State +} + +------------------------------- Player ------------------------------- + +data Player = Player { + playerHp :: Maybe Int, + inventory :: [Item] +} + +instance Living Player where + hp = playerHp + +------------------------------- State -------------------------------- + +-- Current state of the game. +data State = Menu + | 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 + +data Item = Item { + itemId :: ItemId, + itemX :: Int, + itemY :: Int, + itemName :: String, + itemDescription :: String, + itemActions :: [([Condition], Action)], + itemValue :: Maybe Int, + useTimes :: Maybe Int +} + +instance Object Item where + id = itemId + x = itemX + y = itemY + name = itemName + description = itemDescription + actions = itemActions + value = itemValue + +data Entity = Entity { + entityId :: EntityId, + entityX :: Int, + entityY :: Int, + entityName :: String, + entityDescription :: String, + entityActions :: [([Condition], Action)], + entityValue :: Maybe Int, + entityHp :: Maybe Int, + direction :: Maybe Direction +} + +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 + +------------------------------ Condition ----------------------------- + +data Condition = InventoryFull + | InventoryContains ItemId + | Not Condition + | AlwaysFalse + deriving (Show, Eq) + +------------------------------- Action ------------------------------- + +data Action = Leave + | RetrieveItem ItemId + | UseItem ItemId + | DecreaseHp EntityId ItemId + | IncreasePlayerHp ItemId + | Nothing + deriving (Show, Eq) + +------------------------------ Direction ----------------------------- + +data Direction = North + | East + | South + | West + deriving (Show) \ No newline at end of file diff --git a/lib/RPGEngine/Input.hs b/lib/RPGEngine/Input.hs index 337a3bc..767a8d4 100644 --- a/lib/RPGEngine/Input.hs +++ b/lib/RPGEngine/Input.hs @@ -4,9 +4,9 @@ module RPGEngine.Input ( handleAllInput ) where -import RPGEngine.Internals.Data.Game -import RPGEngine.Internals.Data.State -import RPGEngine.Internals.Input +import RPGEngine.Data.Types +import RPGEngine.Data.State +import RPGEngine.Input.Core import Graphics.Gloss.Interface.IO.Game diff --git a/lib/RPGEngine/Internals/Input.hs b/lib/RPGEngine/Input/Core.hs similarity index 98% rename from lib/RPGEngine/Internals/Input.hs rename to lib/RPGEngine/Input/Core.hs index d74c6d6..e2e81b9 100644 --- a/lib/RPGEngine/Internals/Input.hs +++ b/lib/RPGEngine/Input/Core.hs @@ -1,7 +1,7 @@ -- Allows to create a massive inputHandler that can handle anything -- after you specify what you want it to do. -module RPGEngine.Internals.Input +module RPGEngine.Input.Core ( InputHandler(..) , composeInputHandlers , handle diff --git a/lib/RPGEngine/Internals/Data/Game.hs b/lib/RPGEngine/Internals/Data/Game.hs deleted file mode 100644 index 7aa8ef4..0000000 --- a/lib/RPGEngine/Internals/Data/Game.hs +++ /dev/null @@ -1,25 +0,0 @@ --- Representation of all the game's data - -module RPGEngine.Internals.Data.Game -( Game(..), - -initGame -) where - -import RPGEngine.Internals.Data.State - ------------------------------ Constants ------------------------------ - --- TODO Add more -data Game = Game { - -- Current state of the game - state :: State -} - ----------------------------------------------------------------------- - --- Initialize the game -initGame :: Game -initGame = Game { - state = defaultState -} diff --git a/lib/RPGEngine/Internals/Data/Internals.hs b/lib/RPGEngine/Internals/Data/Internals.hs deleted file mode 100644 index 476772b..0000000 --- a/lib/RPGEngine/Internals/Data/Internals.hs +++ /dev/null @@ -1,77 +0,0 @@ --- Represents an item in the game. - -module RPGEngine.Internals.Data.Internals -( Action(..) -, Condition(..) -, Object(..) -, EntityId -, ItemId -) where - ------------------------------ Constants ------------------------------ - -type EntityId = String -type ItemId = String - -data Object = - Item { -- All fields are required - -- Easy way to identify items - id :: ItemId, - -- Horizontal coördinate in the level - x :: Int, - -- Vertical coördinate in the level - y :: Int, - name :: String, - -- Short description of the object - description :: String, - -- Counts how often the object can be used by the player. Either - -- infinite or a natural number - useTimes :: Maybe Int, - -- List of conditional actions when the player is standing on this object - actions :: [([Condition], Action)], - -- Interpretation depends on action with this object. - value :: Maybe Int - } - | Entity { - -- Required fields - -- Easy way to identify items - id :: EntityId, - -- Horizontal coördinate in the level - x :: Int, - -- Vertical coördinate in the level - y :: Int, - name :: String, - -- Short description of the object - description :: String, - -- List of conditional actions when the player is standing on this object - actions :: [([Condition], Action)], - -- Optional fields - -- The direction of the item. e.g. a door has a direction. - direction :: Maybe Direction, - -- Some entities have health points. - hp :: Maybe Int, - -- Interpretation depends on action with this object. - value :: Maybe Int - } - -data Direction = North - | East - | South - | West - deriving (Show) - -data Action = Leave - | RetrieveItem ItemId - | UseItem ItemId - | DecreaseHp EntityId ItemId - | IncreasePlayerHp ItemId - | Nothing - deriving (Show, Eq) - -data Condition = InventoryFull - | InventoryContains ItemId - | Not Condition - | AlwaysFalse - deriving (Show, Eq) - ----------------------------------------------------------------------- diff --git a/lib/RPGEngine/Internals/Data/Player.hs b/lib/RPGEngine/Internals/Data/Player.hs deleted file mode 100644 index c325df0..0000000 --- a/lib/RPGEngine/Internals/Data/Player.hs +++ /dev/null @@ -1,15 +0,0 @@ --- Represents a player in the game. This player can move around, pick --- up items and interact with the world. - -module RPGEngine.Internals.Data.Player -( Player(..) -) where - -import RPGEngine.Internals.Data.Internals - ------------------------------ Constants ------------------------------ - -data Player = Player { - hp :: Int, - inventory :: [Object] -} \ No newline at end of file diff --git a/lib/RPGEngine/Parse.hs b/lib/RPGEngine/Parse.hs index 15d3458..477b150 100644 --- a/lib/RPGEngine/Parse.hs +++ b/lib/RPGEngine/Parse.hs @@ -1,6 +1,6 @@ module RPGEngine.Parse where -import RPGEngine.Internals.Data.Game +import RPGEngine.Data.Types -- TODO parseFromFile gebruiken diff --git a/lib/RPGEngine/Internals/Parse.hs b/lib/RPGEngine/Parse/Core.hs similarity index 94% rename from lib/RPGEngine/Internals/Parse.hs rename to lib/RPGEngine/Parse/Core.hs index 1118d85..7e704ab 100644 --- a/lib/RPGEngine/Internals/Parse.hs +++ b/lib/RPGEngine/Parse/Core.hs @@ -1,4 +1,4 @@ -module RPGEngine.Internals.Parse where +module RPGEngine.Parse.Core where import Text.Parsec import Text.Parsec.String diff --git a/lib/RPGEngine/Internals/Parse/StructureElement.hs b/lib/RPGEngine/Parse/StructureElement.hs similarity index 94% rename from lib/RPGEngine/Internals/Parse/StructureElement.hs rename to lib/RPGEngine/Parse/StructureElement.hs index f9955fd..e8f4b34 100644 --- a/lib/RPGEngine/Internals/Parse/StructureElement.hs +++ b/lib/RPGEngine/Parse/StructureElement.hs @@ -1,7 +1,7 @@ -module RPGEngine.Internals.Parse.StructureElement where +module RPGEngine.Parse.StructureElement where -import RPGEngine.Internals.Data.Internals (Action(..), Condition(..)) -import RPGEngine.Internals.Parse ( ignoreWS ) +import RPGEngine.Data.Types (Action(..), Condition(..)) +import RPGEngine.Parse.Core ( ignoreWS ) import Text.Parsec ( char, @@ -134,7 +134,7 @@ action = try $ do | script == "useItem" = UseItem arg | script == "decreaseHp" = DecreaseHp first second | script == "increasePlayerHp" = IncreasePlayerHp arg - | otherwise = RPGEngine.Internals.Data.Internals.Nothing + | otherwise = RPGEngine.Data.Types.Nothing (first, ',':second) = break (== ',') arg return $ Action answer diff --git a/lib/RPGEngine/Render.hs b/lib/RPGEngine/Render.hs index e65d589..ca39b23 100644 --- a/lib/RPGEngine/Render.hs +++ b/lib/RPGEngine/Render.hs @@ -7,8 +7,7 @@ module RPGEngine.Render , render ) where -import RPGEngine.Internals.Data.Game(Game(..)) -import RPGEngine.Internals.Data.State(State(..)) +import RPGEngine.Data.Types import Graphics.Gloss ----------------------------- Constants ------------------------------ diff --git a/rpg-engine.cabal b/rpg-engine.cabal index bc85730..4968079 100644 --- a/rpg-engine.cabal +++ b/rpg-engine.cabal @@ -13,17 +13,18 @@ library exposed-modules: RPGEngine - RPGEngine.Input - RPGEngine.Parse - RPGEngine.Render + RPGEngine.Data.Game + RPGEngine.Data.Types + RPGEngine.Data.State - RPGEngine.Internals.Data.Game - RPGEngine.Internals.Data.Internals - RPGEngine.Internals.Data.Player - RPGEngine.Internals.Data.State - RPGEngine.Internals.Input - RPGEngine.Internals.Parse - RPGEngine.Internals.Parse.StructureElement + RPGEngine.Input + RPGEngine.Input.Core + + RPGEngine.Parse + RPGEngine.Parse.Core + RPGEngine.Parse.StructureElement + + RPGEngine.Render executable rpg-engine main-is: Main.hs