Esempio n. 1
0
        private void OnFavButtonClicked(StoredCategory storedCategory, string avatarId, bool disallowRecursiveRequests)
        {
            if (FavCatMod.Database.myStoredAvatars.FindById(avatarId) == null)
            {
                if (disallowRecursiveRequests)
                {
                    return;
                }

                // something showed an unknown avatar, request it before favoriting
                new ApiAvatar {
                    id = avatarId
                }.Fetch(new Action <ApiContainer>(_ =>
                {
                    MelonCoroutines.Start(ReFavAfterDelay(storedCategory, avatarId));
                }));
                return;
            }

            if (FavCatMod.Database.AvatarFavorites.IsFavorite(avatarId, storedCategory.CategoryName))
            {
                FavCatMod.Database.AvatarFavorites.DeleteFavorite(avatarId, storedCategory.CategoryName);
            }
            else
            {
                FavCatMod.Database.AvatarFavorites.AddFavorite(avatarId, storedCategory.CategoryName);
            }
        }
Esempio n. 2
0
        public void RenameCategory(StoredCategory category, string newName)
        {
            var oldName = category.CategoryName;

            myStoredCategories.Delete(oldName);
            foreach (var storedFavorite in myStoredFavorites.Find(it => it.Category == oldName))
            {
                storedFavorite.Category = newName;
                myStoredFavorites.Update(storedFavorite);
            }

            category.CategoryName = newName;
            myStoredCategories.Upsert(category);

            // no events fired
        }
Esempio n. 3
0
 protected abstract void OnFavButtonClicked(StoredCategory storedCategory);
Esempio n. 4
0
        protected override void OnFavButtonClicked(StoredCategory storedCategory)
        {
            ApiAvatar currentApiAvatar = myPageAvatar.field_Public_SimpleAvatarPedestal_0.field_Internal_ApiAvatar_0;

            OnFavButtonClicked(storedCategory, currentApiAvatar.id, false);
        }
Esempio n. 5
0
        private IEnumerator ReFavAfterDelay(StoredCategory category, string id)
        {
            yield return(new WaitForSeconds(0.25f));

            OnFavButtonClicked(category, id, true);
        }
Esempio n. 6
0
 public void DeleteCategory(StoredCategory category)
 {
     myStoredFavorites.DeleteMany(it => it.Category == category.CategoryName);
     myStoredCategories.Delete(category.CategoryName);
 }
Esempio n. 7
0
 public void UpdateCategory(StoredCategory category)
 {
     myStoredCategories.Upsert(category);
 }
Esempio n. 8
0
 protected override void OnFavButtonClicked(StoredCategory storedCategory)
 {
     // do nothing
 }
Esempio n. 9
0
        // might be re-used for worlds/players
        internal static async Task ProcessTextFile(string filePath)
        {
            var fileName = Path.GetFileName(filePath);

            MelonDebug.Msg($"Started avatar import process for file {fileName}");

            var toAdd = new List <string>();

            { // file access block
                using var file   = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                using var reader = new StreamReader(file);
                string line;

                while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                {
                    var matches = AvatarIdRegex.Matches(line);
                    foreach (Match match in matches)
                    {
                        var avatarId = match.Value;
                        toAdd.Add(avatarId);
                    }
                }
            }

            for (var i = 0; i < toAdd.Count; i++)
            {
                ImportStatusInner = $"Fetching avatar {i + 1}/{toAdd.Count}";
                var avatarId = toAdd[i];
                if (FavCatMod.Database.myStoredAvatars.FindById(avatarId) == null)
                {
                    await TaskUtilities.YieldToMainThread();

                    new ApiAvatar {
                        id = avatarId
                    }.Fetch();                             // it will get intercepted and stored
                    await Task.Delay(TimeSpan.FromSeconds(5f + Random.Range(0f, 5f))).ConfigureAwait(false);
                }
            }

            ImportStatusInner = "Creating favorites list";
            await TaskUtilities.YieldToMainThread();

            var userId           = APIUser.CurrentUser.id;
            var categoryName     = $"Imported from {fileName}";
            var existingCategory = FavCatMod.Database.AvatarFavorites.GetCategory(categoryName);

            foreach (var avatarId in toAdd)
            {
                if (FavCatMod.Database.AvatarFavorites.IsFavorite(avatarId, categoryName))
                {
                    continue;
                }

                var storedAvatar = FavCatMod.Database.myStoredAvatars.FindById(avatarId);
                if (storedAvatar == null || storedAvatar.ReleaseStatus != "public" && storedAvatar.AuthorId != userId)
                {
                    continue;
                }

                FavCatMod.Database.AvatarFavorites.AddFavorite(avatarId, categoryName);
            }

            if (existingCategory == null)
            {
                existingCategory = new StoredCategory {
                    CategoryName = categoryName, SortType = "!added"
                };
                FavCatMod.Database.AvatarFavorites.UpdateCategory(existingCategory);

                var avatarModule = FavCatMod.Instance.AvatarModule !;
                avatarModule.CreateList(existingCategory);
                avatarModule.ReorderLists();
                avatarModule.RefreshFavButtons();
            }

            MelonDebug.Msg($"Done importing {fileName}");
            File.Delete(filePath);
        }