Map reader

by parakeet

JavaScript

let JSONData = {"mappers":[]};
let rawData;

let currentMapper = null;
let mapList = [];
let currentWord = "";
let char = "";

function parse(){

	for(let i = 0; i < rawData.length; i++){
    char = rawData.charAt(i);

    //if a mapper hasn't been selected yet
    if(char == "/"){
    
    	//puts the previous mapper into the JSONData
    	if(currentMapper != null){
      	//if the last map's name has a space at the end, get rid of it
      	if(currentWord.charAt(currentWord.length - 1) == " "){
        	currentWord = currentWord.substring(0, currentWord.length - 1);
        }
      	mapList[mapList.length] = currentWord;
      	JSONData.mappers[JSONData.mappers.length] = {"name": currentMapper, "maps": mapList};
        currentMapper = null;
        mapList = [];
        currentWord = "";
      }

    //find the mapper's full name (name ends when "(" is found)
      while(char != "("){
        if(char != " " && char != "/"){
          currentWord += char;
        }
        i++;
        char = rawData.charAt(i);
      }
      //set up for finding this mapper's maps
      currentMapper = currentWord;
      currentWord = "";
      i++;
      char = rawData.charAt(i);
    }


    //records this maps name and sets up for the next
		if(char == ","){
    	//if the map's name has a space at the end, get rid of it
      if(currentWord.charAt(currentWord.length - 1) == " "){
      	currentWord = currentWord.substring(0, currentWord.length - 1);
      }
    	mapList[mapList.length] = currentWord;
      currentWord = "";
      i++;
      continue;
    }
    
    //constructs the map name
    currentWord += char;


  }
	//put the last mapper in the JSONData
	mapList[mapList.length] = currentWord;
	JSONData.mappers[JSONData.mappers.length] = {"name": currentMapper, "maps": mapList};
	console.log(JSON.stringify(JSONData));
  console.log(JSONData);
}





rawData = "/Shinxray(VivaPinata, RoyalFlush, Bloons, TimeGear, GravityRush, Waluigi, Merry, CalamityShrine, Lucina, QB,...