Ejemplo n.º 1
0
 public static void FinalizeWriting()
 {
     if (Scribe.writer != null)
     {
         Scribe.ExitNode();
         Scribe.writer.WriteEndDocument();
         Scribe.writer.Flush();
         Scribe.writer.Close();
         Scribe.writer = null;
     }
     if (Scribe.saveStream != null)
     {
         Scribe.saveStream.Flush();
         Scribe.saveStream.Close();
         Scribe.saveStream = null;
     }
     Scribe.mode = LoadSaveMode.Inactive;
     //DebugLoadIDsSavingErrorsChecker.CheckForErrorsAndClear();
 }
 public static void LookDeep <T>(ref T target, string label, params object[] ctorArgs)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         IExposable exposable = target as IExposable;
         if (target != null && exposable == null)
         {
             //Log.Error(string.Concat(new object[]
             //{
             //"Cannot use LookDeep to save non-IExposable non-null ",
             //label,
             //" of type ",
             //typeof(T)
             //}));
             return;
         }
         if (target == null)
         {
             Scribe.EnterNode(label);
             Scribe.WriteAttribute("IsNull", "True");
             Scribe.ExitNode();
         }
         else
         {
             Scribe.EnterNode(label);
             if (target.GetType() != typeof(T))
             {
                 Scribe.WriteAttribute("Class", target.GetType().ToString());
             }
             exposable.ExposeData();
             Scribe.ExitNode();
         }
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         target = ScribeExtractor.SaveableFromNode <T>(Scribe.curParent[label], ctorArgs);
     }
 }
 public static void LookValue <T>(ref T value, string label, T defaultValue = default(T), bool forceSave = false)
 {
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         //if (typeof(T) == typeof(TargetInfo))
         //{
         //    Log.Error("Saving a TargetInfo " + label + " with Scribe_Values. TargetInfos must be saved with Scribe_TargetInfo.");
         //    return;
         //}
         //if (typeof(Thing).IsAssignableFrom(typeof(T)))
         //{
         //    Log.Error("Using Scribe_Values with a Thing reference " + label + ". Use Scribe_References or Scribe_Deep instead.");
         //    return;
         //}
         //if (typeof(IExposable).IsAssignableFrom(typeof(T)))
         //{
         //    Log.Error("Using Scribe_Values with a IExposable reference " + label + ". Use Scribe_References or Scribe_Deep instead.");
         //    return;
         //}
         if (forceSave || (value == null && defaultValue != null) || (value != null && !value.Equals(defaultValue)))
         {
             if (value != null)
             {
                 Scribe.WriteElement(label, value.ToString());
             }
             else
             {
                 Scribe.WriteElement(label, "");
             }
         }
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         value = ScribeExtractor.ValueFromNode <T>(Scribe.curParent[label], defaultValue);
     }
 }
Ejemplo n.º 4
0
 public static void FinalizeLoading()
 {
     Scribe.ExitNode();
 }
        private void buttonConvertFile_Click(object sender, EventArgs e)
        {
            if (!File.Exists(workFilePath) || txtFileSelected.Text == null || txtFileSelected.Text == "")
            {
                return;
            }
            string outFile = "";

            if (rbMapGen.Checked)
            {
                outFile = "MapGeneratorBlueprintsX_" + Path.GetFileNameWithoutExtension(txtFileSelected.Text) + ".xml";
            }

            if (rbMapGenFB.Checked)
            {
                outFile = "MapGeneratorBaseBlueprintsX_" + Path.GetFileNameWithoutExtension(txtFileSelected.Text) + ".xml";
            }

            string outFilePath = System.IO.Path.Combine(path, outFile);

            // Load Fluffy Blueprint
            Fluffy_Blueprint blueprintIN = new Fluffy_Blueprint();

            Scribe.InitLoading(workFilePath);
            Scribe.EnterNode("Blueprint");
            blueprintIN.ExposeData();
            Scribe.ExitNode();
            Scribe.FinalizeLoading();

            string nodeName = "";

            if (rbMapGen.Checked)
            {
                nodeName = "MapGenerator.MapGeneratorBlueprintDef";
            }

            if (rbMapGenFB.Checked)
            {
                nodeName = "MapGenerator.MapGeneratorBaseBlueprintDef";
            }


            // Write data to MapGen Blueprint
            Misc_Blueprint blueprintOUT = new Misc_Blueprint();

            blueprintOUT.createMapGenFactionBaseBlueprint = rbMapGenFB.Checked;

            Converter.FillMiscBlueprintFromFluffyBlueprint(blueprintIN, ref blueprintOUT);

            Scribe.InitWriting(outFilePath, "Defs");
            Scribe.EnterNode(nodeName);

            if (rbMapGenFB.Checked)
            {
                Scribe.WriteAttribute("Name", "TODO_enter_a_name_here");
            }

            blueprintOUT.ExposeData();
            Scribe.FinalizeWriting();


            txtFileCreated.Text = outFile;
        }
Ejemplo n.º 6
0
 public static void LookList <T>(ref List <T> list, bool saveDestroyedThings, string label, LookMode lookMode = LookMode.Undefined, params object[] ctorArgs)
 {
     if (lookMode == LookMode.Undefined)
     {
         if (Helper_Parsing.HandlesType(typeof(T)))
         {
             lookMode = LookMode.Value;
         }
         else
         {
             lookMode = LookMode.Deep;
         }
     }
     if (Scribe.mode == LoadSaveMode.Saving)
     {
         if (list == null && lookMode == LookMode.Reference)
         {
             //Log.Warning(string.Concat(new object[]
             //{
             //    "Saving null list \"",
             //    label,
             //    "\" with look mode ",
             //    lookMode,
             //    ". This will cause bugs because null lists are not registered during loading so CrossRefResolver will break."
             //}));
         }
         Scribe.EnterNode(label);
         if (list == null)
         {
             Scribe.WriteAttribute("IsNull", "True");
         }
         else
         {
             foreach (T current in list)
             {
                 if (lookMode == LookMode.Value)
                 {
                     T t = current;
                     Scribe_Values.LookValue <T>(ref t, "li", default(T), true);
                 }
                 else if (lookMode == LookMode.Deep)
                 {
                     T t2 = current;
                     Scribe_Deep.LookDeep <T>(ref t2, "li", ctorArgs);
                 }
             }
         }
         Scribe.ExitNode();
     }
     else if (Scribe.mode == LoadSaveMode.LoadingVars)
     {
         if (Scribe.curParent == null)
         {
             //Log.Error("XmlHandling.curParent is null. I'm not sure why.");
             list = null;
             return;
         }
         XmlNode xmlNode = Scribe.curParent[label];
         if (xmlNode == null)
         {
             list = null;
             return;
         }
         XmlAttribute xmlAttribute = xmlNode.Attributes["IsNull"];
         if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "true")
         {
             list = null;
             return;
         }
         if (lookMode == LookMode.Value)
         {
             list = new List <T>(xmlNode.ChildNodes.Count);
             foreach (XmlNode subNode in xmlNode.ChildNodes)
             {
                 T item = ScribeExtractor.ValueFromNode <T>(subNode, default(T));
                 list.Add(item);
             }
         }
         else if (lookMode == LookMode.Deep)
         {
             list = new List <T>(xmlNode.ChildNodes.Count);
             foreach (XmlNode subNode2 in xmlNode.ChildNodes)
             {
                 T item2 = ScribeExtractor.SaveableFromNode <T>(subNode2, ctorArgs);
                 list.Add(item2);
             }
         }
     }
 }