Beispiel #1
0
        public SkillTree(String treestring, bool displayProgress, UpdateLoadingWindow update)
        {
            PoESkillTree inTree = null;

            if (!_Initialized)
            {
                var jss = new JsonSerializerSettings
                {
                    Error = delegate(object sender, ErrorEventArgs args)
                    {
                        Debug.WriteLine(args.ErrorContext.Error.Message);
                        args.ErrorContext.Handled = true;
                    }
                };

                inTree = JsonConvert.DeserializeObject <PoESkillTree>(treestring.Replace("Additional ", ""), jss);
            }
            int qindex = 0;

            if (!_Initialized)
            {
                SkillTree._IconInActiveSkills = new SkillIcons();
                //TODO: (SpaceOgre) This is not used atm, so no need to run it.
                foreach (var obj in inTree.skillSprites)
                {
                    if (obj.Key.Contains("inactive"))
                    {
                        continue;
                    }
                    _IconInActiveSkills.Images[obj.Value[3].filename] = null;
                    foreach (var o in obj.Value[3].coords)
                    {
                        _IconInActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] =
                            new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h),
                                                            obj.Value[3].filename);
                    }
                }
            }

            if (!_Initialized)
            {
                SkillTree._IconActiveSkills = new SkillIcons();
                foreach (var obj in inTree.skillSprites)
                {
                    if (obj.Key.Contains("active"))
                    {
                        continue;
                    }
                    _IconActiveSkills.Images[obj.Value[3].filename] = null;
                    foreach (var o in obj.Value[3].coords)
                    {
                        _IconActiveSkills.SkillPositions[o.Key + "_" + o.Value.w] =
                            new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h),
                                                            obj.Value[3].filename);
                    }
                }
            }

            if (!_Initialized)
            {
                foreach (var ass in inTree.assets)
                {
                    _assets[ass.Key] = new Asset(ass.Key,
                                                 ass.Value.ContainsKey(0.3835f) ? ass.Value[0.3835f] : ass.Value.Values.First());
                }
            }

            if (!_Initialized)
            {
                _rootNodeList = new List <int>();
                if (inTree.root != null)
                {
                    foreach (int i in inTree.root.ot)
                    {
                        _rootNodeList.Add(i);
                    }
                }
                else if (inTree.main != null)
                {
                    foreach (int i in inTree.main.ot)
                    {
                        _rootNodeList.Add(i);
                    }
                }
            }

            if (displayProgress)
            {
                update(50, 100);
            }

            if (!_Initialized)
            {
                _IconActiveSkills.OpenOrDownloadImages(update);
            }

            if (displayProgress)
            {
                update(75, 100);
            }

            if (!_Initialized)
            {
                _IconInActiveSkills.OpenOrDownloadImages(update);
            }


            if (!_Initialized)
            {
                _CharBaseAttributes = new Dictionary <string, float> [7];
                foreach (var c in inTree.characterData)
                {
                    _CharBaseAttributes[c.Key] = new Dictionary <string, float>
                    {
                        { "+# to Strength", c.Value.base_str },
                        { "+# to Dexterity", c.Value.base_dex },
                        { "+# to Intelligence", c.Value.base_int }
                    };
                }
            }



            if (!_Initialized)
            {
                _Skillnodes = new Dictionary <ushort, SkillNode>();
                foreach (Node nd in inTree.nodes)
                {
                    _Skillnodes.Add(nd.id, new SkillNode
                    {
                        Id         = nd.id,
                        Name       = nd.dn,
                        attributes = nd.sd,
                        Orbit      = nd.o,
                        OrbitIndex = nd.oidx,
                        Icon       = nd.icon,
                        LinkId     = nd.ot,
                        G          = nd.g,
                        Da         = nd.da,
                        Ia         = nd.ia,
                        IsKeyStone = nd.ks,
                        IsNotable  = nd.not,
                        Sa         = nd.sa,
                        IsMastery  = nd.m,
                        Spc        = nd.spc.Count() > 0 ? (int?)nd.spc[0] : null
                    });
                    if (_rootNodeList.Contains(nd.id))
                    {
                        _rootNodeClassDictionary.Add(nd.dn.ToString().ToUpper(), nd.id);
                        foreach (int linkedNode in nd.ot)
                        {
                            _startNodeDictionary.Add(linkedNode, nd.id);
                        }
                    }
                    foreach (int node in nd.ot)
                    {
                        if (!_startNodeDictionary.ContainsKey(nd.id) && _rootNodeList.Contains(node))
                        {
                            _startNodeDictionary.Add(nd.id, node);
                        }
                    }
                }


                foreach (var skillNode in Skillnodes)
                {
                    foreach (ushort i in skillNode.Value.LinkId)
                    {
                        if (
                            _links.Count(nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) ==
                            1)
                        {
                            continue;
                        }
                        _links.Add(new[] { skillNode.Key, i });
                    }
                }
                foreach (var ints in _links)
                {
                    if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]]))
                    {
                        Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]);
                    }
                    if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]]))
                    {
                        Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]);
                    }
                }
            }



            if (!_Initialized)
            {
                _NodeGroups = new List <SkillNodeGroup>();
                foreach (var gp in inTree.groups)
                {
                    var ng = new SkillNodeGroup();

                    ng.OcpOrb   = gp.Value.oo;
                    ng.Position = new Vector2D(gp.Value.x, gp.Value.y);
                    foreach (ushort node in gp.Value.n)
                    {
                        ng.Nodes.Add(Skillnodes[node]);
                    }
                    NodeGroups.Add(ng);
                }
                foreach (SkillNodeGroup group in NodeGroups)
                {
                    foreach (SkillNode node in group.Nodes)
                    {
                        node.SkillNodeGroup = group;
                    }
                }
            }

            if (!_Initialized)
            {
                _TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1),
                                    new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1));
            }


            InitNodeSurround();//

            DrawNodeSurround();
            DrawNodeBaseSurround();
            InitSkillIconLayers();
            DrawSkillIconLayer();
            DrawBackgroundLayer();
            InitFaceBrushesAndLayer();
            DrawLinkBackgroundLayer(_links);
            InitOtherDynamicLayers();
            CreateCombineVisual();

            if (_links != null)
            {
                var regexAttrib = new Regex("[0-9]*\\.?[0-9]+");
                foreach (var skillNode in Skillnodes)
                {
                    skillNode.Value.Attributes = new Dictionary <string, List <float> >();
                    foreach (string s in skillNode.Value.attributes)
                    {
                        var values = new List <float>();

                        foreach (Match m in regexAttrib.Matches(s))
                        {
                            if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#")))
                            {
                                AttributeTypes.Add(regexAttrib.Replace(s, "#"));
                            }
                            if (m.Value == "")
                            {
                                values.Add(float.NaN);
                            }
                            else
                            {
                                values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture));
                            }
                        }
                        string cs = (regexAttrib.Replace(s, "#"));

                        skillNode.Value.Attributes[cs] = values;
                    }
                }
            }
            if (displayProgress)
            {
                update(100, 100);
            }

            _Initialized = true;
        }
Beispiel #2
0
        private async Task LoadUser(string token)
        {
            var client             = new HttpClient();
            var httpRequestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri("https://kwikwink-lab.fr/api/auth/user"),
                Headers    =
                {
                    { HttpRequestHeader.Accept.ToString(),        "application/json" },
                    { HttpRequestHeader.Authorization.ToString(), "Bearer " + token  }
                }
            };

            var response = client.SendAsync(httpRequestMessage).Result;

            Console.WriteLine(response.StatusCode);

            if (response.IsSuccessStatusCode)
            {
                string myloguser = await response.Content.ReadAsStringAsync();

                user        = JsonConvert.DeserializeObject <User>(myloguser);
                App.user_id = user.id;
                Title       = user.first_name + " " + user.last_name;
            }


            //brubrubruh

            /*var httpNodesRequestMessage = new HttpRequestMessage
             * {
             *  Method = HttpMethod.Get,
             *  RequestUri = new Uri("https://kwikwink-lab.fr/api/users/me/gateways"),
             *  Headers = {
             *          { HttpRequestHeader.Accept.ToString(), "application/json" },
             *          { HttpRequestHeader.Authorization.ToString(), "Bearer " + access_token }
             *  }
             * };
             * var NodesResponse = client.SendAsync(httpNodesRequestMessage).Result;
             *
             * Console.WriteLine("body response " + await NodesResponse.Content.ReadAsStringAsync());
             */

            string NodesResponse = "{\"data\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"bruh\",\"user\":\"76f62a58-5404-486d-9afc-07bded328704\",\"connected\":true,\"is_streaming\":true,\"address\":\"somewhere\",\"zipcode\":\"string\",\"city\":\"Dij city\",\"permissions\":[\"string\"],\"nodes\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"Passerelle Test\",\"permissions\":[\"string\"],\"devices\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"type\":\"lock\",\"state\":\"unlock\",\"battery\":0},{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f09\",\"type\":\"door_sensor\",\"state\":\"open\",\"battery\":60}]},{\"id\":\"507f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"George la passerelle\",\"permissions\":[\"string\"],\"devices\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6faa\",\"type\":\"lock\",\"state\":\"lock\",\"battery\":0},{\"id\":\"49'f6eca-6276-4993-bfeb-53ccbbba6f09\",\"type\":\"door_sensor\",\"state\":\"close\",\"battery\":60}]}],\"created_at\":\"2019-08-24T14:15:22Z\",\"updated_at\":\"2019-08-24T14:15:22Z\"},{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"Le Bureau\",\"user\":\"76f62a58-5404-486d-9afc-07bded328704\",\"connected\":true,\"is_streaming\":true,\"address\":\"somewhere\",\"zipcode\":\"string\",\"city\":\"Dij city\",\"permissions\":[\"string\"],\"nodes\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"Passerelle Test\",\"permissions\":[\"string\"],\"devices\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f08\",\"type\":\"lock\",\"state\":\"unlock\",\"battery\":0},{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6f09\",\"type\":\"door_sensor\",\"state\":\"open\",\"battery\":60}]},{\"id\":\"507f6eca-6276-4993-bfeb-53cbbbba6f08\",\"name\":\"George la passerelle\",\"permissions\":[\"string\"],\"devices\":[{\"id\":\"497f6eca-6276-4993-bfeb-53cbbbba6faa\",\"type\":\"lock\",\"state\":\"lock\",\"battery\":0},{\"id\":\"49'f6eca-6276-4993-bfeb-53ccbbba6f09\",\"type\":\"door_sensor\",\"state\":\"close\",\"battery\":60}]}],\"created_at\":\"2019-08-24T14:15:22Z\",\"updated_at\":\"2019-08-24T14:15:22Z\"}]}";

            gateways = JsonConvert.DeserializeObject <Gateways>(NodesResponse);


            foreach (Gateway gtw in gateways.data)
            {
                List <NodeEntityWrapper> tmp = new List <NodeEntityWrapper>();
                Console.WriteLine($"gateway id => {gtw.name}");
                foreach (Node nd in gtw.nodes)
                {
                    Console.WriteLine($"node id => {nd.name}");
                    Nodes.Add(nd);
                    tmp.Add(new NodeEntityWrapper(nd));
                }
                NodeGroups.Add(new Grouping <Gateway, NodeEntityWrapper>(gtw, tmp));
            }
        }