#18 Started conversion to Game
This commit is contained in:
parent
d4fbcda73b
commit
de02c7113f
11 changed files with 300 additions and 112 deletions
|
@ -1,7 +1,10 @@
|
|||
module ParseGameSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import RPGEngine.Parse.StructureElement
|
||||
import RPGEngine.Parse.StructElement
|
||||
import RPGEngine.Data
|
||||
import RPGEngine.Parse.Core
|
||||
import RPGEngine.Parse.Game
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
|
@ -14,39 +17,118 @@ spec = do
|
|||
pending
|
||||
|
||||
describe "Player" $ do
|
||||
it "TODO: Simple player" $ do
|
||||
pending
|
||||
it "cannot die" $ do
|
||||
let input = "player: { hp: infinite, inventory: [] }"
|
||||
correct = Player {
|
||||
playerHp = Prelude.Nothing,
|
||||
inventory = []
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
it "without inventory" $ do
|
||||
let input = "player: { hp: 50, inventory: [] }"
|
||||
correct = Player {
|
||||
playerHp = Just 50,
|
||||
inventory = []
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
it "with inventory" $ do
|
||||
let input = "player: { hp: 50, inventory: [ { id: \"dagger\", x: 0, y: 0, name: \"Dolk\", description: \"Basis schade tegen monsters\", useTimes: infinite, value: 10, actions: {} } ] }"
|
||||
correct = Player {
|
||||
playerHp = Just 50,
|
||||
inventory = [
|
||||
Item {
|
||||
itemId = "dagger",
|
||||
itemX = 0,
|
||||
itemY = 0,
|
||||
itemName = "Dolk",
|
||||
itemDescription = "Basis schade tegen monsters",
|
||||
itemActions = [],
|
||||
itemValue = Just 10,
|
||||
useTimes = Prelude.Nothing
|
||||
}
|
||||
]
|
||||
}
|
||||
Right (Entry (Tag "player") struct) = parseWith structElement input
|
||||
structToPlayer struct `shouldBe` correct
|
||||
|
||||
describe "Inventory" $ do
|
||||
it "TODO: Empty inventory" $ do
|
||||
describe "Layout" $ do
|
||||
it "simple" $ do
|
||||
pending
|
||||
it "TODO: Singleton inventory" $ do
|
||||
pending
|
||||
it "TODO: Filled inventory" $ do
|
||||
pending
|
||||
|
||||
|
||||
describe "Items" $ do
|
||||
it "TODO: Simple item" $ do
|
||||
pending
|
||||
-- Check id
|
||||
-- Check x
|
||||
-- Check y
|
||||
-- Check name
|
||||
-- Check description
|
||||
-- Check useTimes
|
||||
-- Check value
|
||||
-- Check actions
|
||||
it "simple" $ do
|
||||
let input = "{ id: \"dagger\", x: 0, y: 0, name: \"Dagger\", description: \"Basic dagger you found somewhere\", useTimes: infinite, value: 10, actions: {} }"
|
||||
correct = Item {
|
||||
itemId = "dagger",
|
||||
itemX = 0,
|
||||
itemY = 0,
|
||||
itemName = "Dagger",
|
||||
itemDescription = "Basic dagger you found somewhere",
|
||||
itemValue = Just 10,
|
||||
itemActions = [],
|
||||
useTimes = Prelude.Nothing
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToItem struct `shouldBe` correct
|
||||
|
||||
it "with actions" $ do
|
||||
let input = "{ id: \"key\", x: 3, y: 1, name: \"Doorkey\", description: \"Unlocks a secret door\", useTimes: 1, value: 0, actions: { [not(inventoryFull())] retrieveItem(key), [] leave() } }"
|
||||
correct = Item {
|
||||
itemId = "key",
|
||||
itemX = 3,
|
||||
itemY = 1,
|
||||
itemName = "Doorkey",
|
||||
itemDescription = "Unlocks a secret door",
|
||||
itemActions = [
|
||||
([], Leave),
|
||||
([Not InventoryFull], RetrieveItem "key")
|
||||
],
|
||||
itemValue = Just 0,
|
||||
useTimes = Just 1
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToItem struct `shouldBe` correct
|
||||
|
||||
describe "Actions" $ do
|
||||
it "TODO: Simple action" $ do
|
||||
pending
|
||||
|
||||
it "no conditions" $ do
|
||||
let input = "{[] leave()}"
|
||||
correct = [([], Leave)]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
it "single condition" $ do
|
||||
let input = "{ [inventoryFull()] useItem(itemId)}"
|
||||
correct = [([InventoryFull], UseItem "itemId")]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
it "multiple conditions" $ do
|
||||
let input = "{ [not(inventoryFull()), inventoryContains(itemId)] increasePlayerHp(itemId)}"
|
||||
correct = [([Not InventoryFull, InventoryContains "itemId"], IncreasePlayerHp "itemId")]
|
||||
Right struct = parseWith structElement input
|
||||
structToActions struct `shouldBe` correct
|
||||
|
||||
describe "Entities" $ do
|
||||
it "TODO: Simple entity" $ do
|
||||
pending
|
||||
|
||||
describe "Level" $ do
|
||||
it "TODO: Simple layout" $ do
|
||||
pending
|
||||
it "Simple layout" $ do
|
||||
let input = "{ layout: { | * * * * * * \n| * s . . e *\n| * * * * * *\n}, items: [], entities: [] }"
|
||||
correct = Level {
|
||||
RPGEngine.Data.layout = [
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked],
|
||||
[Blocked, Entrance, Walkable, Walkable, Exit, Blocked],
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked]
|
||||
],
|
||||
items = [],
|
||||
entities = []
|
||||
}
|
||||
Right struct = parseWith structElement input
|
||||
structToLevel struct `shouldBe` correct
|
||||
it "TODO: Complex layout" $ do
|
||||
pending
|
|
@ -1,10 +1,10 @@
|
|||
module ParseStructureElementSpec where
|
||||
module ParseStructElementSpec where
|
||||
|
||||
import Test.Hspec
|
||||
|
||||
import RPGEngine.Data
|
||||
import RPGEngine.Parse.Core
|
||||
import RPGEngine.Parse.StructureElement
|
||||
import RPGEngine.Parse.StructElement
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
|
@ -12,21 +12,21 @@ spec = do
|
|||
it "can parse blocks" $ do
|
||||
let input = "{}"
|
||||
correct = Right $ Block []
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
parseWith structElement input `shouldBe` correct
|
||||
|
||||
let input = "{{}}"
|
||||
correct = Right $ Block [Block []]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
parseWith structElement input `shouldBe` correct
|
||||
|
||||
let input = "{{}, {}}"
|
||||
correct = Right $ Block [Block [], Block []]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
parseWith structElement input `shouldBe` correct
|
||||
|
||||
let input = "{ id: 1 }"
|
||||
correct = Right (Block [
|
||||
Entry (Tag "id") $ Regular $ Integer 1
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
let input = "{ id: \"key\", x: 3, y: 1}"
|
||||
correct = Right $ Block [
|
||||
|
@ -34,14 +34,14 @@ spec = do
|
|||
Entry (Tag "x") $ Regular $ Integer 3,
|
||||
Entry (Tag "y") $ Regular $ Integer 1
|
||||
]
|
||||
parseWith structureElement input `shouldBe` correct
|
||||
parseWith structElement input `shouldBe` correct
|
||||
|
||||
let input = "actions: { [not(inventoryFull())] retrieveItem(key), [] leave()}"
|
||||
correct = Right (Entry (Tag "actions") $ Block [
|
||||
Entry (ConditionList [Not InventoryFull]) $ Regular $ Action $ RetrieveItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, name:\"Secret door\", description: \"This secret door can only be opened with a key\", direction: left, y: 1}]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
|
@ -52,7 +52,7 @@ spec = do
|
|||
Entry (Tag "direction") $ Regular $ Direction West,
|
||||
Entry (Tag "y") $ Regular $ Integer 1
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, y: 1, name:\"Secret door\", description: \"This secret door can only be opened with a key\", actions: { [inventoryContains(key)] useItem(key), [] leave() } } ]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
|
@ -66,7 +66,7 @@ spec = do
|
|||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
]
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
let input = "entities: [ { id: \"door\", x: 4, y: 1, name:\"Secret door\", description: \"This secret door can only be opened with a key\", direction: left , actions: { [inventoryContains(key)] useItem(key), [] leave() } } ]"
|
||||
correct = Right (Entry (Tag "entities") $ Block [ Block [
|
||||
|
@ -81,7 +81,7 @@ spec = do
|
|||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
]
|
||||
]], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
it "can parse entries" $ do
|
||||
let input = "id: \"dagger\""
|
||||
|
@ -105,7 +105,7 @@ spec = do
|
|||
Entry (ConditionList [Not InventoryFull]) $ Regular $ Action $ RetrieveItem "key",
|
||||
Entry (ConditionList []) $ Regular $ Action Leave
|
||||
], "")
|
||||
parseWithRest structureElement input `shouldBe` correct
|
||||
parseWithRest structElement input `shouldBe` correct
|
||||
|
||||
it "can parse regulars" $ do
|
||||
let input = "this is a string"
|
||||
|
@ -237,19 +237,19 @@ spec = do
|
|||
it "can parse directions" $ do
|
||||
let input = "up"
|
||||
correct = Right $ Direction North
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
parseWith RPGEngine.Parse.StructElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "right"
|
||||
correct = Right $ Direction East
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
parseWith RPGEngine.Parse.StructElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "down"
|
||||
correct = Right $ Direction South
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
parseWith RPGEngine.Parse.StructElement.direction input `shouldBe` correct
|
||||
|
||||
let input = "left"
|
||||
correct = Right $ Direction West
|
||||
parseWith RPGEngine.Parse.StructureElement.direction input `shouldBe` correct
|
||||
parseWith RPGEngine.Parse.StructElement.direction input `shouldBe` correct
|
||||
|
||||
it "can parse layouts" $ do
|
||||
let input = "| * * * * * * * *\n| * s . . . . e *\n| * * * * * * * *"
|
||||
|
@ -258,7 +258,7 @@ spec = do
|
|||
[Blocked, Entrance, Walkable, Walkable, Walkable, Walkable, Exit, Blocked],
|
||||
[Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked, Blocked]
|
||||
]
|
||||
parseWith RPGEngine.Parse.StructureElement.layout input `shouldBe` correct
|
||||
parseWith RPGEngine.Parse.StructElement.layout input `shouldBe` correct
|
||||
|
||||
describe "Brackets" $ do
|
||||
it "matches closing <" $ do
|
Reference in a new issue