So, I'm building myself a browser based rpg using Javascript. Originally, my level had a single layer and was loaded from a javascript 2d map array. However, I'm changing my code to allow support for multiple layers loaded from a file.
I can retrieve the file data without too many problems, however, I have no idea how to parse the information into useable arrays.
The contents of my text file are as follows;
LAYER
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
LAYER
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0
My Ajax and PHP for retrieving the level;
// JAVASCRIPT
$.ajax({
type: 'POST',
url: 'lib/ajax.php',
data: {method: 'getLevel'},
success: function(data){
},
error: function(x, h, r){
console.log(x, h, r);
}
})
// PHP FILE 2
public function getLevel(){
$file = file_get_contents('../levels/level1.txt');
echo $file;
}
There is an intermediate file handling all of my ajax requests, passing them to a functions class.
I can get my level data fine, I just don't know what to do with it once I have it.
I know I can get someway towards achieving this by adding newline characters at the end of each group, and parsing them that way. However, this will become a nightmare when implementing a tile editor in the future. Do you guys have any suggestions how to go about this? Would you suggest parsing at the php or javascript level, or both?