#10 #18 Fix parsing

This commit is contained in:
Tibo De Peuter 2022-12-22 22:05:25 +01:00
parent 5cc96cbdba
commit f3bce99120
18 changed files with 289 additions and 103 deletions

View file

@ -10,26 +10,25 @@ import RPGEngine.Data
entityActions, entityValue, entityHp, direction),
Item(itemId, itemX, itemY, itemName, itemDescription, itemValue,
itemActions, useTimes),
Level(layout, items, entities),
Level(layout, items, entities, index),
Game (..), State (..) )
import RPGEngine.Parse.TextToStructure
( Value(Infinite, Action, Layout, String, Direction, Integer),
Key(Tag, ConditionList),
Structure(..) )
import RPGEngine.Data.Default (defaultPlayer, defaultLevel, defaultItem, defaultEntity)
import RPGEngine.Input.Playing (putCoords, spawnPlayer)
------------------------------ Exported ------------------------------
structureToGame :: Structure -> Game
-- structureToGame [Entry(Tag "player") playerBlock, Entry(Tag "levels") levelsBlock] = game
structureToGame (Entry (Tag "player") playerBlock) = game
where game = Game{ state = newState }
newState = Playing{ levels = newLevels, level = currentLevel, player = newPlayer, restart = newState }
-- newLevels = structureToLevels levelsBlock
-- currentLevel = head newLevels
newLevels = [defaultLevel]
currentLevel = defaultLevel
newPlayer = structureToPlayer playerBlock
structureToGame :: [Structure] -> Game
structureToGame [Entry (Tag "player") playerBlock, Entry (Tag "levels") levelsBlock] = game
where game = Game newState
newState = Playing newLevels 0 currentLevel newPlayer newState
newLevels = structureToLevels levelsBlock
currentLevel = head newLevels
newPlayer = spawnPlayer currentLevel $ structureToPlayer playerBlock
structureToGame _ = Game Menu
------------------------------- Player -------------------------------
@ -60,7 +59,9 @@ structureToLevels (Block struct) = structureToLevel <$> struct
structureToLevels _ = [defaultLevel]
structureToLevel :: Structure -> Level
structureToLevel (Block entries) = structureToLevel' entries defaultLevel
structureToLevel (Block entries) = indexIsSet
where indexIsSet = level{ index = putCoords level }
level = structureToLevel' entries defaultLevel
structureToLevel _ = defaultLevel
structureToLevel' :: [Structure] -> Level -> Level