public static JSONElement OnConvertToJSONElement(object obj)
            {
                JSONBool jsonObj = new JSONBool();

                jsonObj._value = (bool)obj;
                return(jsonObj);
            }
    public void SaveLevel()
    {
        JSONObject levelJSON = new JSONObject();

        //saving the current active charger to set spawn point
        JSONObject activeChargerJSON = new JSONObject();

        activeChargerJSON["x"].AsFloat = currentActiveCharger.gameObject.transform.position.x;
        activeChargerJSON["y"].AsFloat = currentActiveCharger.gameObject.transform.position.y + .5f;
        levelJSON["playerSpawnPoint"]  = activeChargerJSON;

        //saving what upgrades are currently obtained
        JSONBool dJumpJSON = new JSONBool(doubleJumpEnabled);
        JSONBool wJumpJSON = new JSONBool(wallJumpEnabled);
        JSONBool aDashJSON = new JSONBool(airDashEnabled);

        levelJSON["doubleJumpActive"] = dJumpJSON;
        levelJSON["wallJumpActive"]   = wJumpJSON;
        levelJSON["airDashActive"]    = aDashJSON;

        //saving smallMaxCharge
        JSONNumber chargeJSON = new JSONNumber(player.GetComponent <RigidbodyPlayer>().smallMaxCharge);

        levelJSON["currentlyAvailableCharge"] = chargeJSON;

        string levelJSONString = levelJSON.ToString();
        string filename        = Application.dataPath + Path.DirectorySeparatorChar + "currentGameState.json";

        Debug.Log(levelJSONString);
        File.WriteAllText(filename, levelJSONString);
    }
Beispiel #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            JSONNode n = new JSONObject();

            n["test"]        = new JSONNumber(1234);
            n["asdf"]        = new JSONObject();
            n["asd4"]        = new JSONObject();
            n["asdf"]["123"] = new JSONBool(true);
            ReceiveNode(n);
        }
 // Bool
 /// <summary>
 /// Sets the value of the preferences identified by the key.
 /// </summary>
 public static void SetBool(string key, bool value)
 {
     if (Prefs[key] == null)
     {
         Prefs[key] = new JSONBool(value);
     }
     else
     {
         Prefs[key].AsBool = value;
     }
     Save();
 }
Beispiel #5
0
            private JSONElement ParseValue()
            {
                switch (lexer.LookAhead())
                {
                case Lexer.Token.String:
                {
                    JSONString jsonString = new JSONString();
                    jsonString._value = EvalLexer(lexer.ParseString());
                    return(jsonString);
                }

                case Lexer.Token.Number:
                {
                    JSONNumber jsonNumber = new JSONNumber();
                    jsonNumber._value = EvalLexer(lexer.ParseDoubleNumber());
                    return(jsonNumber);
                }

                case Lexer.Token.CurlyOpen:
                    return(ParseObject());

                case Lexer.Token.SquaredOpen:
                    return(ParseArray());

                case Lexer.Token.True:
                {
                    lexer.NextToken();
                    JSONBool jsonBool = new JSONBool();
                    jsonBool._value = true;
                    return(jsonBool);
                }

                case Lexer.Token.False:
                {
                    lexer.NextToken();
                    JSONBool jsonBool = new JSONBool();
                    jsonBool._value = false;
                    return(jsonBool);
                }

                case Lexer.Token.Null:
                    lexer.NextToken();
                    return(null);

                case Lexer.Token.None:
                    break;
                }

                TriggerError("Unable to parse value");
                return(null);
            }
Beispiel #6
0
    private void SendToPrivateServer(string eventName, Dictionary <string, object> eventData)
    {
        WWWForm postData = new WWWForm();

        postData.AddField("user_uuid", uuid);

        string timestamp = DateTime.UtcNow.ToString("u");

        postData.AddField("event_timestamp", timestamp);

        JSONObject data = new JSONObject();

        foreach (KeyValuePair <string, object> entry in eventData)
        {
            object   valueObject = entry.Value;
            JSONNode node        = null;

            if (valueObject is bool)
            {
                node = new JSONBool((bool)valueObject);
            }
            else if (valueObject is int)
            {
                node = new JSONNumber(valueObject.ToString());
            }
            else if (valueObject is float)
            {
                node = new JSONNumber((float)valueObject);
            }
            else if (valueObject is string)
            {
                node = new JSONString((string)valueObject);
            }
            else
            {
                Debug.LogError("Unsupported type in analytics.");
            }

            if (node != null)
            {
                data.Add(entry.Key, node);
            }
        }

        postData.AddField("event_name", eventName);
        postData.AddField("event_data", data.ToString());

        WWW httpRequest = new WWW("https://thejv.club/roguelike-analytics/", postData);

        StartCoroutine(SendRequest(httpRequest));
    }
    public static bool GetBoolChild(this JSONArray array, int index)
    {
        JSONNode childNode = array[index];

        if (childNode == null)
        {
            return(false);
        }

        JSONBool boolNode = childNode as JSONBool;

        if (boolNode == null)
        {
            Debug.LogErrorFormat("JSON deserialization: expected [{0}] to be Bool.", index);
        }
        return(boolNode);
    }
    public static bool GetBoolChild(this JSONNode node, string key)
    {
        JSONNode childNode = node[key];

        if (childNode == null)
        {
            return(false);
        }

        JSONBool boolNode = childNode as JSONBool;

        if (boolNode == null)
        {
            Debug.LogErrorFormat("JSON deserialization: expected '{0}' to be Bool.", key);
        }
        return(boolNode);
    }
Beispiel #9
0
        public static JSONNode Copy(JSONNode node)
        {
            JSONNode result = null;

            if (node.IsBoolean)
            {
                result = new JSONBool(false);
            }
            if (node.IsNumber)
            {
                result = new JSONNumber(0);
            }
            if (node.IsString)
            {
                result = new JSONString(string.Empty);
            }
            if (node.IsNull)
            {
                result = JSONNull.CreateOrGet();
            }
            if (node.IsArray)
            {
                result = new JSONArray();
                foreach (var arrayItem in node)
                {
                    result.Add(Copy(arrayItem));
                }
            }
            if (node.IsObject)
            {
                result = new JSONObject();
                foreach (var field in node)
                {
                    result.Add(field.Key, Copy(field));
                }
            }
            return(result);
        }
Beispiel #10
0
        public void Execute(JSONNode args)
        {
            var uid = args["uid"].Value;
            var api = ApiManager.Instance;

            if (api.Agents.TryGetValue(uid, out GameObject obj))
            {
                var bridge = obj.GetComponentInChildren <BridgeClient>();
                if (bridge == null)
                {
                    api.SendError($"Agent '{uid}' is missing bridge client");
                }
                else
                {
                    var result = new JSONBool(bridge.BridgeStatus == Status.Connected);
                    api.SendResult(result);
                }
            }
            else
            {
                api.SendError($"Agent '{uid}' not found");
            }
        }
Beispiel #11
0
        public void Execute(JSONNode args)
        {
            var uid = args["uid"].Value;

            GameObject obj;

            if (ApiManager.Instance.Agents.TryGetValue(uid, out obj))
            {
                var setup = obj.GetComponent <AgentSetup>();
                if (setup == null)
                {
                    ApiManager.Instance.SendError($"Agent '{uid}' is not an EGO vehicle");
                }
                else
                {
                    var result = new JSONBool(setup.Connector.Bridge.Status == Comm.BridgeStatus.Connected);
                    ApiManager.Instance.SendResult(result);
                }
            }
            else
            {
                ApiManager.Instance.SendError($"Agent '{uid}' not found");
            }
        }
Beispiel #12
0
        public void TestValues()
        {
            int  int_const = 1234;
            JSON int_json  = int_const;
            int  int_value = int_json;

            Assert.IsTrue(int_json.GetJSONType() == JSONType.Value);
            Assert.IsTrue(int_json.AsValue().GetValueType() == JSONValueType.Int);
            Assert.IsTrue(int_json.AsValue().ToInt() == int_const);
            Assert.IsTrue(int_json == int_const);
            Assert.IsTrue(int_json == int_value);

            long long_const = (long)int.MaxValue + 1;
            JSON long_json  = long_const;
            long long_value = long_json;

            Assert.IsTrue(long_json.GetJSONType() == JSONType.Value);
            Assert.IsTrue(long_json.AsValue().GetValueType() == JSONValueType.Long);
            Assert.IsTrue(long_json.AsValue().ToLong() == long_const);
            Assert.IsTrue(long_json == long_const);
            Assert.IsTrue(long_json == long_value);

            float float_const = 0.0f;
            JSON  float_json  = float_const;
            float float_value = float_json;

            Assert.IsTrue(float_json.GetJSONType() == JSONType.Value);
            Assert.IsTrue(float_json.AsValue().GetValueType() == JSONValueType.Float);
            Assert.IsTrue(float_json.AsValue().ToFloat() == float_const);
            Assert.IsTrue(float_json == float_const);
            Assert.IsTrue(float_json == float_value);

            string string_const = "this is a string";
            JSON   string_json  = string_const;
            string string_value = string_json;

            Assert.IsTrue(string_json.GetJSONType() == JSONType.Value);
            Assert.IsTrue(string_json.AsValue().GetValueType() == JSONValueType.String);
            Assert.IsTrue(string_json.AsValue().ToString() == string_const);
            Assert.IsTrue(string_json == string_const);
            Assert.IsTrue(string_json == string_value);

            bool bool_const = false;
            JSON bool_json  = bool_const;
            bool bool_value = bool_json;

            Assert.IsTrue(bool_json.GetJSONType() == JSONType.Value);
            Assert.IsTrue(bool_json.AsValue().GetValueType() == JSONValueType.Bool);
            Assert.IsTrue(bool_json.AsValue().ToBool() == bool_const);
            Assert.IsTrue(bool_json == bool_const);
            Assert.IsTrue(bool_json == bool_value);

            var values = new JSONObject();

            {
                JSON    item           = 1;
                JSONInt explicitItem   = 1;
                JSONInt created        = new JSONInt(1);
                var     assignedInt    = new JSONInt().SetInt(1);
                var     assignedLong   = new JSONInt().SetLong(1L);
                var     assignedfloat  = new JSONInt().SetFloat(1f);
                var     assignedBool   = new JSONInt().SetBool(true);
                var     assignedString = new JSONInt().SetString("1");
                JSON    array          = new JSONArray {
                    1, item, explicitItem, created, assignedInt, assignedLong, assignedfloat, assignedBool, assignedString
                };
                values["Int"] = array;
            }
            {
                JSON     item           = 1L;
                JSONLong explicitItem   = 1L;
                JSONLong created        = new JSONLong(1L);
                var      assignedInt    = new JSONLong().SetInt(1);
                var      assignedLong   = new JSONLong().SetLong(1L);
                var      assignedfloat  = new JSONLong().SetFloat(1f);
                var      assignedBool   = new JSONLong().SetBool(true);
                var      assignedString = new JSONLong().SetString("1");
                JSON     array          = new JSONArray {
                    1L, item, explicitItem, created, assignedInt, assignedLong, assignedfloat, assignedBool, assignedString
                };
                values["Long"] = array;
            }
            {
                JSON      item           = 1f;
                JSONFloat explicitItem   = 1f;
                JSONFloat created        = new JSONFloat(1f);
                var       assignedInt    = new JSONFloat().SetInt(1);
                var       assignedLong   = new JSONFloat().SetLong(1L);
                var       assignedfloat  = new JSONFloat().SetFloat(1f);
                var       assignedBool   = new JSONFloat().SetBool(true);
                var       assignedString = new JSONFloat().SetString("1");
                JSON      array          = new JSONArray {
                    1f, item, explicitItem, created, assignedInt, assignedLong, assignedfloat, assignedBool, assignedString
                };
                values["Float"] = array;
            }
            {
                JSON     item           = true;
                JSONBool explicitItem   = true;
                JSONBool created        = new JSONBool(true);
                var      assignedInt    = new JSONBool().SetInt(1);
                var      assignedLong   = new JSONBool().SetLong(1L);
                var      assignedfloat  = new JSONBool().SetFloat(1f);
                var      assignedBool   = new JSONBool().SetBool(true);
                var      assignedString = new JSONBool().SetString("true");
                JSON     array          = new JSONArray {
                    true, item, explicitItem, created, assignedInt, assignedLong, assignedfloat, assignedBool, assignedString
                };
                values["Bool"] = array;
            }
            {
                JSON       item           = "1";
                JSONString explicitItem   = "1";
                JSONString created        = new JSONString("1");
                var        assignedInt    = new JSONString().SetInt(1);
                var        assignedLong   = new JSONString().SetLong(1L);
                var        assignedfloat  = new JSONString().SetFloat(1f);
                var        assignedBool   = new JSONString().SetBool(true);
                var        assignedString = new JSONString().SetString("1");
                JSON       array          = new JSONArray {
                    "1", item, explicitItem, created, assignedInt, assignedLong, assignedfloat, assignedBool, assignedString
                };
                values["String"] = array;
            }
            foreach (var kvp in values)
            {
                for (int i = 0; i < kvp.Value.Count - 1; ++i)
                {
                    var a     = kvp.Value[i];
                    var b     = kvp.Value[i + 1];
                    var equal = a == b;
                    if (kvp.Key == "String")
                    {
                        if ((a == "true" && b == "1") || (a == "1" && b == "true"))
                        {
                            equal = true;
                        }
                    }
                    Assert.IsTrue(equal);
                }
            }
        }
Beispiel #13
0
        private void ChangeType(object sender, EventArgs e)
        {
            ComboBox c = (ComboBox)sender;
            JSONNode n = (JSONNode)c.Tag;
            TreeNode t = JSONFormUtil.FindTreeNode(tview_object.TopNode, n);
            JSONNode newnode;

            switch (c.SelectedIndex)
            {
            case 0:
                newnode = new JSONArray();
                break;

            case 1:
                newnode = new JSONBool(true);
                break;

            case 2:
                newnode = new JSONNull();
                break;

            case 3:
                newnode = new JSONNumber(0);
                break;

            case 4:
                newnode = new JSONObject();
                break;

            case 5:
                newnode = new JSONString("type a string");
                break;

            default:
                newnode = new JSONNull();
                break;
            }
            t.Nodes.Clear();
            t.Text = newnode.type.GetTypeString();
            t.Tag  = newnode;
            JSONNode pNode = n.parent;

            for (int i = 0; i < pNode.Count; ++i)
            {
                if (ReferenceEquals(pNode[i], n))
                {
                    pNode[i] = newnode;
                    break;
                }
            }
            Panel p = (Panel)c.Parent;

            p.Tag = newnode;

            Control keybox         = FindControl(p, "keybox");
            string  original_key   = keybox.Text;
            bool    original_fixed = keybox.Enabled;

            p.Controls.Clear();

            p.Controls.Add(CreateKeyBox(newnode, original_key, original_fixed));
            p.Controls.Add(CreateComboBox(newnode));
            p.Controls.Add(CreateDeleteButton(newnode));
            if (newnode.type == JSONType.Object || newnode.type == JSONType.Array)
            {
                p.Controls.Add(CreateValueLabel());
                p.Controls.Add(CreateModifyButton(newnode));
                Panel g = CreateJSONNodeGroupBox(newnode, p);
                p.Controls.Add(CreateNewNodeButton(newnode));
                g.BackColor = FormConstValue.baseColor;
                g.Location  = new Point(FormConstValue.stepX, FormConstValue.stepY);
                p.Controls.Add(g);
            }
            else
            {
                p.Controls.Add(CreateValueTextBox(newnode));
            }
            PanelReSort(p);
        }
Beispiel #14
0
        private static JSONNode DoObject2JSONNode(string key, object obj, JSONNode parent)
        {
            if (obj == null)
            {
                JSONNode jnull = new JSONNull();
                if (!DoObject2JSONNode_AddToParent(parent, key, jnull))
                {
                    return(jnull);
                }
            }
            else if (obj is IDictionary)
            {
                JSONObject jobject = Johny.JSONNodePool.Claim(typeof(Johny.JSONObject)).AsObject;
                var        it      = (obj as IDictionary).GetEnumerator();
                while (it.MoveNext())
                {
                    DoObject2JSONNode(it.Key as string, it.Value, jobject);
                }

                if (!DoObject2JSONNode_AddToParent(parent, key, jobject))
                {
                    return(jobject);
                }
            }
            else if (obj is ICollection)
            {
                JSONArray jarray = Johny.JSONNodePool.Claim(typeof(Johny.JSONArray)).AsArray;
                var       it     = (obj as ICollection).GetEnumerator();
                while (it.MoveNext())
                {
                    DoObject2JSONNode(string.Empty, it.Current, jarray);
                }

                if (!DoObject2JSONNode_AddToParent(parent, key, jarray))
                {
                    return(jarray);
                }
            }
            else if (obj is string)
            {
                JSONString jstring = Johny.JSONNodePool.Claim(typeof(Johny.JSONString)) as JSONString;
                jstring.InitString(obj as string);

                if (!DoObject2JSONNode_AddToParent(parent, key, jstring))
                {
                    return(jstring);
                }
            }
            else if (obj is bool)
            {
                JSONBool jbool = new JSONBool((bool)obj);
                if (!DoObject2JSONNode_AddToParent(parent, key, jbool))
                {
                    return(jbool);
                }
            }
            else if (obj is System.Enum)
            {
                JSONNumber jnum = new JSONNumber((int)obj);
                if (!DoObject2JSONNode_AddToParent(parent, key, jnum))
                {
                    return(jnum);
                }
            }
            else if (IsNumeric(obj))
            {
                double     dd   = Convert.ToDouble(obj);
                JSONNumber jnum = new JSONNumber(dd);
                if (!DoObject2JSONNode_AddToParent(parent, key, jnum))
                {
                    return(jnum);
                }
            }
            else
            {
                EB.Debug.LogError($"此类型JSON无法解析,请自行转换成基本类型!==> {obj.GetType().FullName}");
            }

            return(null);
        }
Beispiel #15
0
 public static string ToString(JSONBool jsonBool)
 {
     return(jsonBool._value ? "true" : "false");
 }