Exemplo n.º 1
0
    static public void OnLoad()
    {
        Debug.LogFormat("CookingTweaks: init");

        string        settings = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CookingTweaks.json"));
        SaveDataProxy data     = FastJson.Deserialize <SaveDataProxy>(settings);

        WaterSettings waterSettings = new WaterSettings();
        FoodSettings  foodSettings  = new FoodSettings(data.food.ElementAt(0).Key);

        // m_water = data.water;
        // m_food = data.food;
        //
        // waterSettings.enabled = m_water.enabled;
        // waterSettings.melting = m_water.melting;
        // waterSettings.boiling = m_water.boiling;
        // waterSettings.drying = m_water.drying;
        //
        // string firstFood = ((FoodTypes)0).ToString();
        // foodSettings.foodType = 0;
        // if (!m_food.ContainsKey(firstFood))
        // {
        //     m_food[((FoodTypes)0).ToString()] = GetEmptyStructure();
        // }
        //
        // foodSettings.enabled = m_food[firstFood].enabled;
        // foodSettings.cooking = m_food[firstFood].cooking;
        // foodSettings.burning = m_food[firstFood].burning;
        //
        // waterSettings.AddToModSettings("Cooking Tweaks");
        // foodSettings.AddToModSettings("Cooking Tweaks");
    }
Exemplo n.º 2
0
        private void Test_Example6()
        {
            string testJson = "{\"h_json\":{\"subKey1\":\"subValue1\",\"subKey2\":{\"subKey21\":\"subValue21\"},\"subKey3\":[\"subValue31\",\"subValue32\"]}}";
            ClassH h        = FastJson.Deserialize <ClassH>(testJson);

            Debug.Log(h.json);
        }
Exemplo n.º 3
0
    public string Deserialize(Stopwatch timer)
    {
        timer.Start();
        Holder list = FastJson.Deserialize <Holder>(jsonText);

        return("Parsed list is " + list.junkList.Length + " entries long");
    }
Exemplo n.º 4
0
        void Start()
        {
            ExampleClass foo = new ExampleClass();

            foo.id   = 1234;
            foo.name = "SampleClass";

            string jsonText = FastJson.Serialize(foo);

            Debug.Log(jsonText);

            ExampleClass fooDecode = FastJson.Deserialize <ExampleClass>(jsonText);

            Debug.Log("id=" + fooDecode.id + " name=" + fooDecode.name);


            int[][][] bar = new int[][][] {
                new int[][]
                {
                    new int[] { 1 },
                    new int[] { 2, 3 }
                },
                new int[][] {
                    new int[] { 4, 5, 6 }
                },
                null
            };

            jsonText = FastJson.Serialize(bar);
            Debug.Log(jsonText);

            int[][][] barDecode = (int[][][])FastJson.Deserialize(jsonText, typeof(int[][][]));
            Debug.Log(ToString(barDecode));
        }
Exemplo n.º 5
0
        private void Test_Example2()
        {
            ClassA tempA = new ClassA();

            // 循环嵌套会直接造成崩溃
            //tempA.SetNext(tempA);

            ClassA tempAnotherA = new ClassA();

            tempA.SetA(tempAnotherA);

            ClassB tempB = new ClassB();

            tempA.SetB(tempB);

            ClassC tempC = new ClassC();

            tempA.SetC(tempC);

            tempA.SetGameObject(this.gameObject);

            // 测试 反序列化
            string jsonStr      = FastJson.Serialize(tempA);
            ClassA deserializeA = FastJson.Deserialize <ClassA>(jsonStr);

            Debug.Log(FastJson.Serialize(deserializeA));
        }
Exemplo n.º 6
0
        private static T LoadDataFromJson <T>(T defaultT) where T : IDataBase
        {
            var dataTypeKey = defaultT.GetType().Name;

            return(PlayerPrefs.HasKey(dataTypeKey) == false
                ? defaultT
                : FastJson.Deserialize <T>(PlayerPrefs.GetString(dataTypeKey, "NULL")));
        }
Exemplo n.º 7
0
    static public void OnLoad()
    {
        Debug.LogFormat("DetectionRange: init");

        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "DetectionRange.json"));
        Dictionary <string, AnimalRanges> settings = FastJson.Deserialize <Dictionary <string, AnimalRanges> >(opts);

        WolfRangesSettings wolves = new WolfRangesSettings();

        if (!settings.ContainsKey("wolf"))
        {
            settings["wolf"] = GetEmptyStructure();
        }
        wolves.SetSettings(settings["wolf"]);
        wolves.AddToModSettings("Detection Range");
        m_animals.Add("wolf", wolves.GetSettings());

        DeerRangesSettings deers = new DeerRangesSettings();

        if (!settings.ContainsKey("deer"))
        {
            settings["deer"] = GetEmptyStructure();
        }
        deers.SetSettings(settings["deer"]);
        deers.AddToModSettings("Detection Range");
        m_animals.Add("deer", deers.GetSettings());

        MooseRangesSettings mooses = new MooseRangesSettings();

        if (!settings.ContainsKey("moose"))
        {
            settings["moose"] = GetEmptyStructure();
        }
        mooses.SetSettings(settings["moose"]);
        mooses.AddToModSettings("Detection Range");
        m_animals.Add("moose", mooses.GetSettings());

        RabbitRangesSettings rabbits = new RabbitRangesSettings();

        if (!settings.ContainsKey("rabbit"))
        {
            settings["rabbit"] = GetEmptyStructure();
        }
        rabbits.SetSettings(settings["rabbit"]);
        rabbits.AddToModSettings("Detection Range");
        m_animals.Add("rabbit", rabbits.GetSettings());

        BearRangesSettings bears = new BearRangesSettings();

        if (!settings.ContainsKey("bear"))
        {
            settings["bear"] = GetEmptyStructure();
        }
        bears.SetSettings(settings["bear"]);
        bears.AddToModSettings("Detection Range");
        m_animals.Add("bear", bears.GetSettings());
    }
Exemplo n.º 8
0
            public static void OnLoad()
            {
                if (File.Exists(Path.Combine(mod_options_folder, options_file_name)))
                {
                    string opts = File.ReadAllText(Path.Combine(mod_options_folder, options_file_name));
                    custom_settings = FastJson.Deserialize <TempDropSettings>(opts);

                    TempDropOptions.temp_drop_celsius_max = custom_settings.temp_drop_celsius_max;
                }

                custom_settings.AddToModSettings("Temperature Drop");
            }
Exemplo n.º 9
0
    static public void OnLoad()
    {
        Debug.LogFormat("TweakRabbits: init");

        TweakRabbitsSettings settings = new TweakRabbitsSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TweakRabbits.json"));

        settings = FastJson.Deserialize <TweakRabbitsSettings>(opts);
        settings.AddToModSettings("Tweak Rabbits");

        killOnHit    = settings.killOnHit;
        stunDuration = settings.stunDuration;
    }
    static public void OnLoad()
    {
        Debug.LogFormat("FasterActionRedux: init");

        FasterActionReduxSettings settings = new FasterActionReduxSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "FasterActionRedux.json"));

        settings = FastJson.Deserialize <FasterActionReduxSettings>(opts);
        settings.AddToModSettings("Faster Actions Redux");

        containerTime = settings.containerTime;
        actionTime    = settings.actionTime;
    }
Exemplo n.º 11
0
            public static void OnLoad()
            {
                if (File.Exists(Path.Combine(mod_options_folder, options_file_name)))
                {
                    string opts = File.ReadAllText(Path.Combine(mod_options_folder, options_file_name));
                    custom_settings = FastJson.Deserialize <GearDecaySettings>(opts);

                    GearDecayOptions.general_decay       = custom_settings.general_decay;
                    GearDecayOptions.decay_before_pickup = custom_settings.decay_before_pickup;
                }

                custom_settings.AddToModSettings("Xpazeman Mini Mods");
            }
Exemplo n.º 12
0
    void Start()
    {
        CipherInt i = new CipherInt();

        i.value = 123;

        string json = FastJson.Serialize(i);

        Debug.Log(json);

        CipherInt d = FastJson.Deserialize <CipherInt>(json);

        Debug.Log(d.value);
    }
Exemplo n.º 13
0
    static public void OnLoad()
    {
        Debug.LogFormat("TimeAccelerator: init");

        TimeAcceleratorSettings settings = new TimeAcceleratorSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TimeAccelerator.json"));

        settings = FastJson.Deserialize <TimeAcceleratorSettings>(opts);
        settings.AddToModSettings("Time Accelerator");

        accelerationKey   = KeyCode.A + settings.accelerationKey;
        holdToAccelerate  = settings.accelerationBehaviour == 0;
        accelerationValue = settings.accelerationValue;
    }
        private static void ProcessFile(string path)
        {
            string text = File.ReadAllText(path);

            try
            {
                ModBlueprint blueprint = FastJson.Deserialize <ModBlueprint>(text);
                Mapper.RegisterBlueprint(blueprint, path);
            }
            catch (Exception e)
            {
                throw new System.ArgumentException("Could not read blueprint from '" + path + "'.", e);
            }
        }
Exemplo n.º 15
0
    static public void OnLoad()
    {
        Debug.LogFormat("StruggleTweaks: init");

        StruggleTweaksSettings settings = new StruggleTweaksSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "StruggleTweaks.json"));

        settings = FastJson.Deserialize <StruggleTweaksSettings>(opts);
        settings.AddToModSettings("Struggle Tweaks");

        chanceToKillWolfAfterStruggle = settings.chanceToKillWolfAfterStruggle;
        wolfBleedoutMinutes           = settings.wolfBleedoutMinutes;
        tapIncrement = settings.tapIncrement;
    }
Exemplo n.º 16
0
    private void Test_8_FastJsonMyText()
    {
        string jsonString = "{\"StringField\":\"ha\\\"ha\\\"ha\"}";

        VeerDebug.Log("json string : " + jsonString);

        TestJsonConvert test = FastJson.Deserialize <TestJsonConvert>(jsonString);

        VeerDebug.Log("fast json string field : " + test.StringField);

        string serialize = FastJson.Serialize(test);

        VeerDebug.Log("fast json serialize : " + serialize);
    }
Exemplo n.º 17
0
    static public void OnLoad()
    {
        Debug.LogFormat("SkipIntroRedux: init");

        SkipIntroReduxSettings settings = new SkipIntroReduxSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SkipIntroRedux.json"));

        settings = FastJson.Deserialize <SkipIntroReduxSettings>(opts);
        settings.AddToModSettings("Skip Intro Redux", MenuType.MainMenuOnly);

        skipDisclaimer = settings.skipDisclaimer;
        skipIntro      = settings.skipIntro;
        skipFade       = settings.skipFade;
    }
Exemplo n.º 18
0
    static public void OnLoad()
    {
        Debug.LogFormat("WeaponCrosshair: init");

        WeaponCrosshairSettings settings = new WeaponCrosshairSettings();
        string opts = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WeaponCrosshair.json"));

        settings = FastJson.Deserialize <WeaponCrosshairSettings>(opts);
        settings.AddToModSettings("Weapon Crosshair");

        stoneCrosshair = settings.stoneCrosshair;
        rifleCrosshair = settings.rifleCrosshair;
        bowCrosshair   = settings.bowCrosshair;
    }
Exemplo n.º 19
0
    static public void OnLoad()
    {
        Debug.LogFormat("MapTweaks: init");

        MapTweakSettings settings = new MapTweakSettings();
        string           opts     = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MapTweaks.json"));

        settings = FastJson.Deserialize <MapTweakSettings>(opts);
        settings.AddToModSettings("Map Tweaks");

        overrideDrawingRange = settings.overrideDrawingRange;
        drawingRange         = settings.drawingRange;
        autodrawEnabled      = settings.autodrawEnabled;
        autodrawDelay        = settings.autodrawDelay;
    }
        public static void OnLoad()
        {
            if (File.Exists(@"mods/ambient-lights/config.json"))
            {
                string opts = File.ReadAllText(Path.Combine(AmbientLightControl.mod_data_folder, "config.json"));
                custom_settings = FastJson.Deserialize <AmbientLightsSettings>(opts);

                AmbientLightsOptions.intensity_multiplier   = custom_settings.intensity_multiplier;
                AmbientLightsOptions.range_multiplier       = custom_settings.range_multiplier;
                AmbientLightsOptions.aurora_intensity       = custom_settings.aurora_intensity;
                AmbientLightsOptions.disable_aurora_flicker = custom_settings.disable_aurora_flicker;
                AmbientLightsOptions.night_brightness       = custom_settings.night_brightness;
                AmbientLightsOptions.enable_debug_key       = custom_settings.enable_debug_key;
            }

            custom_settings.AddToModSettings("Ambient Lighting Settings");
        }
Exemplo n.º 21
0
    private void Test_9_FastJsonSerialize()
    {
        JSONObject json = JSONObject.obj;

        json.AddField("StringField", TestInnerJsonText);

        string jsonString = json.ToString();

        VeerDebug.Log("json to string : " + jsonString);

        TestJsonConvert test = FastJson.Deserialize <TestJsonConvert>(jsonString);

        VeerDebug.Log("fast json string field : " + test.StringField);

        string serialize = FastJson.Serialize(test);

        VeerDebug.Log("fast json serialize : " + serialize);
    }
Exemplo n.º 22
0
        private void Test_Example4()
        {
            ClassE e = new ClassE();
            ClassB b = new ClassB();
            ClassF f = new ClassF();
            ClassG g = new ClassG();

            e.class_b_list.Add(b);
            e.class_b_list.Add(f);
            e.class_b_list.Add(g);

            // 测试 反序列化
            string jsonStr = FastJson.Serialize(e);

            Debug.Log(jsonStr);
            ClassE deserializeE = FastJson.Deserialize <ClassE>(jsonStr);

            Debug.Log(FastJson.Serialize(deserializeE));
        }
Exemplo n.º 23
0
 private void Parse(string json)
 {
     infoList.Clear();
     if(string.IsNullOrEmpty(json))
         return;
     try
     {
         Dictionary<string, object> jsonDic = FastJson.Deserialize(json) as Dictionary<string, object>;
         List<object> list = jsonDic["apps"] as List<object>;
         if (list == null)
             return;
         for (int i = 0; i < list.Count; i++)
         {
             Dictionary<string, object> dic = list[i] as Dictionary<string, object>;
             CookieInfo info = new CookieInfo();
             info.package = dic.ContainsKey("pkg") ? dic["pkg"].ToString() : "";
             info.name = dic.ContainsKey("name") ? dic["name"].ToString() : "";
             //info.logoPath = dic.ContainsKey("path") ? dic["path"].ToString() : "";
             info.logoUrl = dic.ContainsKey("url") ? dic["url"].ToString() : "";
             info.version = dic.ContainsKey("ver") ? dic["ver"].ToString() : "";
             info.build = dic.ContainsKey("build") ? uint.Parse(dic["build"].ToString()) : 0;
             info.auther = dic.ContainsKey("auther") ? dic["auther"].ToString() : "";
             info.size = dic.ContainsKey("size") ? uint.Parse(dic["size"].ToString()) : 0;
             //info.downloadPriority = dic.ContainsKey("down") ? uint.Parse(dic["down"].ToString()) : 0;
             //info.status = dic.ContainsKey("st") ? int.Parse(dic["st"].ToString()) : 0;
             List<object> images = dic.ContainsKey("images") ? dic["images"] as List<object> : null;
             if (images != null)
             {
                 for (int j = 0; j < images.Count; j++)
                 {
                     Dictionary<string, object> tmp = images[j] as Dictionary<string, object>;
                     info.AddScreenshot(tmp["url"].ToString(), tmp["path"].ToString());
                 }
             }
             if (info.downloadPriority > downloadPriority)
                 downloadPriority = info.downloadPriority;
             //ZLog.Log("read cookie:"+info.ToString());
             infoList.Add(info);
         }
     }catch(Exception e){
         Debug.LogException(e);
     }
 }
Exemplo n.º 24
0
        private void Test_Example5()
        {
            Debug.Log("Test_Example5 begin ...");

            // 测试 Error Json
            ClassA a = null;

            try
            {
                FastJson.Deserialize <ClassA>("error json string ...");
                Debug.Log("deserialize success ...");
            }
            catch
            { Debug.Log("deserialize failed ..."); }

            if (a == null)
            {
                Debug.Log("when given error json ClassA is null...");
            }
            else
            {
                Debug.Log("when given error json ClassA is new ClassA ...");
            }

            // 测试 Default(T)
            a = null;
            try
            {
                FastJson.Deserialize <ClassA>("{}");
                Debug.Log("deserialize success ...");
            }
            catch
            { Debug.Log("deserialize failed ..."); }

            if (a == null)
            {
                Debug.Log("default ClassA is null...");
            }
            else
            {
                Debug.Log("default ClassA is new ClassA ...");
            }
        }
Exemplo n.º 25
0
        internal static void LoadDefinitions()
        {
            string defsPath = Path.Combine(modDataFolder, "definitions");

            string[] defFiles = Directory.GetFiles(defsPath, "*.json");
            Log(defsPath);


            if (defFiles.Length > 0)
            {
                objList = new List <Localization_def>();

                for (int i = 0; i < defFiles.Length; i++)
                {
                    string data = File.ReadAllText(defFiles[i]);
                    List <Localization_def> fileObjs = null;

                    try
                    {
                        fileObjs = FastJson.Deserialize <List <Localization_def> >(data);

                        objList.AddRange(fileObjs);

                        Log(" " + Path.GetFileName(defFiles[i]) + " definitions loaded ");
                    }
                    catch (FormatException e)
                    {
                        Log(" ERROR: " + Path.GetFileName(defFiles[i]) + " incorrectly formatted.");
                    }
                }
                if (objList.Count > 0)
                {
                    foreach (var o in objList)
                    {
                        keys.Add(o.id, o.text);
                    }
                }
            }
        }
Exemplo n.º 26
0
        private void Test_Example3()
        {
            ClassD tempD = new ClassD();

            tempD.class_c_list  = new List <ClassC>();
            tempD.class_c_array = new ClassC[3];
            tempD.class_c_dic   = new Dictionary <string, ClassC>();

            ClassC c1 = new ClassC();

            c1.c_tag = "c1";
            tempD.class_c_list.Add(c1);
            tempD.class_c_array[0] = c1;
            tempD.class_c_dic.Add("c0", c1);

            ClassC c2 = new ClassC();

            c2.c_tag = "c2";
            tempD.class_c_list.Add(c2);
            tempD.class_c_array[1] = c2;
            tempD.class_c_dic.Add("c1", c2);

            ClassC c3 = new ClassC();

            c3.c_tag = "c3";
            tempD.class_c_list.Add(c3);
            tempD.class_c_array[2] = c3;
            tempD.class_c_dic.Add("c2", c3);

            string jsonStr = FastJson.Serialize(tempD);

            Debug.Log(jsonStr);

            // 反序列化后其 list array dic 内容不再是相同引用,考虑限制 List 和 Array 的反序列化
            ClassD deserializeD = FastJson.Deserialize <ClassD>(jsonStr);

            Debug.Log(FastJson.Serialize(deserializeD));
        }
    void Test1 <T, U>(string name, GenerateFunc <U> generate) where T : new()
    {
        resultText = new StringBuilder();

        T obj = GenerateTestData2 <T, U>(generate);

        Stopwatch("FastJson,s," + name, () => { FastJson.Serialize(obj); });
        //Stopwatch( "EasyJson,s,"+name,	()=>{ EasyJSON.Serializer.Serialize(obj); } );
        //Stopwatch( "XML-JSON,s,"+name,	()=>{ JSONSerializer.Serialize(obj); } );
        //Stopwatch( "JSON.NET,s,"+name,    ()=>{ Newtonsoft.Json.JsonConvert.SerializeObject(obj); } );

        string fastJsonText = FastJson.Serialize(obj);

        //string jsonDotNetText = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        //string easyJsonText = EasyJSON.Serializer.Serialize(obj);
        //string xmlJsonText = JSONSerializer.Serialize(obj);

        Stopwatch("FastJson,d," + name, () => { FastJson.Deserialize <T>(fastJsonText); });
        //Stopwatch( "EasyJson,d,"+name,	()=>{ EasyJSON.Serializer.Deserialize<T>(easyJsonText); } );
        //Stopwatch( "XML-JSON,d,"+name,	()=>{ JSONSerializer.Deserialize<T>(xmlJsonText); } );
        //Stopwatch( "JSON.NET,d,"+name,    ()=>{ Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonDotNetText); } );

        Debug.Log(resultText.ToString());
    }
Exemplo n.º 28
0
 private void Test_Example8()
 {
     // 测试 反序列化 JSONObject 暂存为 string
     ClassI i = FastJson.Deserialize <ClassI>("{\"str\":{\"temp_key\":\"temp_value\"}}");
 }