private void buttonConvertFile_Click(object sender, EventArgs e)
        {
            if (!File.Exists(workFilePath) || txtFileSelected.Text == null || txtFileSelected.Text == "")
            {
                return;
            }

            string outFile     = "MapGenerator_" + 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();

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

            Converter.FillMiscBlueprintFromFluffyBlueprint(blueprintIN, ref blueprintOUT);

            Scribe.InitWriting(outFilePath, "Defs");
            Scribe.EnterNode("MapGenerator.MapGeneratorBaseBlueprintDef");
            Scribe.WriteAttribute("Name", "TODO_enter_a_name_here");
            blueprintOUT.ExposeData();
            Scribe.FinalizeWriting();


            txtFileCreated.Text = outFile;
        }
示例#2
0
        public static void InitWriting(string filePath, string documentElementName)
        {
            //DebugLoadIDsSavingErrorsChecker.Clear();
            Scribe.mode       = LoadSaveMode.Saving;
            Scribe.saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent      = true;
            xmlWriterSettings.IndentChars = "\t";
            Scribe.writer = XmlWriter.Create(Scribe.saveStream, xmlWriterSettings);
            Scribe.writer.WriteStartDocument();
            Scribe.EnterNode(documentElementName);
        }
示例#3
0
        public static void WriteMetaHeader()
        {
            Scribe.EnterNode("meta");
            string currentVersionStringWithRev = "0.18.1722"; //VersionControl.CurrentVersionStringWithRev;

            Scribe_Values.LookValue <string>(ref currentVersionStringWithRev, "gameVersion", null, false);
            //List<string> list = (from mod in LoadedModManager.RunningMods
            //                     select mod.Identifier).ToList<string>();
            //Scribe_Collections.LookList<string>(ref list, "modIds", LookMode.Undefined, new object[0]);
            //List<string> list2 = (from mod in LoadedModManager.RunningMods
            //                      select mod.Name).ToList<string>();
            //Scribe_Collections.LookList<string>(ref list2, "modNames", LookMode.Undefined, new object[0]);
            Scribe.ExitNode();
        }
 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);
     }
 }
示例#5
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);
             }
         }
     }
 }