Example #1
0
    void Awake()
    {
        //PlayerPrefs.DeleteAll(); // erase save
        //SteamUserStats.ResetAllStats(true); // erase all achievements
        //PlayerPrefs.SetInt("PlayerProgress", 61); // unluck all levels

        if (instance != null && instance != this)
        {
            Destroy(gameObject);
            return;
        }
        else
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }

        //debug only
        debugForSteam = true;

        script = this;
        if (!SteamManager.Initialized)
        {
            gameObject.SetActive(false);
        }
    }
    // Use this for initialization
    void Start()
    {
        if (instance != null)
        {
            Destroy(this.gameObject);
        }

        instance = this;
        GameObject.DontDestroyOnLoad(gameObject);

        if (AppId == 0)
        {
            throw new System.Exception("You need to set the AppId to your game");
        }

        Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

        try {
            System.IO.File.WriteAllText("steam_appid.txt", AppId.ToString());
        } catch (System.Exception e) {
            Debug.LogWarning("Couldn't write steam_appid.txt: " + e.Message);
        }

        // Create the client
        client = new Facepunch.Steamworks.Client(AppId);

        if (!client.IsValid)
        {
            client = null;
            Debug.LogWarning("Couldn't initialize Steam");
            return;
        }
        Debug.Log("Steam Initialized: " + client.Username + " / " + client.SteamId);
    }
Example #3
0
 public void RicochetCheck(int combo)
 {
     if (combo >= 6 && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_RICOCHET");
     }
 }
Example #4
0
    public void FollowCheckUnlock(int score)
    {
        // Score of at least 20,000
        if (!ReadWriteSaveManager.Instance.GetData("UnlockedFollow", false))
        {
            if (score >= 20000)
            {
                ReadWriteSaveManager.Instance.SetData("UnlockedFollow", true, true);
                if (steamBuild)
                {
                    SteamAchievements.UnlockAchievement("FOLLOW_UNLOCK");
                }
            }
        }

        // Score of at least 50,000
        if (score >= 50000 && steamBuild)
        {
            SteamAchievements.UnlockAchievement("TRI_MASTER");
        }

        // Score of at least 100,000
        if (score >= 100000 && steamBuild)
        {
            SteamAchievements.UnlockAchievement("TRI_LEGEND");
        }
    }
Example #5
0
 public void StackedCheck(int comboScore)
 {
     if (comboScore >= 3000 && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_STACKED");
     }
 }
Example #6
0
 public void HomingCheck(int combo)
 {
     if (combo >= 8 && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_HOMING");
     }
 }
Example #7
0
 public void GiantCheck(float checkSizeX, float currentSizeX)
 {
     if (currentSizeX >= checkSizeX && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_GIANT");
     }
 }
Example #8
0
 public void HeaveCheck(int combo)
 {
     if (combo >= 5 && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_HEAVE");
     }
 }
Example #9
0
 public void SpreadCheck(int hitTris)
 {
     if (hitTris >= 3 && steamBuild)
     {
         SteamAchievements.UnlockAchievement("TRI_SPREAD");
     }
 }
Example #10
0
    public void TripleCheckUnlock()
    {
        int setGames = ReadWriteSaveManager.Instance.GetData("GameCompletions", 0) + 1;

        ReadWriteSaveManager.Instance.SetData("GameCompletions", setGames, true);
        int games = ReadWriteSaveManager.Instance.GetData("GameCompletions", 0);

        // Play 3 games to the end
        if (!ReadWriteSaveManager.Instance.GetData("UnlockedTriple", false))
        {
            if (games > 3)
            {
                ReadWriteSaveManager.Instance.SetData("UnlockedTriple", true, true);
                if (steamBuild)
                {
                    SteamAchievements.UnlockAchievement("TRIPLE_UNLOCK");
                }
            }
        }

        // Play 50 games to the end
        if (games > 50 && steamBuild)
        {
            SteamAchievements.UnlockAchievement("TRI_ADDICT");
        }

        // Play 100 games to the end
        if (games > 100 && steamBuild)
        {
            SteamAchievements.UnlockAchievement("TRI_FOREVER");
        }
    }
Example #11
0
 private void Awake()
 {
     script = this;
     if (!SteamManager.Initialized)
     {
         gameObject.SetActive(false);
         return;
     }
 }
Example #12
0
 public void BounceCheckUnlock(bool homing, bool shooting, bool sitting, bool dashing)
 {
     // Defeat each enemy type in one shot
     if (!ReadWriteSaveManager.Instance.GetData("UnlockedBounce", false))
     {
         if (homing && shooting && sitting && dashing)
         {
             ReadWriteSaveManager.Instance.SetData("UnlockedBounce", true, true);
             if (steamBuild)
             {
                 SteamAchievements.UnlockAchievement("BOUNCE_UNLOCK");
             }
         }
     }
 }
Example #13
0
 public void SpongeCheckUnlock(int combo)
 {
     // Get an 8-enemy combo
     if (!ReadWriteSaveManager.Instance.GetData("UnlockedSponge", false))
     {
         if (combo >= 6)
         {
             ReadWriteSaveManager.Instance.SetData("UnlockedSponge", true, true);
             if (steamBuild)
             {
                 SteamAchievements.UnlockAchievement("SPONGE_UNLOCK");
             }
         }
     }
 }
        public GameAchievements GetManual(Game game)
        {
            GameAchievements gameAchievements = GetDefault(game);

            SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);

            steamAPI.SetLocal();
            gameAchievements          = steamAPI.GetAchievements(game);
            gameAchievements.IsManual = true;

            Add(gameAchievements);

#if DEBUG
            logger.Debug($"{PluginName} [Ignored] - GetManual({game.Id.ToString()}) - gameAchievements: {JsonConvert.SerializeObject(gameAchievements)}");
#endif

            return(gameAchievements);
        }
Example #15
0
    public void Start()
    {
        //QualitySettings.vSyncCount = 0;  // VSync must be disabled
        //Application.targetFrameRate = 200; // test

        buttonRightSound   = Resources.Load <AudioClip>("Sound/Sound_Effects/Button_Click/coin_22");
        levelCompleteSound = Resources.Load <AudioClip>("Sound/Sound_Effects/power_up_18");
        starsRevealed      = Resources.Load <AudioClip>("Sound/Sound_Effects/star_3");

        starSounds = new List <AudioClip>
        {
            Resources.Load <AudioClip>("Sound/Sound_Effects/star_1"),
            Resources.Load <AudioClip>("Sound/Sound_Effects/star_2")
        };

        animationWonPrefab = Resources.Load <GameObject>("Prefabs/GameWonEffect");
        StartCoroutine(ShowButtonsToPlay());

        GameObject soundObject = GameObject.Find("SoundController");
        GameObject menuObject  = GameObject.Find("Canvas");

        if (!soundObject.activeSelf)
        {
            soundObject.SetActive(true);
        }

        if (menuObject != null)
        {
            menu = menuObject.GetComponent <Menu>();
        }

        soundController = soundObject.GetComponent <SoundController>();

        steamAchievements = GameObject.Find("SteamAchievements");

        if (steamAchievements != null)
        {
            scriptAchievments = steamAchievements.GetComponent <SteamAchievements>();
        }

        soundController.LoadGameVolume();
        getButtonsInvisible();
        getButtonsTeleport();
    }
Example #16
0
 public void RapidCheckUnlock()
 {
     // Unlock all other tris
     if (!ReadWriteSaveManager.Instance.GetData("UnlockedRapid", false))
     {
         bool triple = ReadWriteSaveManager.Instance.GetData("UnlockedTriple", false);
         bool follow = ReadWriteSaveManager.Instance.GetData("UnlockedFollow", false);
         bool sponge = ReadWriteSaveManager.Instance.GetData("UnlockedSponge", false);
         bool bounce = ReadWriteSaveManager.Instance.GetData("UnlockedBounce", false);
         if (triple && follow && sponge && bounce)
         {
             ReadWriteSaveManager.Instance.SetData("UnlockedRapid", true, true);
             if (steamBuild)
             {
                 SteamAchievements.UnlockAchievement("RAPID_UNLOCK");
             }
         }
     }
 }
Example #17
0
    // Use this for initialization
    void Start()
    {
        if (instance != null)
        {
            Destroy(this.gameObject);
        }

        steamAch          = GetComponentInParent <SteamAchievements>();
        totalRoundsPlayed = PlayerPrefs.GetInt("rounds", 0);
        intercepts        = PlayerPrefs.GetInt("intercepts", 0);

        playedCherry  = PlayerPrefs.GetInt("cherry", 0) == 1;
        playedCity    = PlayerPrefs.GetInt("city", 0) == 1;
        playedTron    = PlayerPrefs.GetInt("tron", 0) == 1;
        playedIceberg = PlayerPrefs.GetInt("iceberg", 0) == 1;
        playedSpace   = PlayerPrefs.GetInt("space", 0) == 1;

        instance = this;
    }
Example #18
0
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="game"></param>
        public GameAchievements GetFromWeb(Game game)
        {
            GameAchievements gameAchievements = GetDefault(game);

            Guid   GameId         = game.Id;
            Guid   GameSourceId   = game.SourceId;
            string GameSourceName = PlayniteTools.GetSourceName(_PlayniteApi, game);

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, PluginSettings, PluginUserDataPath, GameSourceName))
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - OK");
#endif

                // TODO one func
                if (GameSourceName.ToLower() == "gog")
                {
                    if (gogAPI == null)
                    {
                        gogAPI = new GogAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = gogAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "steam")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "origin")
                {
                    if (originAPI == null)
                    {
                        originAPI = new OriginAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = originAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "xbox")
                {
                    if (xboxAPI == null)
                    {
                        xboxAPI = new XboxAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    }
                    gameAchievements = xboxAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked")
                {
                    SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    steamAPI.SetLocal();
                    gameAchievements = steamAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "retroachievements")
                {
                    RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = retroAchievementsAPI.GetAchievements(game);
                }

                if (GameSourceName.ToLower() == "rpcs3")
                {
                    Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(_PlayniteApi, PluginSettings, PluginUserDataPath);
                    gameAchievements = rpcs3Achievements.GetAchievements(game);
                }

#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - Achievements for {game.Name} - {GameSourceName} - {JsonConvert.SerializeObject(gameAchievements)}");
#endif
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShow({game.Name}, {GameSourceName}) - KO");
#endif
            }

            return(gameAchievements);
        }
Example #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="GameSourceName"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static bool VerifToAddOrShow(SuccessStory plugin, IPlayniteAPI PlayniteApi, SuccessStorySettings settings, string PluginUserDataPath, string GameSourceName)
        {
            if (settings.EnableSteam && GameSourceName.ToLower() == "steam")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("SteamLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Steam is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Steam-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    SteamAchievements steamAchievements = new SteamAchievements(PlayniteApi, settings, PluginUserDataPath);
                    if (!steamAchievements.IsConfigured())
                    {
                        logger.Warn("SuccessStory - Bad Steam configuration");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Steam-NoConfig",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsSteamBadConfig")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableGog && GameSourceName.ToLower() == "gog")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("GogLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - GOG is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-GOG-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    GogAchievements gogAchievements = new GogAchievements(PlayniteApi, settings, PluginUserDataPath);

                    if (VerifToAddOrShowGog == null)
                    {
                        VerifToAddOrShowGog = gogAchievements.IsConnected();
                    }

                    if (!(bool)VerifToAddOrShowGog)
                    {
                        logger.Warn("SuccessStory - Gog user is not authenticate");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Gog-NoAuthenticated",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogNoAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableOrigin && GameSourceName.ToLower() == "origin")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("OriginLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Origin is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Origin-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    OriginAchievements originAchievements = new OriginAchievements(PlayniteApi, settings, PluginUserDataPath);

                    if (VerifToAddOrShowOrigin == null)
                    {
                        VerifToAddOrShowOrigin = originAchievements.IsConnected();
                    }

                    if (!(bool)VerifToAddOrShowOrigin)
                    {
                        logger.Warn("SuccessStory - Origin user is not authenticated");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Origin-NoAuthenticate",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsOriginNoAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableXbox && GameSourceName.ToLower() == "xbox")
            {
                if (PlayniteTools.IsDisabledPlaynitePlugins("XboxLibrary", PlayniteApi.Paths.ConfigurationPath))
                {
                    logger.Warn("SuccessStory - Xbox is enable then disabled");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Xbox-disabled",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxDisabled")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                else
                {
                    XboxAchievements xboxAchievements = new XboxAchievements(PlayniteApi, settings, PluginUserDataPath);

#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}");
#endif
                    if (VerifToAddOrShowXbox == null)
                    {
                        VerifToAddOrShowXbox = xboxAchievements.IsConnected();
                    }
#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - VerifToAddOrShowXbox: {VerifToAddOrShowXbox}");
#endif

                    if (!(bool)VerifToAddOrShowXbox)
                    {
                        logger.Warn("SuccessStory - Xbox user is not authenticated");
                        PlayniteApi.Notifications.Add(new NotificationMessage(
                                                          "SuccessStory-Xbox-NoAuthenticate",
                                                          $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsXboxNotAuthenticate")}",
                                                          NotificationType.Error,
                                                          () => plugin.OpenSettingsView()
                                                          ));
                        return(false);
                    }
                }
                return(true);
            }

            if (settings.EnableLocal && (GameSourceName.ToLower() == "playnite" || GameSourceName.ToLower() == "hacked"))
            {
                return(true);
            }

            if (settings.EnableRetroAchievements && GameSourceName.ToLower() == "retroachievements")
            {
                RetroAchievements retroAchievements = new RetroAchievements(PlayniteApi, settings, PluginUserDataPath);
                if (!retroAchievements.IsConfigured())
                {
                    logger.Warn("SuccessStory - Bad RetroAchievements configuration");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-RetroAchievements-NoConfig",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRetroAchievementsBadConfig")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                return(true);
            }

            if (settings.EnableRpcs3Achievements && GameSourceName.ToLower() == "rpcs3")
            {
                Rpcs3Achievements rpcs3Achievements = new Rpcs3Achievements(PlayniteApi, settings, PluginUserDataPath);
                if (!rpcs3Achievements.IsConfigured())
                {
                    logger.Warn("SuccessStory - Bad RPCS3 configuration");
                    PlayniteApi.Notifications.Add(new NotificationMessage(
                                                      "SuccessStory-Rpcs3-NoConfig",
                                                      $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsRpcs3BadConfig")}",
                                                      NotificationType.Error,
                                                      () => plugin.OpenSettingsView()
                                                      ));
                    return(false);
                }
                return(true);
            }

            logger.Warn($"SuccessStory - VerifToAddOrShow() find no action for {GameSourceName}");
            return(false);
        }
Example #20
0
    public IEnumerator GoToLevel(Level level, bool fromCongrats = false)
    {
        if (gameCamera.isInTransition)
        {
            yield break;
        }

        var prevLevel = activeLevel;

        activeLevel = level;

        history.Clear();

        if (activeLevel == null)
        {
            screenFade.SetColor(prevLevel.cameraParams.backgroundColor);
            screenFade.FadeIn();

            yield return(new WaitWhile(() => screenFade.fadeOut == true));

            yield return(new WaitForSeconds(0.5f));

            cityMapGameObject.SetActive(true);
            prevLevel.gameObject.SetActive(false);

            gameCamera.MoveImmediate(gameCamera.cameraCityInbetweenTransform);
            gameCamera.StartMoving(gameCamera.cameraCityTransform, null);

            screenFade.FadeOut();

            musicManager.SetTrack(0, true);

            yield return(new WaitWhile(() => screenFade.fadeOut == false));

            if (prevLevel.buttonString == "35" && !gameData.IsSolvedCompletely())
            {
                yield return(new WaitWhile(() => gameCamera.isInTransition == true));

                phoneUI.animatorComponent.SetTrigger("Show");
                phoneUI.isShowing = true;

                yield return(new WaitWhile(() => phoneUI.isShowing == true));

                yield return(new WaitForSeconds(1.0f));

#if !DISABLESTEAMWORKS
                if (SteamManager.Initialized)
                {
                    SteamAchievements.UnlockSteamAchievement("ACHIEVEMENT_04");
                }
#endif
            }
            else if (gameData.IsSolvedCompletely() && fromCongrats)
            {
                yield return(new WaitWhile(() => gameCamera.isInTransition == true));

                Debug.Log("Game Completed!!!");

                if (System.String.IsNullOrEmpty(gameData.date))
                {
                    gameData.date = System.DateTime.Now.ToString("dd.MM.yyyy");
                    Save();
                }

                certificateUI.animatorComponent.SetTrigger("Show");
                certificateUI.dateText.text = gameData.date;
                certificateUI.isShowing     = true;

                yield return(new WaitWhile(() => certificateUI.isShowing == true));

                yield return(new WaitForSeconds(1.0f));

#if !DISABLESTEAMWORKS
                if (SteamManager.Initialized)
                {
                    SteamAchievements.UnlockSteamAchievement("ACHIEVEMENT_05");
                }
#endif
            }
            else
            {
                yield return(new WaitForSeconds(0.5f));

#if !DISABLESTEAMWORKS
                if (SteamManager.Initialized)
                {
                    if (gameData.IsSolvedLevelsForGettingSmarterAchievement())
                    {
                        SteamAchievements.UnlockSteamAchievement("ACHIEVEMENT_01");
                    }
                    if (gameData.IsSolvedLevelsForHalfwayToSuccessAchievement())
                    {
                        SteamAchievements.UnlockSteamAchievement("ACHIEVEMENT_02");
                    }
                    if (gameData.IsSolvedLevelsForUrbanistAchievement())
                    {
                        SteamAchievements.UnlockSteamAchievement("ACHIEVEMENT_03");
                    }
                }
#endif
            }

            cityUI.animatorComponent.SetTrigger("Show");
        }
        else
        {
            levelUI.UpdateText(activeLevel.goldMedalThreshold, history.Count);
            levelUI.UpdateLevelInfo(activeLevel.levelName, activeLevel.buttonString);

            var room = activeLevel.room;
            if (room == null)
            {
                Debug.Log("Room is null");
                yield break;
            }
            room.ResetRoom();
            activeLevel.MovablesToStart();

            screenFade.SetColor(activeLevel.cameraParams.backgroundColor);
            screenFade.FadeIn();

            gameCamera.StartMoving(activeLevel.cameraParams, null, true);

            yield return(new WaitWhile(() => screenFade.fadeOut == true));

            cityMapGameObject.SetActive(false);
            activeLevel.gameObject.SetActive(true);

            yield return(new WaitWhile(() => gameCamera.isInTransition == true));

            screenFade.FadeOut();

            musicManager.SetTrack(activeLevel.trackIndex, true);

            yield return(new WaitWhile(() => screenFade.fadeOut == false));

            levelUI.animatorComponent.SetTrigger("Show");

            activeLevel.StartTimer();
        }
    }
Example #21
0
        private void RefreshData(string SourceName, bool IsGet = false)
        {
            SuccessStoryDatabase.ListErrors = new CumulErrors();

#if DEBUG
            logger.Info($"SuccessStory [Ignored] - RefreshData() - Start");
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
#endif

            SuccessStorySettings.IsEnabled = false;

            pbDataLoad.IsIndeterminate = false;
            pbDataLoad.Minimum         = 0;
            pbDataLoad.Value           = 0;

            DataLoad.Visibility   = Visibility.Visible;
            tcSettings.Visibility = Visibility.Hidden;

            tokenSource = new CancellationTokenSource();
            ct          = tokenSource.Token;

            bool IsFirstLoop = true;

            var taskSystem = Task.Run(() =>
            {
                try
                {
                    // filter games
                    IEnumerable <Game> FilterDatabaseGame = null;
                    switch (SourceName.ToLower())
                    {
                    case "all":
                        FilterDatabaseGame = _PlayniteApi.Database.Games;
                        break;

                    case "allrecent":
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(
                            x => x.LastActivity > DateTime.Now.AddMonths(-2) || (x.Added != null && x.Added > DateTime.Now.AddMonths(-2))
                            );
                        break;

                    case "allinstalled":
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(x => x.IsInstalled);
                        break;

                    default:
                        FilterDatabaseGame = _PlayniteApi.Database.Games.Where(
                            x => PlayniteTools.GetSourceName(_PlayniteApi, x).ToLower() == SourceName.ToLower()
                            );
                        break;
                    }

                    Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Maximum = FilterDatabaseGame.Count(); });
#if DEBUG
                    logger.Debug($"SuccessStory [Ignored] - FilterDatabaseGame: {FilterDatabaseGame.Count()}");
#endif
                    foreach (var game in FilterDatabaseGame)
                    {
                        try
                        {
                            if (SourceName.ToLower() == "steam" && IsFirstLoop)
                            {
#if DEBUG
                                logger.Debug($"SuccessStory [Ignored] - Check Steam profil with {game.GameId}");
#endif

                                SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, PluginDatabase.PluginSettings, _PluginUserDataPath);
                                int AppId = 0;
                                int.TryParse(game.GameId, out AppId);
                                if (!steamAPI.CheckIsPublic(AppId))
                                {
                                    SuccessStoryDatabase.ListErrors.Add(resources.GetString("LOCSuccessStoryNotificationsSteamPrivate"));
                                    break;
                                }
                                IsFirstLoop = false;
                            }

                            // Respect API limitation
                            Thread.Sleep(1000);

                            if (IsGet)
                            {
                                // Add only it's not loaded
                                if (!PluginDatabase.VerifAchievementsLoad(game.Id))
                                {
                                    PluginDatabase.Get(game);
                                }
                            }
                            else
                            {
                                PluginDatabase.Remove(game);
                                PluginDatabase.Get(game);
                            }

                            Application.Current.Dispatcher.BeginInvoke((Action) delegate { pbDataLoad.Value += 1; });
                        }
                        catch (Exception ex)
                        {
                            Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet}) for {game.Name}");
                        }

                        if (ct.IsCancellationRequested)
                        {
                            logger.Info($"IsCancellationRequested for RefreshData({ SourceName}, { IsGet})");
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "SuccessStory", $"Error on RefreshData({SourceName}, {IsGet})");
                }
            }, tokenSource.Token)
                             .ContinueWith(antecedent =>
            {
                Application.Current.Dispatcher.BeginInvoke((Action) delegate
                {
                    DataLoad.Visibility   = Visibility.Collapsed;
                    tcSettings.Visibility = Visibility.Visible;

                    if (!WithoutMessage)
                    {
                        if (SuccessStoryDatabase.ListErrors.Get() != string.Empty)
                        {
                            _PlayniteApi.Dialogs.ShowErrorMessage(SuccessStoryDatabase.ListErrors.Get(), "SuccessStory errors");
                        }
                        else
                        {
                            _PlayniteApi.Dialogs.ShowMessage((string)ResourceProvider.GetResource("LOCSuccessStoryRefreshDataMessage"), "Success Story");
                        }
                    }

                    SetTotal();

                    SuccessStorySettings.IsEnabled = true;
#if DEBUG
                    stopwatch.Stop();
                    logger.Debug($"SuccessStory [Ignored] - RefreshData() - End - {stopwatch.Elapsed}");
#endif
                });
            });
        }
Example #22
0
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="GameAdded"></param>
        public void Add(Game GameAdded, SuccessStorySettings settings)
        {
            GameAchievements GameAchievements = new GameAchievements();

            Guid   GameId         = GameAdded.Id;
            Guid   GameSourceId   = GameAdded.SourceId;
            string GameSourceName = "";

            if (GameSourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
            {
                GameSourceName = GameAdded.Source.Name;
            }
            else
            {
                GameSourceName = "Playnite";
            }

            string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json";

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(GameSourceName, settings))
            {
                // Generate only not exist
                if (!File.Exists(PluginDatabaseGamePath))
                {
                    // TODO one func
                    if (GameSourceName.ToLower() == "gog")
                    {
                        if (gogAPI == null)
                        {
                            gogAPI = new GogAchievements(PlayniteApi);
                        }
                        GameAchievements = gogAPI.GetAchievements(PlayniteApi, GameId);
                    }

                    if (GameSourceName.ToLower() == "steam")
                    {
                        SteamAchievements steamAPI = new SteamAchievements();
                        GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath);
                    }

                    if (GameSourceName.ToLower() == "origin")
                    {
                        if (originAPI == null)
                        {
                            originAPI = new OriginAchievements(PlayniteApi);
                        }
                        GameAchievements = originAPI.GetAchievements(PlayniteApi, GameId);
                    }

                    if (GameSourceName.ToLower() == "playnite")
                    {
                        SteamAchievements steamAPI = new SteamAchievements();
                        GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath, settings.EnableLocal);
                    }

                    File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements));
                }
            }
        }
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="GameAdded"></param>
        public void Add(Game GameAdded, SuccessStorySettings settings)
        {
            GameAchievements GameAchievements = new GameAchievements();

            Guid   GameId                 = GameAdded.Id;
            Guid   GameSourceId           = GameAdded.SourceId;
            string GameSourceName         = PlayniteTools.GetSourceName(GameAdded, _PlayniteApi);
            string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json";

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(_plugin, _PlayniteApi, GameSourceName, settings, _PluginUserDataPath))
            {
                // Generate only not exist
                if (!File.Exists(PluginDatabaseGamePath))
                {
#if DEBUG
                    logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - OK");
#endif

                    // TODO one func
                    if (GameSourceName.ToLower() == "gog")
                    {
                        if (gogAPI == null)
                        {
                            gogAPI = new GogAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = gogAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "steam")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "origin")
                    {
                        if (originAPI == null)
                        {
                            originAPI = new OriginAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = originAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "xbox")
                    {
                        if (xboxAPI == null)
                        {
                            xboxAPI = new XboxAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        }
                        GameAchievements = xboxAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "playnite")
                    {
                        SteamAchievements steamAPI = new SteamAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        steamAPI.SetLocal();
                        GameAchievements = steamAPI.GetAchievements(GameAdded);
                    }

                    if (GameSourceName.ToLower() == "retroachievements")
                    {
                        RetroAchievements retroAchievementsAPI = new RetroAchievements(_PlayniteApi, settings, _PluginUserDataPath);
                        GameAchievements = retroAchievementsAPI.GetAchievements(GameAdded);
                    }

#if DEBUG
                    logger.Debug($"SuccessStory - Achievements for {GameAdded.Name} - {GameSourceName} - {JsonConvert.SerializeObject(GameAchievements)}");
#endif

                    if (GameAchievements != null)
                    {
                        File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements));
                    }
                }
            }
            else
            {
#if DEBUG
                logger.Debug($"SuccessStory - VerifToAddOrShow({GameAdded.Name}, {GameSourceName}) - KO");
#endif
            }
        }
        /// <summary>
        /// Generate database achivements for the game if achievement exist and game not exist in database.
        /// </summary>
        /// <param name="GameAdded"></param>
        public void Add(Game GameAdded, SuccessStorySettings settings)
        {
            GameAchievements GameAchievements = new GameAchievements();

            Guid   GameId         = GameAdded.Id;
            Guid   GameSourceId   = GameAdded.SourceId;
            string GameSourceName = "";

            List <Guid> ListEmulators = new List <Guid>();

            foreach (var item in PlayniteApi.Database.Emulators)
            {
                ListEmulators.Add(item.Id);
            }

            if (GameSourceId != Guid.Parse("00000000-0000-0000-0000-000000000000"))
            {
                GameSourceName = GameAdded.Source.Name;

                if (GameAdded.PlayAction != null && GameAdded.PlayAction.EmulatorId != null && ListEmulators.Contains(GameAdded.PlayAction.EmulatorId))
                {
                    GameSourceName = "RetroAchievements";
                }
            }
            else
            {
                if (GameAdded.PlayAction != null && GameAdded.PlayAction.EmulatorId != null && ListEmulators.Contains(GameAdded.PlayAction.EmulatorId))
                {
                    GameSourceName = "RetroAchievements";
                }
                else
                {
                    GameSourceName = "Playnite";
                }
            }


            string PluginDatabaseGamePath = PluginDatabasePath + GameId.ToString() + ".json";

            List <Achievements> Achievements = new List <Achievements>();

            // Generate database only this source
            if (VerifToAddOrShow(GameSourceName, settings, PluginUserDataPath))
            {
                // Generate only not exist
                if (!File.Exists(PluginDatabaseGamePath))
                {
                    // TODO one func
                    if (GameSourceName.ToLower() == "gog")
                    {
                        if (gogAPI == null)
                        {
                            gogAPI = new GogAchievements(PlayniteApi);
                        }
                        GameAchievements = gogAPI.GetAchievements(PlayniteApi, GameId);
                    }

                    if (GameSourceName.ToLower() == "steam")
                    {
                        SteamAchievements steamAPI = new SteamAchievements();
                        GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath);
                    }

                    if (GameSourceName.ToLower() == "origin")
                    {
                        if (originAPI == null)
                        {
                            originAPI = new OriginAchievements(PlayniteApi);
                        }
                        GameAchievements = originAPI.GetAchievements(PlayniteApi, GameId);
                    }

                    if (GameSourceName.ToLower() == "playnite")
                    {
                        SteamAchievements steamAPI = new SteamAchievements();
                        GameAchievements = steamAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath, settings.EnableLocal);
                    }

                    if (GameSourceName.ToLower() == "retroachievements")
                    {
                        RetroAchievements retroAchievementsAPI = new RetroAchievements(settings);
                        GameAchievements = retroAchievementsAPI.GetAchievements(PlayniteApi, GameId, PluginUserDataPath);
                    }

                    if (GameAchievements != null)
                    {
                        File.WriteAllText(PluginDatabaseGamePath, JsonConvert.SerializeObject(GameAchievements));
                    }
                }
            }
        }