예제 #1
0
        public override void Update()
        {
            if (url == null || readyToDelete)
            {
                readyToDelete = true;
                return;
            }

            if (string.IsNullOrEmpty(www.error))
            {
                if (www.isDone && ready)
                {
                    Log($"Fetching RainDB data... path [{url}]");
                    string        file = www.text;
                    List <object> json = file.listFromJson();

                    foreach (object jsonPack in json)
                    {
                        RegionPack regionPack = new RegionPack("");
                        //CustomWorldMod.Log($"Obtained data [{jsonPack.ToString()}]");
                        CustomWorldMod.FromDictionaryToPackInfo(jsonPack as Dictionary <string, object>, ref regionPack);
                        try
                        {
                            regionPack.activated = true;
                            //regionPack.activated = CustomWorldMod.installedRegionPacks.ContainsKey(regionPack.name);
                            CustomWorldMod.rainDbPacks.Add(regionPack.name, regionPack);
                        }
                        catch (Exception e) { Log($"Exception when adding fetched region [{e}]", true); }
                    }
                    // CustomWorldMod.rainDbPacks = CustomWorldMod.rainDbPacks.OrderBy(x => x.Value.activated == true);
                    //var sorted = from entry in CustomWorldMod.rainDbPacks orderby entry.Value.activated ascending select entry;
                    //CustomWorldMod.rainDbPacks = CustomWorldMod.rainDbPacks.OrderBy(x => x.Value.activated).ToDictionary(x => x.Key, x => x.Value);
                    Log($"Added fetched regions [{string.Join(", ", CustomWorldMod.rainDbPacks.Keys.ToArray())}]");
                    ready         = false;
                    readyToDelete = true;
                    CustomWorldMod.UpdateLocalPackWithOnline();
                    CustomWorldMod.LoadThumbnails();
                }
            }
            else
            {
                readyToDelete = true;
                Log(www.error, true);
                CustomWorldMod.OfflineMode = true;
                if (CustomWorldMod.OfflineMode)
                {
                    Log("RUNNING CUSTOM REGIONS IN OFFLINE MODE");
                    CustomWorldMod.LoadThumbnails();
                }
            }
        }
예제 #2
0
        public override void Update()
        {
            if (url == null || readyToDelete)
            {
                readyToDelete = true;
                return;
            }

            if (string.IsNullOrEmpty(www.error))
            {
                if (www.isDone && ready)
                {
                    Log($"Fetching RainDB data... path [{url}]");
                    string        file = www.text;
                    List <object> json;
                    try
                    {
                        json = file.listFromJson();

                        Dictionary <string, RegionPack> tempRainDb = new Dictionary <string, RegionPack>();
                        foreach (object jsonPack in json)
                        {
                            RegionPack regionPack = new RegionPack("");
                            //CustomWorldMod.Log($"Obtained data [{jsonPack.ToString()}]");
                            CustomWorldMod.FromDictionaryToPackInfo(jsonPack as Dictionary <string, object>, ref regionPack, authorative: true);
                            try
                            {
                                regionPack.activated = true;
                                //regionPack.activated = CustomWorldMod.installedRegionPacks.ContainsKey(regionPack.name);
                                tempRainDb.Add(regionPack.name, regionPack);
                            }
                            catch (Exception e) { Log($"Exception when adding fetched region [{e}]", true); }
                        }
                        var date    = DateTime.UtcNow.Date;
                        var seed    = date.Year * 1000 + date.DayOfYear;
                        var random1 = new System.Random(seed);

                        var seq = Enumerable.Range(0, tempRainDb.Count()).OrderBy(x => random1.Next()).Take(tempRainDb.Count()).ToList();
                        foreach (int item in seq)
                        {
                            KeyValuePair <string, RegionPack> tempItem = tempRainDb.ElementAt(item);
                            CustomWorldMod.rainDbPacks.Add(tempItem.Key, tempItem.Value);
                        }

                        Log($"Added fetched regions [{string.Join(", ", CustomWorldMod.rainDbPacks.Keys.ToArray())}]");
                    }
                    catch (Exception e)
                    {
                        Log("Error fetching regions " + e, true);
                    }
                    ready         = false;
                    readyToDelete = true;
                    CustomWorldMod.UpdateLocalPackWithOnline();
                    CustomWorldMod.LoadThumbnails();
                }
            }
            else
            {
                readyToDelete = true;
                Log(www.error, true);
                CustomWorldMod.OfflineMode = true;
                if (CustomWorldMod.OfflineMode)
                {
                    Log("RUNNING CUSTOM REGIONS IN OFFLINE MODE");
                    CustomWorldMod.LoadThumbnails();
                }
            }
        }