public override void LoadPawnToSav(PawnData pawn, XElement xElement, SavSlot savSlot) { int i = 0; foreach (XElement childElement in xElement.Elements()) { if (i >= Keys.Count) { throw new XmlException(string.Format( "An array in the save config is missing a key " + "for the following element: {0}\n" + "Array's first key is: {1}", childElement.ToString(), Keys.Count > 0 ? Keys[0] : "")); } if (Keys[i].Length > 0) { PawnParameter pawnParameter = pawn.GetParameter(Keys[i]); if (pawnParameter != null) { LoadParameterToSav(pawnParameter, childElement); } } ++i; } }
/// <summary> /// Load a Pawn from the .sav file /// </summary> /// <param name="savSlot">The Pawn to load</param> /// <param name="savRoot">The .sav file</param> /// <returns>The loaded Pawn, or null if no Pawn was loaded</returns> public static PawnData LoadPawnSav(SavSlot savSlot, XElement savRoot) { PawnData loadPawn = new PawnData(); savConfigRootClass.LoadSavToPawn(loadPawn, savRoot, savSlot); return(loadPawn); }
private void butLoad_Click(object sender, RoutedEventArgs e) { PawnData result = null; OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = PawnFilter; openDialog.Title = "Open Pawn file"; bool?dialogResult = openDialog.ShowDialog(); if (dialogResult == true) { try { result = PawnIO.LoadPawn(openDialog.FileName); } catch (Exception ex) { MessageBox.Show( ex.Message, "Error loading Pawn", MessageBoxButton.OK, MessageBoxImage.Error); } } if (result != null) { SetLoadedPawn(result); } }
public override void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot) { if (isName) { LoadSavNameToPawn(pawn, xElement); return; } PawnParameter pawnParameter = pawn.GetOrAddParameter(Key); pawnParameter.Value = xElement.GetParsedValueAttribute(); }
public override void LoadPawnToSav(PawnData pawn, XElement xElement, SavSlot savSlot) { if (isName) { LoadPawnNameToSav(pawn, xElement); return; } PawnParameter pawnParameter = pawn.GetParameter(Key); if (pawnParameter != null) { LoadParameterToSav(pawnParameter, xElement); } }
/// <summary> /// Save a Pawn to a Pawn file /// </summary> /// <param name="pawn">The Pawn to save</param> public static void SavePawn(PawnData pawn, string filename) { XElement pawnFile = new XElement(ElementNamePawnFileRoot); pawnFile.SetAttributeValue(ElementNamePawnFileVersion, 2); foreach (KeyValuePair <string, PawnParameter> kvp in pawn.ParameterDict) { pawnFile.Add( new XElement(ElementNamePawnFileParameter, new XElement(ElementNamePawnFileKey, kvp.Key), new XElement(ElementNamePawnFileValue, kvp.Value.Value) ) ); } pawnFile.Save(filename); }
public override void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot) { int i = 0; foreach (XElement childElement in xElement.Elements()) { if (i >= Classes.Count) { throw new XmlException(string.Format( "Class array {0} in save config is missing a child class", Name)); } Classes[i].LoadSavToPawn(pawn, childElement, savSlot); ++i; } }
/// <summary> /// Loads the .sav file specified by SavPath, using DDsavelib if it is packed, /// replaces the Pawn in the slot specified by SavSourcePawn with the given Pawn, /// then writes the modified .sav back, repacking it using DDsavelib if it was originally packed. /// Throws an exception if anything fails. /// </summary> /// <param name="exportPawn">The Pawn to export to the .sav file</param> public void Export(PawnData exportPawn) { bool? isPacked; XElement savRoot = LoadSav(out isPacked); PawnIO.SavePawnSav(exportPawn, SavSourcePawn, savRoot); string encoded = EncodeXml(savRoot); if (isPacked == true) { SavTool.RepackSav(SavPath, encoded); } else if (isPacked == false) { File.WriteAllText(SavPath, encoded, new UTF8Encoding(false)); } }
public override void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot) { // only proceed with the write if there is no condition // or if the condition allows reading for the current Pawn if (ParseCondition == null || (ParseCondition.AllowedPawns.Contains(savSlot) && !ParseCondition.IsWriteOnly)) { int i = 0; foreach (XElement childXElement in xElement.Elements()) { if (i == Children.Count) { return; } if (childXElement.GetNameAttribute() == Children[i].Name) { Children[i].LoadSavToPawn(pawn, childXElement, savSlot); ++i; } } } }
private static PawnData LoadPawnVersion1(XElement pawnFile) { SavConfigClass appearanceConfig = null; foreach (SavConfigElement childElement in savConfigRootClass.Children) { SavConfigClass childClass = childElement as SavConfigClass; if (childClass != null && childClass.Name == "mEdit") { appearanceConfig = childClass; break; } } if (appearanceConfig == null) { return(null); } PawnData loadPawn = new PawnData(); appearanceConfig.LoadSavToPawn(loadPawn, pawnFile, SavSlot.MainPawn); return(loadPawn); }
private void LoadSavNameToPawn(PawnData pawn, XElement xElement) { StringBuilder sb = new StringBuilder(); try { foreach (XElement letterElement in xElement.Elements()) { long value = letterElement.GetParsedValueAttribute(); if (value == 0) { break; } sb.Append((char)value); } pawn.GetOrAddParameter(Key).Value = sb.ToString(); } catch (Exception ex) { throw new XmlException(".sav file contained an invalid Pawn name.", ex); } }
/// <summary> /// Load a Pawn from a Pawn file /// </summary> /// <param name="pawnFilePath">The path to the Pawn file</param> /// <returns>The loaded Pawn</returns> public static PawnData LoadPawn(string filename) { PawnData loadPawn = null; try { XElement pawnFile = XElement.Load(filename); XAttribute versionAttribute = pawnFile.Attribute(ElementNamePawnFileVersion); if (versionAttribute != null && versionAttribute.Value == "1") { loadPawn = LoadPawnVersion1(pawnFile); } else { loadPawn = new PawnData(); foreach (XElement child in pawnFile.Elements()) { loadPawn.ParameterDict.Add( child.Element(ElementNamePawnFileKey).Value, new PawnParameter { Value = child.Element(ElementNamePawnFileValue).Value } ); } } } catch (Exception ex) { throw new XmlException(string.Format( "{0} is not a valid Pawn file.", filename), ex); } return(loadPawn); }
private void LoadPawnNameToSav(PawnData pawn, XElement xElement) { string name = pawn.GetParameter(Key).Value as string; int letterIndex = 0; foreach (XElement letterElement in xElement.Elements()) { XAttribute letterAttribute = letterElement.GetValueAttribute(); if (letterIndex < name.Length) { letterAttribute.Value = ((int)name[letterIndex]).ToString(); ++letterIndex; } else if (letterAttribute.Value == "0") { break; } else { letterAttribute.Value = "0"; } } }
private void butSavImport_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; PawnData result = null; try { result = SavTab.Import(); } catch (Exception ex) { MessageBox.Show( ex.Message, "Error importing from .sav", MessageBoxButton.OK, MessageBoxImage.Error); } if (result != null) { SetLoadedPawn(result); } Cursor = Cursors.Arrow; }
public override void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot) { int i = 0; foreach (XElement childElement in xElement.Elements()) { if (i >= Keys.Count) { throw new XmlException(string.Format( "Array {0} in save config is missing a child class", Name)); } if (Keys[i].Length > 0) { PawnParameter pawnParameter = pawn.GetOrAddParameter(Keys[i]); if (pawnParameter != null) { pawnParameter.Value = childElement.GetParsedValueAttribute(); } } ++i; } }
private static PawnData LoadPawnVersion1(XElement pawnFile) { SavConfigClass appearanceConfig = null; foreach (SavConfigElement childElement in savConfigRootClass.Children) { SavConfigClass childClass = childElement as SavConfigClass; if (childClass != null && childClass.Name == "mEdit") { appearanceConfig = childClass; break; } } if (appearanceConfig == null) { return null; } PawnData loadPawn = new PawnData(); appearanceConfig.LoadSavToPawn(loadPawn, pawnFile, SavSlot.MainPawn); return loadPawn; }
/// <summary> /// Save a Pawn to the .sav file /// </summary> /// <param name="pawn">The Pawn to save</param> /// <param name="savSlot">The Pawn to save to</param> /// <param name="savRoot">The loaded .sav file</param> public static void SavePawnSav(PawnData pawn, SavSlot savSlot, XElement savRoot) { savConfigRootClass.LoadPawnToSav(pawn, savRoot, savSlot); }
/// <summary> /// Save a Pawn to a Pawn file /// </summary> /// <param name="pawn">The Pawn to save</param> public static void SavePawn(PawnData pawn, string filename) { XElement pawnFile = new XElement(ElementNamePawnFileRoot); pawnFile.SetAttributeValue(ElementNamePawnFileVersion, 2); foreach (KeyValuePair<string, PawnParameter> kvp in pawn.ParameterDict) { pawnFile.Add( new XElement(ElementNamePawnFileParameter, new XElement(ElementNamePawnFileKey, kvp.Key), new XElement(ElementNamePawnFileValue, kvp.Value.Value) ) ); } pawnFile.Save(filename); }
/// <summary> /// Load a Pawn from the .sav file /// </summary> /// <param name="savSlot">The Pawn to load</param> /// <param name="savRoot">The .sav file</param> /// <returns>The loaded Pawn, or null if no Pawn was loaded</returns> public static PawnData LoadPawnSav(SavSlot savSlot, XElement savRoot) { PawnData loadPawn = new PawnData(); savConfigRootClass.LoadSavToPawn(loadPawn, savRoot, savSlot); return loadPawn; }
private void SetLoadedPawn(PawnData pawnData) { loadedPawnData = pawnData; nameParameter = null; loadedPawnTreeRoot = CreatePawnTreeCategory(templatePawnRoot); }
private void SetLoadedPawn(PawnData pawnData) { PawnEditTreeTab.TreeList.Model = null; pawnModel.LoadedPawn = pawnData; PawnEditTreeTab.TreeList.Model = PawnModel; }
/// <summary> /// Load a Pawn from a Pawn file /// </summary> /// <param name="pawnFilePath">The path to the Pawn file</param> /// <returns>The loaded Pawn</returns> public static PawnData LoadPawn(string filename) { PawnData loadPawn = null; try { XElement pawnFile = XElement.Load(filename); XAttribute versionAttribute = pawnFile.Attribute(ElementNamePawnFileVersion); if (versionAttribute != null && versionAttribute.Value == "1") { loadPawn = LoadPawnVersion1(pawnFile); } else { loadPawn = new PawnData(); foreach (XElement child in pawnFile.Elements()) { loadPawn.ParameterDict.Add( child.Element(ElementNamePawnFileKey).Value, new PawnParameter { Value = child.Element(ElementNamePawnFileValue).Value } ); } } } catch (Exception ex) { throw new XmlException(string.Format( "{0} is not a valid Pawn file.", filename), ex); } return loadPawn; }
public abstract void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot);
public abstract void LoadPawnToSav(PawnData pawn, XElement xElement, SavSlot savSlot);