コード例 #1
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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;
                }
            }
コード例 #2
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
        /// <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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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();
            }
コード例 #5
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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);
                }
            }
コード例 #6
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
        /// <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);
        }
コード例 #7
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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;
                }
            }
コード例 #8
0
        /// <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));
            }
        }
コード例 #9
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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;
                        }
                    }
                }
            }
コード例 #10
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
        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);
        }
コード例 #11
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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);
                }
            }
コード例 #12
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
        /// <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);
        }
コード例 #13
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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";
                    }
                }
            }
コード例 #14
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;
        }
コード例 #15
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
            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;
                }
            }
コード例 #16
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
            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;
                        }
                    }
                }
            }
コード例 #17
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
 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;
 }
コード例 #18
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
 /// <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);
 }
コード例 #19
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
 /// <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);
 }
コード例 #20
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
 /// <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;
 }
コード例 #21
0
ファイル: PawnModel.cs プロジェクト: historyme/PawnManager
 private void SetLoadedPawn(PawnData pawnData)
 {
     loadedPawnData     = pawnData;
     nameParameter      = null;
     loadedPawnTreeRoot = CreatePawnTreeCategory(templatePawnRoot);
 }
コード例 #22
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
 /// <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);
 }
コード例 #23
0
 private void SetLoadedPawn(PawnData pawnData)
 {
     PawnEditTreeTab.TreeList.Model = null;
     pawnModel.LoadedPawn           = pawnData;
     PawnEditTreeTab.TreeList.Model = PawnModel;
 }
コード例 #24
0
ファイル: PawnIO.cs プロジェクト: Meem0/PawnManager
        /// <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;
        }
コード例 #25
0
ファイル: PawnModel.cs プロジェクト: Meem0/PawnManager
 private void SetLoadedPawn(PawnData pawnData)
 {
     loadedPawnData = pawnData;
     nameParameter = null;
     loadedPawnTreeRoot = CreatePawnTreeCategory(templatePawnRoot);
 }
コード例 #26
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
 public abstract void LoadSavToPawn(PawnData pawn, XElement xElement, SavSlot savSlot);
コード例 #27
0
ファイル: MainWindow.xaml.cs プロジェクト: Meem0/PawnManager
 private void SetLoadedPawn(PawnData pawnData)
 {
     PawnEditTreeTab.TreeList.Model = null;
     pawnModel.LoadedPawn = pawnData;
     PawnEditTreeTab.TreeList.Model = PawnModel;
 }
コード例 #28
0
ファイル: PawnIO.cs プロジェクト: historyme/PawnManager
 public abstract void LoadPawnToSav(PawnData pawn, XElement xElement, SavSlot savSlot);