Пример #1
0
        public static void FetchAllUserEvents(int fromTimeStamp,
                                              int untilTimeStamp,
                                              Action <List <UserEvent> > onSuccess,
                                              Action <WebRequestError> onError)
        {
            // - Filter -
            RequestFilter userEventFilter = new RequestFilter();

            userEventFilter.sortFieldName = GetUserEventsFilterFields.dateAdded;
            userEventFilter.fieldFilters[GetUserEventsFilterFields.dateAdded]
                = new RangeFilter <int>()
                {
                min            = fromTimeStamp,
                isMinInclusive = false,
                max            = untilTimeStamp,
                isMaxInclusive = true,
                };

            // - Get All Events -
            ModManager.FetchAllResultsForQuery <UserEvent>((p, s, e) => APIClient.GetUserEvents(userEventFilter, p, s, e),
                                                           onSuccess,
                                                           onError);
        }
        // ------[ INITIALIZATION ]------
        protected virtual void OnEnable()
        {
            buildProfile = new EditableModfile();
            buildProfile.version.value = "0.0.0";
            uploadSucceededMessage     = null;
            uploadFailedMessage        = null;

            string authToken = CacheClient.LoadAuthenticatedUserToken();

            if (!String.IsNullOrEmpty(authToken))
            {
                APIClient.userAuthorizationToken = authToken;

                ModManager.GetAuthenticatedUserProfile((userProfile) =>
                {
                    this.user = userProfile;
                    Repaint();
                },
                                                       null);
            }

            LoginWindow.userLoggedIn += OnUserLogin;
        }
Пример #3
0
        private Texture2D GetGalleryImageTexture(string imageFileName,
                                                 string imageSource)
        {
            if (String.IsNullOrEmpty(imageFileName))
            {
                return(null);
            }

            Texture2D texture;

            // - Get -
            if (this.textureCache.TryGetValue(imageFileName, out texture))
            {
                return(texture);
            }
            // - Load -
            else if ((texture = CacheClient.ReadImageFile(imageSource)) != null)
            {
                this.textureCache.Add(imageFileName, texture);
                return(texture);
            }
            // - LoadOrDownload -
            else if (profile != null)
            {
                this.textureCache.Add(imageFileName, ApplicationImages.LoadingPlaceholder);

                ModManager.GetModGalleryImage(profile,
                                              imageFileName,
                                              IMAGE_PREVIEW_SIZE,
                                              (t) => { this.textureCache[imageFileName] = t; isRepaintRequired = true; },
                                              null);
                return(this.textureCache[imageFileName]);
            }

            return(null);
        }
Пример #4
0
        public static void SubmitModChanges(int modId,
                                            EditableModProfile modEdits,
                                            Action <ModProfile> modSubmissionSucceeded,
                                            Action <WebRequestError> modSubmissionFailed)
        {
            Debug.Assert(modId > 0);

            Action <ModProfile> submitChanges = (profile) =>
            {
                if (modEdits.status.isDirty ||
                    modEdits.visibility.isDirty ||
                    modEdits.name.isDirty ||
                    modEdits.nameId.isDirty ||
                    modEdits.summary.isDirty ||
                    modEdits.description.isDirty ||
                    modEdits.homepageURL.isDirty ||
                    modEdits.metadataBlob.isDirty)
                {
                    var parameters = new EditModParameters();
                    if (modEdits.status.isDirty)
                    {
                        parameters.status = modEdits.status.value;
                    }
                    if (modEdits.visibility.isDirty)
                    {
                        parameters.visibility = modEdits.visibility.value;
                    }
                    if (modEdits.name.isDirty)
                    {
                        parameters.name = modEdits.name.value;
                    }
                    if (modEdits.nameId.isDirty)
                    {
                        parameters.nameId = modEdits.nameId.value;
                    }
                    if (modEdits.summary.isDirty)
                    {
                        parameters.summary = modEdits.summary.value;
                    }
                    if (modEdits.description.isDirty)
                    {
                        parameters.description = modEdits.description.value;
                    }
                    if (modEdits.homepageURL.isDirty)
                    {
                        parameters.homepageURL = modEdits.homepageURL.value;
                    }
                    if (modEdits.metadataBlob.isDirty)
                    {
                        parameters.metadataBlob = modEdits.metadataBlob.value;
                    }

                    APIClient.EditMod(modId, parameters,
                                      (p) => SubmitModProfileComponents(profile, modEdits,
                                                                        modSubmissionSucceeded,
                                                                        modSubmissionFailed),
                                      modSubmissionFailed);
                }
                // - Get updated ModProfile -
                else
                {
                    SubmitModProfileComponents(profile,
                                               modEdits,
                                               modSubmissionSucceeded,
                                               modSubmissionFailed);
                }
            };

            ModManager.GetModProfile(modId,
                                     submitChanges,
                                     modSubmissionFailed);
        }
Пример #5
0
        public static void ApplyModEventsToCache(IEnumerable <ModEvent> modEvents,
                                                 Action <List <ModProfile> > profilesAvailableCallback     = null,
                                                 Action <List <ModProfile> > profilesEditedCallback        = null,
                                                 Action <List <int> > profilesUnavailableCallback          = null,
                                                 Action <List <int> > profilesDeletedCallback              = null,
                                                 Action <List <ModfileStub> > profileBuildsUpdatedCallback = null,
                                                 Action onSuccess = null,
                                                 Action <WebRequestError> onError = null)
        {
            List <int> addedIds          = new List <int>();
            List <int> editedIds         = new List <int>();
            List <int> modfileChangedIds = new List <int>();
            List <int> removedIds        = new List <int>();
            List <int> deletedIds        = new List <int>();

            // Sort by event type
            foreach (ModEvent modEvent in modEvents)
            {
                switch (modEvent.eventType)
                {
                case ModEventType.ModAvailable:
                {
                    addedIds.Add(modEvent.modId);
                }
                break;

                case ModEventType.ModEdited:
                {
                    editedIds.Add(modEvent.modId);
                }
                break;

                case ModEventType.ModfileChanged:
                {
                    modfileChangedIds.Add(modEvent.modId);
                }
                break;

                case ModEventType.ModUnavailable:
                {
                    removedIds.Add(modEvent.modId);
                }
                break;

                case ModEventType.ModDeleted:
                {
                    deletedIds.Add(modEvent.modId);
                }
                break;
                }
            }

            // --- Process Add/Edit/ModfileChanged ---
            List <int> modsToFetch = new List <int>(addedIds.Count + editedIds.Count + modfileChangedIds.Count);

            modsToFetch.AddRange(addedIds);
            modsToFetch.AddRange(editedIds);
            modsToFetch.AddRange(modfileChangedIds);

            if (modsToFetch.Count > 0)
            {
                // - Filter & Pagination -
                RequestFilter modsFilter = new RequestFilter();
                modsFilter.fieldFilters[GetAllModsFilterFields.id]
                    = new InArrayFilter <int>()
                    {
                    filterArray = modsToFetch.ToArray(),
                    };
                // - Get Mods -
                Action <List <ModProfile> > onGetMods = (updatedProfiles) =>
                {
                    // - Create Update Lists -
                    List <ModProfile>  addedProfiles       = new List <ModProfile>(addedIds.Count);
                    List <ModProfile>  editedProfiles      = new List <ModProfile>(editedIds.Count);
                    List <ModfileStub> modfileChangedStubs = new List <ModfileStub>(modfileChangedIds.Count);

                    foreach (ModProfile profile in updatedProfiles)
                    {
                        int idIndex;
                        // NOTE(@jackson): If added, ignore everything else
                        if ((idIndex = addedIds.IndexOf(profile.id)) >= 0)
                        {
                            addedIds.RemoveAt(idIndex);
                            addedProfiles.Add(profile);
                        }
                        else
                        {
                            if ((idIndex = editedIds.IndexOf(profile.id)) >= 0)
                            {
                                editedIds.RemoveAt(idIndex);
                                editedProfiles.Add(profile);
                            }
                            if ((idIndex = modfileChangedIds.IndexOf(profile.id)) >= 0)
                            {
                                modfileChangedIds.RemoveAt(idIndex);
                                modfileChangedStubs.Add(profile.activeBuild);
                            }
                        }
                    }

                    // - Save changed to cache -
                    CacheClient.SaveModProfiles(updatedProfiles);

                    // --- Notifications ---
                    if (profilesAvailableCallback != null &&
                        addedProfiles.Count > 0)
                    {
                        profilesAvailableCallback(addedProfiles);
                    }

                    if (profilesEditedCallback != null &&
                        editedProfiles.Count > 0)
                    {
                        profilesEditedCallback(editedProfiles);
                    }

                    if (profileBuildsUpdatedCallback != null &&
                        modfileChangedStubs.Count > 0)
                    {
                        profileBuildsUpdatedCallback(modfileChangedStubs);
                    }
                };

                ModManager.FetchAllResultsForQuery <ModProfile>((p, s, e) => APIClient.GetAllMods(modsFilter, p, s, e),
                                                                onGetMods,
                                                                null);
            }

            // --- Process Removed ---
            if (removedIds.Count > 0)
            {
                // TODO(@jackson): Compare with subscriptions
                foreach (int modId in removedIds)
                {
                    CacheClient.DeleteMod(modId);
                }

                if (profilesUnavailableCallback != null)
                {
                    profilesUnavailableCallback(removedIds);
                }
            }

            if (deletedIds.Count > 0)
            {
                // TODO(@jackson): Check install state
                foreach (int modId in deletedIds)
                {
                    CacheClient.DeleteMod(modId);
                }

                if (profilesDeletedCallback != null)
                {
                    profilesDeletedCallback(deletedIds);
                }
            }
        }
        protected virtual void LayoutLogoField()
        {
            bool doBrowse = false;

            // - Browse Field -
            EditorGUILayout.BeginHorizontal();
            doBrowse |= EditorGUILayoutExtensions.BrowseButton(logoLocation,
                                                               new GUIContent("Logo"));
            bool isUndoRequested = EditorGUILayoutExtensions.UndoButton(isUndoEnabled);

            EditorGUILayout.EndHorizontal();

            // - Draw Texture -
            if (logoTexture != null)
            {
                Rect logoRect = EditorGUILayout.GetControlRect(false,
                                                               LOGO_PREVIEW_HEIGHT,
                                                               null);
                EditorGUI.DrawPreviewTexture(new Rect((logoRect.width - LOGO_PREVIEW_WIDTH) * 0.5f,
                                                      logoRect.y,
                                                      LOGO_PREVIEW_WIDTH,
                                                      logoRect.height),
                                             logoTexture,
                                             null,
                                             ScaleMode.ScaleAndCrop);
                doBrowse |= GUI.Button(logoRect, "", GUI.skin.label);
            }

            if (doBrowse)
            {
                EditorApplication.delayCall += () =>
                {
                    string path = EditorUtility.OpenFilePanelWithFilters("Select Mod Logo",
                                                                         "",
                                                                         IMAGE_FILE_FILTER);
                    Texture2D newLogoTexture = CacheClient.ReadImageFile(path);

                    if (newLogoTexture)
                    {
                        logoProperty.FindPropertyRelative("value.url").stringValue      = path;
                        logoProperty.FindPropertyRelative("value.fileName").stringValue = Path.GetFileName(path);
                        logoProperty.FindPropertyRelative("isDirty").boolValue          = true;
                        logoProperty.serializedObject.ApplyModifiedProperties();

                        logoTexture       = newLogoTexture;
                        logoLocation      = path;
                        lastLogoWriteTime = (new FileInfo(logoLocation)).LastWriteTime;
                    }
                };
            }

            if (isUndoRequested)
            {
                logoProperty.FindPropertyRelative("value.url").stringValue      = profile.logoLocator.GetURL();
                logoProperty.FindPropertyRelative("value.fileName").stringValue = profile.logoLocator.GetFileName();
                logoProperty.FindPropertyRelative("isDirty").boolValue          = false;

                logoLocation = profile.logoLocator.GetSizeURL(LOGO_PREVIEW_SIZE);
                logoTexture  = ApplicationImages.LoadingPlaceholder;

                ModManager.GetModLogo(profile, LOGO_PREVIEW_SIZE,
                                      (t) => { logoTexture = t; isRepaintRequired = true; },
                                      WebRequestError.LogAsWarning);
            }
        }
Пример #7
0
        // ------[ INITIALIZATION ]------
        protected virtual void OnEnable()
        {
            // Grab Serialized Properties
            serializedObject.Update();
            modIdProperty = serializedObject.FindProperty("modId");
            editableModProfileProperty = serializedObject.FindProperty("editableModProfile");
            isModListLoading           = false;
            profileViewParts           = new IModProfileViewPart[]
            {
                new LoadingProfileViewPart()
            };

            // Profile Initialization
            if (modIdProperty.intValue == ScriptableModProfile.UNINITIALIZED_MOD_ID)
            {
                this.profile = null;

                string userAuthToken = CacheClient.LoadAuthenticatedUserToken();

                if (!String.IsNullOrEmpty(userAuthToken))
                {
                    APIClient.userAuthorizationToken = userAuthToken;

                    this.isModListLoading = true;
                    this.modOptions       = new string[] { "Loading..." };

                    Action <WebRequestError> onError = (e) =>
                    {
                        WebRequestError.LogAsWarning(e);
                        isModListLoading = false;
                    };

                    ModManager.GetAuthenticatedUserProfile((userProfile) =>
                    {
                        this.user = userProfile;

                        // - Find User Mods -
                        Action <List <ModProfile> > onGetUserMods = (profiles) =>
                        {
                            modInitializationOptionIndex = 0;
                            modList    = profiles.ToArray();
                            modOptions = new string[modList.Length];
                            for (int i = 0; i < modList.Length; ++i)
                            {
                                ModProfile mod = modList[i];
                                modOptions[i]  = mod.name;
                            }

                            isModListLoading = false;
                        };

                        ModManager.GetAuthenticatedUserMods(onGetUserMods, onError);
                    },
                                                           onError);
                }
                else
                {
                    this.modOptions = new string[0];
                }

                modInitializationOptionIndex = 0;
            }
            else
            {
                // Initialize View
                profile = null;

                System.Action <ModProfile> onGetProfile = (p) =>
                {
                    profile = p;

                    profileViewParts = CreateProfileViewParts();

                    foreach (IModProfileViewPart viewPart in profileViewParts)
                    {
                        viewPart.OnEnable(editableModProfileProperty, p, this.user);
                    }
                    ;

                    profileGetErrorMessage = string.Empty;
                };

                System.Action <WebRequestError> onGetProfileError = (e) =>
                {
                    profile = null;

                    profileViewParts = CreateProfileViewParts();

                    foreach (IModProfileViewPart viewPart in profileViewParts)
                    {
                        viewPart.OnEnable(editableModProfileProperty, null, this.user);
                    }
                    ;

                    profileGetErrorMessage = ("Unable to fetch the mod profile data on the server.\n"
                                              + e.message);
                };

                ModManager.GetModProfile(modIdProperty.intValue,
                                         onGetProfile,
                                         onGetProfileError);
            }

            scrollPos        = Vector2.zero;
            isProfileSyncing = false;

            // Events
            EditorApplication.update += OnUpdate;
            LoginWindow.userLoggedIn += OnUserLogin;
        }