public bool ImportTile(int nTileIndex, int[] b) { if (nTileIndex >= NumTiles) { // "Too many tiles specified for sprite '{0}'." m_doc.ErrorId("ErrorSpriteTooManyTiles", m_strName); // Return true because the error isn't fatal. return(true); } m_Tiles[nTileIndex].Import(b); return(true); }
//TODO: save into temp file and overwrite original if successful // so that if there is an exception, the old file is still intact. private bool SaveFile_(string strPath) { TextWriter tw; try { tw = new StreamWriter(strPath); } catch (Exception ex) { // "An exception was thrown while opening the file for writing: {0}" m_doc.ErrorId("ExceptionOpenWrite", ex.Message); return(false); } tw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); tw.WriteLine("<spritely"); tw.WriteLine("\txmlns=\"http://schemas.kacmarcik.com/spritely/2009\""); tw.WriteLine("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); tw.WriteLine("\txsi:schemaLocation=\"http://schemas.kacmarcik.com/spritely/2009 spritely.xsd\""); tw.WriteLine("\t"); tw.WriteLine("\tversion=\"2\" name=\"project\""); tw.WriteLine("\t>"); tw.WriteLine(""); Options.Save(tw); m_doc.Palettes.Save(tw); m_doc.Spritesets.Save(tw); m_doc.BackgroundPalettes.Save(tw); m_doc.BackgroundSpritesets.Save(tw); m_doc.BackgroundMaps.Save(tw); m_doc.BackgroundImages.Save(tw); tw.WriteLine("</spritely>"); tw.Close(); m_fHasUnsavedChanges = false; return(true); }
// Returns false if the original name was invalid. private bool ValidateName() { if (!Regex.IsMatch(tbName.Text, "^[A-Za-z_][A-Za-z0-9_]*$")) { string strOriginal = tbName.Text; string strNew = tbName.Text; // Fixup the name so that if the user tries to validate again, it will work. // First, auto-generate a name if the field is blank if (strNew == "") { strNew = m_doc.BackgroundImages.GenerateUniqueBgImageName(); } ; // Replace invalid characters with an underscore strNew = Regex.Replace(strNew, "[^A-Za-z0-9_]", "_"); // Make sure string begins with a letter if (!Regex.IsMatch(strNew, "^[A-Za-z_]")) { strNew = "S" + strNew; } // "Invalid sprite name. // Valid names must begin with a letter and contain only 'A'-'Z', 'a'-'z', '0'-'9' and '_' characters. // Fixing up sprite name - changing from '{0}' to '{1}'." m_doc.ErrorId("ErrorInvalidSpriteName", strOriginal, strNew); // Update the sprite name. tbName.Text = strNew; // The name is now valid, but we need to cancel the current operation so that the // user has a chance to read the error message displayed above before continuing. return(false); } return(true); }