/// <summary>Submits changes to a mod to the server.</summary>
        public void SubmitModChanges(int modId, EditableModProfile modEdits)
        {
            Debug.Assert(modId != ModProfile.NULL_ID);

            this.eModProfile = modEdits;

            if (this.eModProfile.status.isDirty ||
                this.eModProfile.visibility.isDirty ||
                this.eModProfile.name.isDirty ||
                this.eModProfile.nameId.isDirty ||
                this.eModProfile.summary.isDirty ||
                this.eModProfile.descriptionAsHTML.isDirty ||
                this.eModProfile.homepageURL.isDirty ||
                this.eModProfile.metadataBlob.isDirty)
            {
                var parameters = new EditModParameters();
                if (this.eModProfile.status.isDirty)
                {
                    parameters.status = this.eModProfile.status.value;
                }
                if (this.eModProfile.visibility.isDirty)
                {
                    parameters.visibility = this.eModProfile.visibility.value;
                }
                if (this.eModProfile.name.isDirty)
                {
                    parameters.name = this.eModProfile.name.value;
                }
                if (this.eModProfile.nameId.isDirty)
                {
                    parameters.nameId = this.eModProfile.nameId.value;
                }
                if (this.eModProfile.summary.isDirty)
                {
                    parameters.summary = this.eModProfile.summary.value;
                }
                if (this.eModProfile.descriptionAsHTML.isDirty)
                {
                    parameters.descriptionAsHTML = this.eModProfile.descriptionAsHTML.value;
                }
                if (this.eModProfile.homepageURL.isDirty)
                {
                    parameters.homepageURL = this.eModProfile.homepageURL.value;
                }
                if (this.eModProfile.metadataBlob.isDirty)
                {
                    parameters.metadataBlob = this.eModProfile.metadataBlob.value;
                }

                APIClient.EditMod(modId, parameters, this.SubmitModChanges_Internal, this.onError);
            }
            // - Get updated ModProfile -
            else
            {
                ModManager.GetModProfile(modId, this.SubmitModChanges_Internal, this.onError);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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;
        }