module ParseGameSpec where import Test.Hspec import RPGEngine.Parse.StructElement import RPGEngine.Data import RPGEngine.Parse.Core import RPGEngine.Parse.Game spec :: Spec spec = do describe "Game" $ do it "TODO: Simple game" $ do pending it "TODO: More complex game" $ do pending it "TODO: Game with multiple levels" $ do pending describe "Player" $ do 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 "Layout" $ do it "simple" $ do pending describe "Items" $ do 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 "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 "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