示例#1
0
        public KeyValuePair <string, JsonNode> ToJson()
        {
            var requests = new JsonNodeList();

            foreach (ItemRequest request in Requests)
            {
                if (request is PutRequest)
                {
                    requests.Add(new JsonObject {
                        { "PutRequest", request.ToJson() }
                    });
                }
                else if (request is DeleteRequest)
                {
                    requests.Add(new JsonObject {
                        { "DeleteRequest", request.ToJson() }
                    });
                }
            }

            return(new KeyValuePair <string, JsonNode>(TableName, requests));
        }
示例#2
0
        public SkillTree()
        {
            nodeList = new NodeList();
            JsonNodeList NodeSaved = JsonSkillTree.GetJsonNodeList;

            NodeType   nodeT;
            ClassType  classT;
            DamageType damageT;
            LeechType  leechT;
            Immunity   immunityT;
            Stat       StatT;
            Perk       perkT;

            int i = 0;

            foreach (JsonNode actualNode in NodeSaved.jsonList)
            {
                nodeT = (NodeType)Enum.Parse(typeof(NodeType), actualNode.baseType);
                switch (nodeT)
                {
                case (NodeType.Damage):
                    damageT = (DamageType)Enum.Parse(typeof(DamageType), actualNode.specificType);
                    nodeList.AddNode(new DamageNode(damageT, actualNode.flatDamage, NodeType.Damage, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Class):
                    classT = (ClassType)Enum.Parse(typeof(ClassType), actualNode.specificType);
                    nodeList.AddNode(new ClassNode(classT, NodeType.Class, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, 1, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Speed):
                    damageT = (DamageType)Enum.Parse(typeof(DamageType), actualNode.specificType);
                    nodeList.AddNode(new SpeedNode(damageT, NodeType.Speed, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Immunity):
                    immunityT = (Immunity)Enum.Parse(typeof(Immunity), actualNode.specificType);
                    nodeList.AddNode(new ImmunityNode(immunityT, NodeType.Immunity, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Leech):
                    leechT = (LeechType)Enum.Parse(typeof(LeechType), actualNode.specificType);
                    nodeList.AddNode(new LeechNode(leechT, NodeType.Leech, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Perk):
                    perkT = (Perk)Enum.Parse(typeof(Perk), actualNode.specificType);
                    nodeList.AddNode(new PerkNode(perkT, NodeType.Perk, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.Stats):
                    StatT = (Stat)Enum.Parse(typeof(Stat), actualNode.specificType);
                    nodeList.AddNode(new StatNode(StatT, actualNode.flatDamage, NodeType.Stats, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;

                case (NodeType.LimitBreak):
                    nodeList.AddNode(new LimitBreakNode(actualNode.specificType, NodeType.LimitBreak, actualNode.unlocked, actualNode.valuePerLevel, actualNode.levelRequirement, actualNode.maxLevel, actualNode.pointsPerLevel, actualNode.ascended));
                    break;
                }

                nodeList.nodeList[i].menuPos = new Vector2(actualNode.posX, actualNode.posY);
                i++;
            }
            i = 0;
            foreach (JsonNode actualNode in NodeSaved.jsonList)
            {
                foreach (int nbID in actualNode.neigthboorlist)
                {
                    nodeList.nodeList[i].AddNeighboor(nodeList.nodeList[nbID]);
                }

                i++;
            }
        }
示例#3
0
        public JsonObject ToJson()
        {
            // {"N":"225"}
            // {"S":"Hello"}
            // {"SS": ["Keneau", "Alexis", "John"]}
            // {"NS": ["1", "2", "3"]}

            JsonNode node;

            if (kind == DbValueType.M)
            {
                node = ((AttributeCollection)value).ToJson();
            }
            else if (kind == DbValueType.B && value is byte[] data)
            {
                node = new JsonString(Convert.ToBase64String(data));
            }
            else if (kind == DbValueType.L)
            {
                var list = new JsonNodeList();

                foreach (var item in (IEnumerable <DbValue>)value)
                {
                    list.Add(item.ToJson());
                }

                node = list;
            }
            else if (value.GetType().IsArray)
            {
                var elementType = value.GetType().GetElementType();

                if (elementType == typeof(string))
                {
                    node = new XImmutableArray <string>((string[])value);
                }
                else
                {
                    var list = new List <string>();

                    foreach (var item in (IEnumerable)value)
                    {
                        list.Add(item.ToString());
                    }

                    node = new XList <string>(list);
                }
            }
            else if (kind == DbValueType.BOOL)
            {
                var val = (bool)value;

                node = val ? JsonBoolean.True : JsonBoolean.False;
            }
            else
            {
                node = new JsonString(value.ToString());
            }

            return(new JsonObject {
                { kind.ToQuickString(), node }
            });
        }