// ------[ 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;
        }
Esempio n. 2
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;
        }