Here's a file I converted from BlitzMax, it can take simple YAML files and saves/loads them. I am basically using this as a way to be able to store complex information into SaveState() and LoadState() Please note I have only tested it on HTML5 so far, and it's works on my Firefox aswell as Chrome broswers. There may (probably?) be bugs still within the code, I just wanted to get this out as soon as I confirmed it's working.
Here's a sample usage:
local stateFile := New YAMLFile("state")
local lastState:String = LoadState()
Print "'"+lastState+"'"
if lastState = ""
local tmpEle:YAMLElement = stateFile.GetElement("PlayerData",true)
tmpEle.GetChildElement("position",true).data = playerShip.pos.ToString()
tmpEle.GetChildElement("target",true).data = target.ToString()
else
stateFile.__debug = true
stateFile.ParseFromString( lastState )
if not stateFile.elements.IsEmpty() then
local parts:String[] = stateFile.GetElement("PlayerData").GetChildElement("position").data.Split(",")
playerShip.pos.x = float(parts[0])
playerShip.pos.y = float(parts[1])
parts = stateFile.GetElement("PlayerData").GetChildElement("target").data.Split(",")
target.x = float(parts[0])
target.y = float(parts[1])
else
local tmpEle:YAMLElement = stateFile.GetElement("PlayerData",true)
tmpEle.GetChildElement("position",true).data = playerShip.pos.ToString()
tmpEle.GetChildElement("target",true).data = target.ToString()
end
stateFile.__debug = false
end
Vector is my own simple class with just x and y fields and ToString() outputs "x,y".
|