This commit is contained in:
Tibo De Peuter 2022-12-23 12:06:46 +01:00
parent f284413836
commit 11eb00ea0b
6 changed files with 59 additions and 21 deletions

View file

@ -6,7 +6,6 @@ import RPGEngine.Data
import RPGEngine.Parse.Core
import RPGEngine.Parse.TextToStructure
import RPGEngine.Parse.StructureToGame
import RPGEngine.Parse.TextToStructure (gameFile)
spec :: Spec
spec = do
@ -40,7 +39,7 @@ spec = do
pendingWith "Still need to write this"
it "Game with multiple levels" $ do
pendingWith "Still need to write this"
describe "Player" $ do
it "cannot die" $ do
let input = "player: { hp: infinite, inventory: [] }"
@ -65,7 +64,7 @@ spec = do
}
Right (Entry (Tag "player") struct) = parseWith structure input
structureToPlayer 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 {
@ -95,7 +94,7 @@ spec = do
correct = Item {
itemId = "dagger",
itemX = 0,
itemY = 0,
itemY = 0,
itemName = "Dagger",
itemDescription = "Basic dagger you found somewhere",
itemValue = Just 10,
@ -104,7 +103,7 @@ spec = do
}
Right struct = parseWith structure input
structureToItem 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 {
@ -122,30 +121,36 @@ spec = do
}
Right struct = parseWith structure input
structureToItem struct `shouldBe` correct
describe "Actions" $ do
it "no conditions" $ do
let input = "{[] leave()}"
correct = [([], Leave)]
Right struct = parseWith structure input
structureToActions struct `shouldBe` correct
it "single condition" $ do
let input = "{ [inventoryFull()] useItem(itemId)}"
correct = [([InventoryFull], UseItem "itemId")]
Right struct = parseWith structure input
structureToActions 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 structure input
structureToActions struct `shouldBe` correct
it "DecreaseHp(entityid, itemid)" $ do
let input = "{ [] decreaseHp(devil, sword) }"
correct = [([], DecreaseHp "devil" "sword")]
Right struct = parseWith structure input
structureToActions struct `shouldBe` correct
describe "Entities" $ do
it "Simple entity" $ do
pendingWith "still need to write this"
describe "Level" $ do
it "Simple layout" $ do
let input = "{ layout: { | * * * * * *\n| * s . . e *\n| * * * * * *\n }, items: [], entities: [] }"

View file

@ -146,10 +146,14 @@ spec = do
correct = Right $ Regular $ Action $ UseItem "secondId"
parseWith regular input `shouldBe` correct
let input = "decreaseHp(entityId,objectId)"
let input = "decreaseHp(entityId, objectId)"
correct = Right $ Regular $ Action $ DecreaseHp "entityId" "objectId"
parseWith regular input `shouldBe` correct
let input = "decreaseHp(entityId,objectId)"
correct = Right $ Regular $ Action $ DecreaseHp "entityId" "objectId"
parseWith regular input `shouldBe` correct
let input = "increasePlayerHp(objectId)"
correct = Right $ Regular $ Action $ IncreasePlayerHp "objectId"
parseWith regular input `shouldBe` correct