private static bool ValidateCreationObject( TileLayerCO creationObject ) { //not implemented yet, but this will be used to verify all creation objects //if the creation object is not valid, return null return true; }
//Read and parse selected layer file private static TileLayerCO ProcessLayer(string layerFileName) { try { //Instantiate the creation object to hold all creation data of this tile layer TileLayerCO tileLayerCO = new TileLayerCO(); //layer Layout list of index to be read in, in the future instead of an integer index, it will probably be an object using (StreamReader streamReader = new StreamReader(layerFileName)) { bool readingTextures = false; bool readingProperties = false; bool readingLayout = false; while (!streamReader.EndOfStream) { string line = streamReader.ReadLine().Trim(); if (!string.IsNullOrEmpty(line)) { if (line.Contains("[Textures]")) { readingTextures = true; readingProperties = false; readingLayout = false; } else if (line.Contains("[Properties]")) { readingTextures = false; readingProperties = true; readingLayout = false; ; } else if (line.Contains("[Layout]")) { readingTextures = false; readingProperties = false; readingLayout = true; } else if (readingTextures) { tileLayerCO.LayerTextureNameList.Add(line); } else if (readingProperties) { string[] propertyPairs = line.Split('='); //There should always be an index 0 / and 1 for the property pairs. Probably should add a try-catch here to handle when this isn't the case string key = propertyPairs[0].Trim(); string value = propertyPairs[1].Trim(); tileLayerCO.LayerPropertyDictionary.Add(key, value); } else if (readingLayout) { List<int> row = new List<int>(); String[] textureIndexes = line.Split(','); foreach (String textureIndex in textureIndexes) { //Should be trimmed but this is a backup if (!String.IsNullOrEmpty(textureIndex)) row.Add(Convert.ToInt32(textureIndex.Trim())); } tileLayerCO.LayerIndexLayout.Add(row); } } } } return tileLayerCO; } catch (Exception e) { throw e; } }