Beispiel #1
0
 public static string GetString(this JsonNode self)
 {
     return(self.Value.GetString());
 }
Beispiel #2
0
        public static Vrm0Meta FromJsonBytes(UniJSON.JsonNode glTF)
        {
            var oldMeta    = new Vrm0Meta();
            var extensions = glTF["extensions"];
            var vrm        = extensions["VRM"];
            var meta       = vrm["meta"];

            foreach (var kv in meta.ObjectItems())
            {
                var key = kv.Key.GetString();
                switch (key)
                {
                case "title":
                    oldMeta.title = kv.Value.GetString();
                    break;

                case "version":
                    oldMeta.version = kv.Value.GetString();
                    break;

                case "author":
                    oldMeta.author = kv.Value.GetString();
                    break;

                case "contactInformation":
                    oldMeta.contactInformation = kv.Value.GetString();
                    break;

                case "reference":
                    oldMeta.reference = kv.Value.GetString();
                    break;

                case "texture":
                    oldMeta.texture = kv.Value.GetInt32();
                    break;

                case "allowedUserName":
                    oldMeta.allowedUser = (AllowedUser)Enum.Parse(typeof(AllowedUser), kv.Value.GetString(), true);
                    break;

                case "violentUssageName":
                    oldMeta.violentUsage = kv.Value.GetString() == "Allow";
                    break;

                case "sexualUssageName":
                    oldMeta.sexualUsage = kv.Value.GetString() == "Allow";
                    break;

                case "commercialUssageName":
                    oldMeta.commercialUsage = kv.Value.GetString() == "Allow";
                    break;

                case "otherPermissionUrl":
                    oldMeta.otherPermissionUrl = kv.Value.GetString();
                    break;

                case "licenseName":
                    oldMeta.licenseType = (LicenseType)Enum.Parse(typeof(LicenseType), kv.Value.GetString(), true);
                    break;

                case "otherLicenseUrl":
                    oldMeta.otherLicenseUrl = kv.Value.GetString();
                    break;

                default:
                    UnityEngine.Debug.Log($"{key}");
                    break;
                }
            }
            return(oldMeta);
        }
Beispiel #3
0
 public static Int32 GetInt32(this JsonNode self)
 {
     return(self.Value.GetInt32());
 }
Beispiel #4
0
 public static Double GetDouble(this JsonNode self)
 {
     return(self.Value.GetDouble());
 }
Beispiel #5
0
 public static Boolean GetBoolean(this JsonNode self)
 {
     return(self.Value.GetBoolean());
 }
Beispiel #6
0
 public JsonPointer(JsonNode node)
 {
     Path = new ArraySegment <string>(node.Path().Skip(1).Select(x => GetKeyFromParent(x)).ToArray());
 }
Beispiel #7
0
        public IEnumerable <JsonDiff> Diff(JsonNode rhs, JsonPointer path = default(JsonPointer))
        {
            switch (Value.ValueType)
            {
            case JsonValueType.Null:
            case JsonValueType.Boolean:
            case JsonValueType.Number:
            case JsonValueType.Integer:
            case JsonValueType.String:
                if (!Equals(rhs))
                {
                    yield return(new JsonDiff(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value, rhs.Value)));
                }
                yield break;
            }

            if (Value.ValueType != rhs.Value.ValueType)
            {
                yield return(new JsonDiff(this, JsonDiffType.ValueChanged, string.Format("{0} => {1}", Value.ValueType, rhs.Value)));

                yield break;
            }

            if (Value.ValueType == JsonValueType.Object)
            {
                var l = ObjectItems.ToDictionary(x => x.Key, x => x.Value);
                var r = rhs.ObjectItems.ToDictionary(x => x.Key, x => x.Value);

                foreach (var kv in l)
                {
                    JsonNode x;
                    if (r.TryGetValue(kv.Key, out x))
                    {
                        r.Remove(kv.Key);
                        // Found
                        foreach (var y in kv.Value.Diff(x))
                        {
                            yield return(y);
                        }
                    }
                    else
                    {
                        // Removed
                        yield return(new JsonDiff(kv.Value, JsonDiffType.KeyRemoved, kv.Value.Value.ToString()));
                    }
                }

                foreach (var kv in r)
                {
                    // Addded
                    yield return(new JsonDiff(kv.Value, JsonDiffType.KeyAdded, kv.Value.Value.ToString()));
                }
            }
            else if (Value.ValueType == JsonValueType.Array)
            {
                var ll = ArrayItems.GetEnumerator();
                var rr = rhs.ArrayItems.GetEnumerator();
                while (true)
                {
                    var lll = ll.MoveNext();
                    var rrr = rr.MoveNext();
                    if (lll && rrr)
                    {
                        // found
                        foreach (var y in ll.Current.Diff(rr.Current))
                        {
                            yield return(y);
                        }
                    }
                    else if (lll)
                    {
                        yield return(new JsonDiff(ll.Current, JsonDiffType.KeyRemoved, ll.Current.Value.ToString()));
                    }
                    else if (rrr)
                    {
                        yield return(new JsonDiff(rr.Current, JsonDiffType.KeyAdded, rr.Current.Value.ToString()));
                    }
                    else
                    {
                        // end
                        break;
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #8
0
 public JsonDiff(JsonNode node, JsonDiffType diffType, string msg)
 {
     Path     = new JsonPointer(node);
     DiffType = diffType;
     Msg      = msg;
 }
Beispiel #9
0
 public bool Parse(IFileSystemAccessor fs, string key, JsonNode value)
 {
     return(false);
 }