public static void SaveLayer(string contentPath, string newFileName, EditorTileLayer tileLayer, List<string>textureFileNames) { //How layer saving will work is, we need to keep in mind when saving, when loading files in they must be loaded in a //particular order. Saving must obey this order. //Currently its Texturelist, Property list, tile layout try { using (StreamWriter writer = new StreamWriter(newFileName)) { writer.WriteLine("[Textures]"); foreach (string textureName in textureFileNames) { string fullTexturePath = contentPath + "\\" + textureName; //save the texture, only if it exists currently in the content path string fullPathWithExtension = string.Empty; foreach (string ext in imageExtensions) { if (File.Exists(fullTexturePath + ext)) { fullPathWithExtension = fullTexturePath + ext; break; } } if( !string.IsNullOrEmpty( fullPathWithExtension ) ) writer.WriteLine(fullPathWithExtension); } writer.WriteLine(); //Write properties writer.WriteLine("[Properties]"); //alpha channel writer.WriteLine("Alpha = " + tileLayer.Alpha.ToString() ); //layer Type writer.WriteLine("Layer Type Index = " + ((int)tileLayer.LayerLayoutType).ToString() ); writer.WriteLine(); //Layout writer.WriteLine("[Layout]"); writer.WriteLine(); for (int x = 0; x < tileLayer.LayoutWidth; x++) { string layerRow = string.Empty; for (int y = 0; y < tileLayer.LayoutHeight; y++) { layerRow += tileLayer.GetCellIndex(x, y).ToString() + " , "; } writer.WriteLine(layerRow); } } } catch (Exception e) { throw e; } }
public TileLayerHandler() { //current layer will start off empty m_currentLayer = null; //Cells will be -1 to mean no layer cells being hovered over m_cellX = -1; m_cellY = -1; m_tileLayerDictionary = new Dictionary<string, EditorTileLayer>(); }
public static void SaveLayer( string contentPath, string newFileName, EditorTileLayer tileLayer, List<string>textureFileNames ) { try { EngineFileHandler.SaveLayer( contentPath, newFileName, tileLayer, textureFileNames); } catch( Exception e ) { throw e; } }
//Try to open and read from a selected layer public static EditorTileLayerDO OpenEditorLayer(string layerFileName) { try { TileLayerCO layerCreationObject = ProcessLayer( layerFileName ); //Validate this creation object (not yet implemented) if( ValidateCreationObject( layerCreationObject ) ) { //Loop through properties of the layer (alpha channel etc.. ), and store them to initiate/set values in the layer //Property values: alpha channel and layer type - default being normal float alphaValue = 0.0f; LayerType.LayerTypesEnum layerType = LayerType.LayerTypesEnum.Normal; foreach (KeyValuePair<string, string> propertyPair in layerCreationObject.LayerPropertyDictionary) { //handle all properties in switch switch (propertyPair.Key.Trim().ToLower()) { case "alpha": alphaValue = float.Parse(propertyPair.Value); break; case "layer type index": layerType = (LayerType.LayerTypesEnum)(int.Parse( propertyPair.Value ) ); break; default: break; } } //Create new editor tile layer EditorTileLayer editorTileLayer = new EditorTileLayer( layerCreationObject.LayerWidth, layerCreationObject.LayerHeight, layerType ); //Set all properties of tile layer, and intialize all editor tiles within this editor layer for (int x = 0; x < layerCreationObject.LayerWidth; x++) for (int y = 0; y < layerCreationObject.LayerHeight; y++) editorTileLayer.SetCellIndex( x, y, layerCreationObject.LayerIndexLayout[x][y]); //Set the return data object, to return the initialized editor tile layer, and the texture names, so the necessary textures //can be added to managed data, and added into the layer's texture list. EditorTileLayerDO editorLayerDO = new EditorTileLayerDO( editorTileLayer, layerCreationObject.LayerTextureNameList ); return editorLayerDO; } else return null; } catch( Exception e ) { throw e; } }
public void UpdateCurrentLayer(string layerKey) { if (m_tileLayerDictionary.ContainsKey(layerKey)) { m_currentLayer = m_tileLayerDictionary[layerKey]; } }
//If layer exists, remove it. If that layer is the current layer, set current layer to null public void RemoveLayer(string layerKey) { if (m_tileLayerDictionary.ContainsKey(layerKey)) { if (m_currentLayer != null) { if (m_currentLayer.Equals(m_tileLayerDictionary[layerKey])) m_currentLayer = null; } m_tileLayerDictionary.Remove( layerKey ); } }
public EditorTileLayerDO(EditorTileLayer tileLayer, List<string> textureNameList) { m_tileLayer = tileLayer; m_layerTextureNameList = textureNameList; }