Ejemplo n.º 1
0
        public void JArrayToStringTest()
        {
            JArray  a    = new JArray();
            JNumber n    = new JNumber(42);
            JNumber n2   = new JNumber(7.3);
            JString s    = new JString("pokus");
            JString s2   = new JString("pokus2");
            JBool   b    = new JBool(true);
            JBool   b2   = new JBool(false);
            JNull   nu   = new JNull();
            JNull   nu2  = new JNull();
            JNull   nu3  = new JNull();
            JToken  t    = new JToken();
            JRoot   root = new JRoot();

            root["pole"] = a;
            a.Add(n);
            a.Add(s);
            a.Add(b);
            a.Add(nu);
            a.Add(t);
            t["string"] = s2;
            t["nill"]   = nu2;
            t["cislo"]  = n2;
            Console.WriteLine(a.ToString());
            JArray aa = new JArray();

            a.Add(aa);
            aa.Add(nu3);
            aa.Add(b2);
            Console.WriteLine(a.ToString());
        }
Ejemplo n.º 2
0
        public void JTokenToStringPressedTest()
        {
            JNumber n    = new JNumber(7.3);
            JNumber n2   = new JNumber(42);
            JNumber n3   = new JNumber(3.14);
            JString s    = new JString("example");
            JBool   b    = new JBool(true);
            JNull   nu   = new JNull();
            JArray  aa   = new JArray();
            JToken  root = new JToken();
            JToken  t    = new JToken();
            JToken  tt   = new JToken();
            JRoot   r    = new JRoot();

            r["mnau"]           = root;
            root["dalsi cislo"] = n;
            root["token"]       = t;
            t["inside"]         = aa;
            t["string"]         = s;
            aa.Add(n2);
            aa.Add(b);
            aa.Add(tt);
            tt["cislo"] = n3;
            tt["nil"]   = (nu);

            try { aa.Add(nu); }
            catch (JsonDuplicatedException e) { Console.WriteLine("zkusili jsme pridat podruhe"); }

            Console.WriteLine(root.ToStringPressed());
            Console.WriteLine(root.ToString());
            Console.WriteLine(r.ToStringPressed());
            Console.WriteLine(r.ToString());
        }
Ejemplo n.º 3
0
        public void JTokenToStringTest()
        {
            JArray  a    = new JArray("test");
            JNumber n    = new JNumber("number", 7.3);
            JString s    = new JString("string", "example");
            JBool   b    = new JBool("bool", true);
            JNull   nu   = new JNull("nil");
            JArray  aa   = new JArray("inside");
            JToken  root = new JToken("root");
            JToken  t    = new JToken("token");
            JToken  tt   = new JToken("token2");

            aa.Value.Add(n);
            aa.Value.Add(b);
            tt.Value.Add(b);
            tt.Value.Add(nu);
            aa.Value.Add(tt);
            a.Value.Add(s);
            a.Value.Add(aa);
            a.Value.Add(n);
            t.Value.Add(aa);
            t.Value.Add(s);
            root.Value.Add(n);
            root.Value.Add(t);
            Console.WriteLine(root.ValueToString(0));
            Assert.Fail();
        }
Ejemplo n.º 4
0
        public void JTokenToStringPressedTest()
        {
            JArray  a    = new JArray("test");
            JNumber n    = new JNumber("number", 7.3);
            JString s    = new JString("string", "example");
            JBool   b    = new JBool("bool", true);
            JNull   nu   = new JNull("nil");
            JArray  aa   = new JArray("inside");
            JToken  root = new JToken("root");
            JToken  t    = new JToken("token");
            JToken  tt   = new JToken("token2");

            aa.Value.Add(n);
            aa.Value.Add(b);
            tt.Value.Add(b);
            tt.Value.Add(nu);
            aa.Value.Add(tt);
            a.Value.Add(s);
            a.Value.Add(aa);
            a.Value.Add(n);
            t.Value.Add(aa);
            t.Value.Add(s);
            root.Value.Add(n);
            root.Value.Add(t);
            Console.WriteLine(root.ValueToStringPressed());
            Assert.AreEqual("{\"number\":7.3,\"token\":{\"inside\":[7.3,true,{\"bool\":true,\"nil\":null}],\"string\":\"example\"}}", root.ValueToStringPressed());
        }
Ejemplo n.º 5
0
        // =================================================================================
        // Import
        // ---------------------------------------------------------------------------------
        public static bool Import(iCS_VisualScriptData storage, string path)
        {
            // -- Decode JSON string. --
            JObject root = JSONFile.Read(path);

            if (root == null || root.isNull)
            {
                Debug.LogWarning("iCanScript: Import failure: JSON file corrupted.");
                return(false);
            }
            // -- Extract version information. --
            var     cache         = new iCS_VisualScriptData();
            JNumber majorVersion  = root.GetValueFor("Storage.MajorVersion") as JNumber;
            JNumber minorVersion  = root.GetValueFor("Storage.MinorVersion") as JNumber;
            JNumber bugFixVersion = root.GetValueFor("Storage.BugFixVersion") as JNumber;

            cache.MajorVersion  = (int)majorVersion.value;
            cache.MinorVersion  = (int)minorVersion.value;
            cache.BugFixVersion = (int)bugFixVersion.value;
            // -- Extract visual script attributes. --
            JBool   isEditorScript   = root.GetValueFor("Storage.IsEditorScript") as JBool;
            JString csharpFileName   = root.GetValueFor("Storage.CSharpFileName") as JString;
            JBool   baseTypeOverride = root.GetValueFor("Storage.BaseTypeOverride") as JBool;
            JString baseType         = root.GetValueFor("Storage.BaseType") as JString;
            JString sourceFileGUID   = root.GetValueFor("Storage.SourceFileGUID") as JString;

            cache.IsEditorScript   = isEditorScript.value;
            cache.CSharpFileName   = csharpFileName.value;
            cache.BaseTypeOverride = baseTypeOverride.value;
            cache.BaseType         = baseType.value;
            cache.SourceFileGUID   = sourceFileGUID.value;
            // -- Extract engine objects. --
            JArray engineObjects = root.GetValueFor("Storage.EngineObjects") as JArray;

            if (engineObjects == null)
            {
                Debug.LogWarning("iCanScript: Import failure: Unable to locate engine array.");
                return(false);
            }
            cache.EngineObjects.Capacity = engineObjects.value.Length;
            foreach (var eobj in engineObjects.value)
            {
                var newObj = ReadEngineObject(eobj as JObject);
                if (newObj != null)
                {
                    cache.EngineObjects.Add(newObj);
                }
                else
                {
                    Debug.LogWarning("iCanScript: Unable to create instance of iCS_EngineObject");
                }
            }
            cache.CopyTo(storage);
            return(true);
        }
Ejemplo n.º 6
0
        public void JBoolValueToStrinTest()
        {
            JBool t = new JBool("", true);

            Assert.IsNotNull(t);
            JBool f = new JBool("", false);

            Console.WriteLine(t.ValueToString(0));
            Assert.AreEqual("true", t.ValueToString(0));
            Console.WriteLine(f.ValueToString(0));
            Assert.AreEqual("false", f.ValueToString(0));
        }
Ejemplo n.º 7
0
 protected override JBool caculate(JBool para1, JBool para2)
 {
     if (!para1.Value)
     {
         return(new JBool(false));
     }
     else if (!para2.Value)
     {
         return(new JBool(false));
     }
     return(new JBool(true));
 }
Ejemplo n.º 8
0
        public void JBoolToStringPressedTest()
        {
            JBool b = new JBool("test")
            {
                Value = true
            };

            Assert.IsNotNull(b);
            Assert.AreEqual("test", b.Name);
            Assert.AreEqual(true, b.Value);
            Console.WriteLine(b.ToString());
            Assert.AreEqual("\"test\":true", b.ToStringPressed());
            b.Value = false;
            Console.WriteLine(b.ToString());
            Assert.AreEqual("\"test\":false", b.ToStringPressed());
        }
Ejemplo n.º 9
0
        public void JBooolFillTest()
        {
            JBool b = new JBool("test")
            {
                Value = true
            };

            Assert.IsNotNull(b);
            Assert.AreEqual("test", b.Name);
            Assert.AreEqual(true, b.Value);
            JBool b2 = new JBool("test2", false);

            Assert.IsNotNull(b2);
            Assert.AreEqual("test2", b2.Name);
            Assert.AreEqual(false, b2.Value);
        }
Ejemplo n.º 10
0
        public void JArrayToStringTest()
        {
            JArray  a  = new JArray("test");
            JNumber n  = new JNumber("cislo", 42);
            JString s  = new JString("string", "pokus");
            JBool   b  = new JBool("bool", true);
            JNull   nu = new JNull("nil");
            JArray  aa = new JArray("inside");

            a.Value.Add(nu);
            a.Value.Add(b);
            a.Value.Add(s);
            aa.Value.Add(n);
            aa.Value.Add(s);
            a.Value.Add(aa);
            Assert.IsNotNull(a);
            Console.WriteLine(a.ToString(0));
            Assert.AreEqual("\"test\": [\n\tnull,\n\ttrue,\n\t\"pokus\",\n\t[\n\t\t42,\n\t\t\"pokus\"\n\t]\n]", a.ToString(0));
        }
Ejemplo n.º 11
0
        public void JArrayValueToStringPressedTest()
        {
            JArray  a  = new JArray("test");
            JNumber n  = new JNumber("cislo", 42);
            JString s  = new JString("string", "pokus");
            JBool   b  = new JBool("bool", true);
            JNull   nu = new JNull("nil");

            //Jobject o = ...
            a.Value.Add(n);
            a.Value.Add(s);
            a.Value.Add(b);
            a.Value.Add(nu);
            JArray aa = new JArray("inside");

            aa.Value.Add(nu);
            aa.Value.Add(b);
            a.Value.Add(aa);
            Console.WriteLine(a.ValueToStringPressed());
            Assert.IsNotNull(a);
            Assert.AreEqual("[42,\"pokus\",true,null,[null,true]]", a.ValueToStringPressed());
        }
Ejemplo n.º 12
0
        // ========================================================================
        /// Creates a new Project info from the given JSON root object.
        ///
        /// @param jsonRoot The JSON root object from which to extract the package
        ///                 information.
        ///
        public static PackageInfo Load(JObject jsonRoot)
        {
            // -- Read the package information from the JSON string. --
            JString version     = jsonRoot.GetValueFor("myVersion") as JString;
            JString packageName = jsonRoot.GetValueFor("myPackageName") as JString;
            JBool   isNested    = jsonRoot.GetValueFor("myIsNested") as JBool;

            // -- Don't create a package if core infromation is not present. --
            if (version == null || version.isNull ||
                packageName == null || packageName.isNull ||
                isNested == null || isNested.isNull)
            {
                return(null);
            }
            // -- Set the package with the information red from the JSON file. --
            var newProject = new PackageInfo();

            newProject.myVersion     = version.value;
            newProject.myPackageName = packageName.value;
            newProject.myIsNested    = isNested.value;

//            newProject.myParentFolder       = parentFolder.value;
            return(newProject);
        }
Ejemplo n.º 13
0
 protected abstract JBool caculate(JBool flag1, JBool flag2);