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 bool FillMiscBlueprintFromFluffyBlueprint(Fluffy_Blueprint source, ref Misc_Blueprint target)
        {
            if (source == null)
            {
                return(false);
            }
            if (target == null)
            {
                target = new Misc_Blueprint();
            }


            target.size = source.size;
            //target.defName = source.name;


            // Fill legend data
            List <Misc_Blueprint.LegendData> buildingLegend = null;
            List <Misc_Blueprint.LegendData> rotationLegend = null;
            List <Misc_Blueprint.LegendData> floorLegend    = null;
            Dictionary <string, string>      mappingBuildingRotation2LegendKey = null;
            Dictionary <string, string>      mappingFloor2LegendKey            = null;

            FillLegendData(source, ref buildingLegend, ref rotationLegend, ref floorLegend,
                           ref mappingBuildingRotation2LegendKey, ref mappingFloor2LegendKey);

            // fill data list
            List <string> buildingDataList = GetMapBase(source.size);
            List <string> floorDataList    = GetMapBase(source.size);

            FillDataList(source, ref buildingDataList, ref floorDataList,
                         ref mappingBuildingRotation2LegendKey, ref mappingFloor2LegendKey);

            // Data must be inverted
            buildingDataList = InvertList(buildingDataList);
            floorDataList    = InvertList(floorDataList);

            StringBuilder buildingData = new StringBuilder();

            for (int i = 0; i < buildingDataList.Count; i++)
            {
                buildingData.AppendLine();
                buildingData.Append(buildingDataList[i]);
            }
            buildingData.AppendLine();
            target.buildingData   = buildingData.ToString();
            target.buildingLegend = buildingLegend;
            target.rotationLegend = rotationLegend;

            StringBuilder floorData = new StringBuilder();

            for (int i = 0; i < floorDataList.Count; i++)
            {
                floorData.AppendLine();

                floorData.Append(floorDataList[i]);
            }
            floorData.AppendLine();
            target.floorData   = floorData.ToString();
            target.floorLegend = floorLegend;



            // Add example for itemData
            target.itemData = buildingData.ToString();
            Misc_Blueprint.LegendData itemLegendData = new Misc_Blueprint.LegendData();
            itemLegendData.key = "s"; itemLegendData.value = "Silver";
            target.itemLegend.Add(itemLegendData);
            target.itemSpawnChance = 60;

            // Add example for pawnData
            target.pawnData = buildingData.ToString();
            Misc_Blueprint.LegendData pawnLegendData = new Misc_Blueprint.LegendData();
            pawnLegendData.key = "x"; pawnLegendData.value = "Mercenary_Elite";
            target.pawnLegend.Add(pawnLegendData);
            target.pawnSpawnChance = 50;



            // MAIN Presets
            target.defName           = "TODO__Blueprint_needs_a_unique_defName";
            target.createdBy         = "TODO__Please_enter_your_username_here";
            target.techLevelRequired = "Neolithic";
            target.chance            = 10;
            //target.size = IntVec2.Invalid;

            if (target.createMapGenFactionBaseBlueprint)
            {
                target.canHaveHoles = false;
            }
            else
            {
                target.canHaveHoles = true;
            }

            target.createTrigger = false;



            buildingData = null;
            floorData    = null;

            return(true);
        }