Exemplo n.º 1
0
        public void SaveGameInfo(string filename)
        {
            // added @Expose tag to fields that I want to be saved in Module class
            ModuleInfo newModInfo = new ModuleInfo();
            newModInfo.saveName = gv.mod.saveName;

            string filepath = gv.mainDirectory + "\\saves\\" + gv.mod.moduleName + "\\" + filename;
            MakeDirectoryIfDoesntExist(filepath);
            string json = JsonConvert.SerializeObject(newModInfo, Newtonsoft.Json.Formatting.Indented);
            using (StreamWriter sw = new StreamWriter(filepath))
            {
                sw.Write(json.ToString());
            }

            /*
            final GsonBuilder builder = new GsonBuilder();
            //builder.setPrettyPrinting();
            builder.excludeFieldsWithoutExposeAnnotation();
            final Gson gson = builder.create();
            String save = gson.toJson(newModInfo, ModuleInfo.class);
            writeToFile(save, filename);
            Toast.makeText(gv.gameContext, "Saved Game Info: " + newModInfo.saveName, Toast.LENGTH_SHORT).show();
            */
        }
Exemplo n.º 2
0
        public ModuleInfo LoadModuleInfo(string filename)
        {
            ModuleInfo m = new ModuleInfo();
            try
            {
                using (StreamReader file = File.OpenText(gv.mainDirectory + "\\saves\\" + gv.mod.moduleName + "\\" + filename))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    m = (ModuleInfo)serializer.Deserialize(file, typeof(ModuleInfo));
                }
            }
            catch { }

            /*
            string qs = readFromFile(filename);
            GsonBuilder gsonb = new GsonBuilder();
            Gson gson = gsonb.create();
            try
            {
                if (qs.length() > 0)
                {
                    m = gson.fromJson(qs, new TypeToken<ModuleInfo>() {}.getType());
                }
            }
            catch (JsonSyntaxException e)
            {
                e.printStackTrace();
            }
            catch (JsonIOException e)
            {
                e.printStackTrace();
            }
            */
            return m;
        }