Esempio n. 1
0
        public static void Save(FileInfo saveFile)
        {
            using (TextWriter tw = File.CreateText(saveFile.FullName))
            {
                JsonSerializer jss = new JsonSerializer
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Formatting.Indented,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full
                };

                CompressedSaveFile csf = new CompressedSaveFile(saveVersion, CompressReactor(), interiorDims, usedFuel);
                jss.Serialize(tw, csf);
                //jss.Serialize(tw, usedFuel);
            }
        }
Esempio n. 2
0
        public static string SaveToString()
        {
            using (StringWriter sw = new StringWriter())
            {
                JsonSerializer jss = new JsonSerializer
                {
                    NullValueHandling = NullValueHandling.Ignore,
                    Formatting        = Formatting.Indented,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full
                };

                CompressedSaveFile csf = new CompressedSaveFile(saveVersion, CompressReactor(), interiorDims, usedFuel);
                jss.Serialize(sw, csf);
                return(sw.ToString());
            }
        }
Esempio n. 3
0
        private static void LoadCompressedReactor(string fileName)
        {
            Block restoreBlock(string type, Vector3 position)
            {
                if (type == "FuelCell")
                {
                    return(new FuelCell("FuelCell", Palette.Textures["FuelCell"], position));
                }
                else if (type == "Beryllium" | type == "Graphite")
                {
                    return(new Moderator((Moderator)Palette.BlockPalette[type], position));
                }
                else if (type.Contains("Active"))
                {
                    return(new Cooler((Cooler)Palette.BlockPalette[type.Split(' ')[1]], position, true));
                }
                else
                {
                    return(new Cooler((Cooler)Palette.BlockPalette[type], position, false));
                }
                throw new ArgumentException("Tried to restore an invalid block");
            }

            CompressedSaveFile csf;

            using (StreamReader sr = File.OpenText(fileName))
            {
                string  jsonText       = sr.ReadToEnd();
                JObject saveJSONObject = JObject.Parse(jsonText);
                Version v;
                v = saveJSONObject["SaveVersion"].ToObject <Version>();
                JsonSerializer js = new JsonSerializer();

                if (v.Major == 2)
                {
                    System.Windows.Forms.MessageBox.Show("Can't load post-overhaul savefiles!");
                    return;
                }
                else if (v >= new Version(1, 2, 23))
                {
                    csf = (CompressedSaveFile)js.Deserialize(new StringReader(jsonText), typeof(CompressedSaveFile));
                }
                else
                {
                    Dictionary <string, List <Vector3> > cr = new Dictionary <string, List <Vector3> >();
                    JToken crToken = saveJSONObject["CompressedReactor"];
                    foreach (var child in crToken.Children())
                    {
                        JProperty entry    = child.First().ToObject <JProperty>();
                        string    name     = entry.Name;
                        var       children = entry.First().Children().ToList();
                        cr.Add(name, new List <Vector3>());
                        foreach (var coord in children)
                        {
                            string[] posV = coord.ToObject <string>().Split(',');
                            cr[name].Add(new Vector3(Convert.ToInt32(posV[0]), Convert.ToInt32(posV[1]), Convert.ToInt32(posV[2])));
                        }
                    }

                    string[] interiorDims = saveJSONObject["InteriorDimensions"].ToObject <string>().Split(',');
                    Vector3  inDimsVector = new Vector3(Convert.ToInt32(interiorDims[0]), Convert.ToInt32(interiorDims[1]), Convert.ToInt32(interiorDims[2]));

                    Fuel fuel = saveJSONObject["UsedFuel"].ToObject <Fuel>();
                    csf = new CompressedSaveFile(v, cr, inDimsVector, fuel);
                }
            }

            InitializeReactor(csf.InteriorDimensions);

            foreach (KeyValuePair <string, List <Vector3> > kvp in csf.CompressedReactor)
            {
                foreach (Vector3 pos in kvp.Value)
                {
                    SetBlock(restoreBlock(kvp.Key, pos), pos);
                }
            }

            usedFuel = csf.UsedFuel;
            FinalizeLoading();
        }