Permalink
Browse files

- Status commit.

- World parser under construction.
  • Loading branch information...
graninas committed Feb 2, 2014
1 parent 02f2da3 commit 314135ec65960e052913cfb9487f563e8abb1491
@@ -3,6 +3,8 @@ module GameLogic.Language.Parsers.ItemParser where
import Middleware.Parsing.Facade as P
import GameLogic.Data.Facade
+import Control.Monad (liftM)
+
data ResourceToken = IntResource String (Int, Int)
deriving (Show, Read, Eq)
@@ -15,17 +17,13 @@ itemTokens :: GenParser Char st [ItemToken]
itemTokens = many itemToken
itemToken :: GenParser Char st ItemToken
-itemToken = emptyToken <|> comment <|> item <?> "token"
+itemToken = emptyToken <|> comment <|> item <?> "itemToken"
emptyToken :: GenParser Char st ItemToken
emptyToken = eol >> return EmptyToken
comment :: GenParser Char st ItemToken
-comment = do
- char ';'
- str <- many (noneOf "\n\r")
- lineEnd
- return $ Comment str
+comment = liftM Comment commentString
item :: GenParser Char st ItemToken
item = do
@@ -1,6 +1,81 @@
module GameLogic.Language.Parsers.WorldParser where
import Middleware.Parsing.Facade as P
+import GameLogic.Parsers.Common
+
+import Control.Monad (liftM)
+
import GameLogic.Data.Facade
+data PropertyToken = IntProperty String Int
+ | ObjectProperty String
+ | CellsProperty
+ deriving (Show, Read, Eq)
+
+data WorldToken = Comment String
+ | World String [PropertyToken]
+ | EmptyToken
+ deriving (Show, Read, Eq)
+
+worldTokens :: GenParser Char st [WorldToken]
+worldTokens = many worldToken
+
+worldToken :: GenParser Char st WorldToken
+worldToken = emptyToken <|> comment <|> item <?> "worldToken"
+
+emptyToken :: GenParser Char st WorldToken
+emptyToken = eol >> return EmptyToken
+
+comment :: GenParser Char st WorldToken
+comment = liftM Comment commentString
+
+world :: GenParser Char st WorldToken
+world = do
+ string "World" >> many1 trueSpace
+ itemName <- stringConstant
+ lineEnd
+ rs <- properties
+ return $ World itemName rs
+
+properties :: GenParser Char st [PropertyToken]
+properties = many property
+
+property :: GenParser Char st PropertyToken
+property = do
+ identation 4
+ name <- identifier
+ case name of
+ "width" -> intProperty name
+ "height" -> intProperty name
+ "defaultCell" -> objectProperty name
+ "cells" -> cellsProperty name
+
+intProperty name = do
+ assignment
+ val <- integerConstant
+ lineEnd
+ return $ IntProperty name val
+
+objectProperty name = do
+ assignment
+ o <- object
+
+
+
+; World definition file
+World "Pandora"
+ width = 20
+ height = 20
+ defaultCell = Object "Empty"
+ cells =
+ (10, 10): Object "Karyon" "Player1"
+ (9, 9): Object "Plasma" "Player1"
+ (9, 10): Object "Plasma" "Player1"
+ (9, 11): Object "Plasma" "Player1"
+ (10, 9): Object "Plasma" "Player1"
+ (10, 11): Object "Plasma" "Player1"
+ (11, 9): Object "Plasma" "Player1"
+ (11, 10): Object "Plasma" "Player1"
+ (11, 11): Object "Plasma" "Player1"
+ (15, 15): Object "Karyon" "Player2"
@@ -28,4 +28,13 @@ eol = try (string "\n\r") <|> try (string "\r\n") <|> try (string "\n") <|> try
identation :: Int -> GenParser Char st String
identation cnt = count cnt trueSpace
-lineEnd = trueSpaces >> optional eol
+lineEnd = trueSpaces >> optional eol
+
+commentString :: GenParser Char st String
+commentString = do
+ char ';'
+ str <- many (noneOf "\n\r")
+ lineEnd
+ return str
+
+assignment = trueSpaces >> char '=' >> trueSpaces
@@ -0,0 +1,17 @@
+; World definition file
+
+World "Pandora"
+ width = 20
+ height = 20
+ defaultCell = Object "Empty"
+ cells =
+ (10, 10): Object "Karyon" "Player1"
+ (9, 9): Object "Plasma" "Player1"
+ (9, 10): Object "Plasma" "Player1"
+ (9, 11): Object "Plasma" "Player1"
+ (10, 9): Object "Plasma" "Player1"
+ (10, 11): Object "Plasma" "Player1"
+ (11, 9): Object "Plasma" "Player1"
+ (11, 10): Object "Plasma" "Player1"
+ (11, 11): Object "Plasma" "Player1"
+ (15, 15): Object "Karyon" "Player2"
View
@@ -0,0 +1,17 @@
+; World definition file
+
+World "Pandora"
+ width = 20
+ heigth = 20
+ defaultCell = Object "Empty" "Player0"
+ cells =
+ (10, 10): Object "Karyon" "Player1"
+ (9, 9): Object "Plasma" "Player1"
+ (9, 10): Object "Plasma" "Player1"
+ (9, 11): Object "Plasma" "Player1"
+ (10, 9): Object "Plasma" "Player1"
+ (10, 11): Object "Plasma" "Player1"
+ (11, 9): Object "Plasma" "Player1"
+ (11, 10): Object "Plasma" "Player1"
+ (11, 11): Object "Plasma" "Player1"
+ (15, 15): Onject "Karyon" "Player2"
View
@@ -0,0 +1,17 @@
+; World definition file
+
+World "Pandora"
+ width = 20
+ heigth = 20
+ defaultCell = Object "Empty"
+ cells =
+ (10, 10): Object "Karyon" "Player1"
+ (9, 9): Object "Plasma" "Player1"
+ (9, 10): Object "Plasma" "Player1"
+ (9, 11): Object "Plasma" "Player1"
+ (10, 9): Object "Plasma" "Player1"
+ (10, 11): Object "Plasma" "Player1"
+ (11, 9): Object "Plasma" "Player1"
+ (11, 10): Object "Plasma" "Player1"
+ (11, 11): Object "Plasma" "Player1"
+ (15, 15): Onject "Karyon" "Player2"
View
@@ -10,3 +10,12 @@ Item "Conductor"
lifebound = (0, 1000)
durability = (100, 100)
energy = (0, 100)
+
+; Conductor
+Item "Plasma"
+ lifebound = (0, 1000)
+ durability = (100, 100)
+ energy = (0, 100)
+
+; Empty
+Item "Empty"
View
@@ -0,0 +1,18 @@
+; General items
+
+Item "Karyon"
+ lifebound = (0, 5000)
+ durability = (100, 100)
+ energy = (300, 2000)
+
+; Conductor
+Item "Conductor"
+ lifebound = (0, 1000)
+ durability = (100, 100)
+ energy = (0, 100)
+
+; Conductor
+Item "Plasma"
+ lifebound = (0, 1000)
+ durability = (100, 100)
+ energy = (0, 100)

0 comments on commit 314135e

Please sign in to comment.