private void UpdatePresence() { if (_elapsedCount <= 10) { _elapsedCount++; return; } SteamRichPresence presence; switch (_appId) { case SteamAppId.TF2: presence = new TF2RichPresence(_steamId, new Assets { LargeImageKey = _imageKey, LargeImageText = _imageText }); break; case SteamAppId.Unturned: presence = new UnturnedRichPresence(_steamId, new Assets { LargeImageKey = _imageKey, LargeImageText = _imageText }); break; default: presence = new DefaultRichPresence(); break; } var updated = false; if (/*presence.State != default && */ SteamRichPresence.LastPresence?.State != presence.State) { StateUpdated?.Invoke(presence.State); updated = true; } if (/*presence.Details != default && */ SteamRichPresence.LastPresence?.Details != presence.Details) { DetailsUpdated?.Invoke(presence.Details); updated = true; } if (/*presence.Party != default && */ presence.Party?.Size != SteamRichPresence.LastPresence?.Party?.Size) { PartyUpdated?.Invoke(presence.Party); updated = true; } if (/*presence.Timestamps?.Start != default && */ presence.Timestamps?.Start != SteamRichPresence.LastPresence?.Timestamps?.Start) { TimestampsUpdated?.Invoke(presence.Timestamps); updated = true; } if (presence.Assets?.LargeImageKey != SteamRichPresence.LastPresence?.Assets?.LargeImageKey || presence.Assets?.SmallImageKey != SteamRichPresence.LastPresence?.Assets?.SmallImageKey) { AssetsUpdated?.Invoke(presence.Assets); updated = true; } if (updated) { SteamRichPresence.LastPresence = presence; } }
public LeagueEvents(PykeAPI leagueAPI) { this.leagueAPI = leagueAPI; _GameflowStateChanged += (s, e) => { try { var state = StateChanged.ParseState(e.Data.ToString()); leagueAPI.logger.Verbose("Invoked GameflowStateChanged: " + state.ToString(), JsonSettings); GameflowStateChanged?.Invoke(s, state); } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking GameflowStateChanged Event.\n" + ex.ToString()); } }; _MatchFoundStatusChanged += (s, e) => { try { leagueAPI.logger.Verbose("Invoked OnMatchFound"); ReadyState state = JsonConvert.DeserializeObject <ReadyState>(e.Data.ToString(), JsonSettings); if (state != null) { OnReadyStateChanged?.Invoke(s, state); } } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking MatchFoundStatusChanged Event.\n" + ex.ToString()); } }; _SelectedChampionChanged += (s, e) => { try { var champ = leagueAPI.Champions.FirstOrDefault(t => t.Key == long.Parse(e.Data.ToString())); if (champ == null) { return; } leagueAPI.logger.Verbose("Invoked SelectedChampionChanged with Champion: " + champ.Name); SelectedChampionChanged?.Invoke(s, champ); } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking SelectedChampionChanged Event.\n" + ex.ToString()); } }; _ChampionTradeRecieved += (s, e) => { try { leagueAPI.logger.Verbose("Invoked ChampionTradesUpdated"); ChampionTradesUpdated?.Invoke(s, JsonConvert.DeserializeObject <List <Trade> >(e.Data.ToString(), JsonSettings)); } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking ChampionTradeRecieved Event.\n" + ex.ToString()); } }; _OnSessionUpdated += (s, e) => { try { var session = JsonConvert.DeserializeObject <Session>(e.Data.ToString(), JsonSettings); leagueAPI.logger.Verbose("Invoked OnSessionUpdated"); OnSessionUpdated?.Invoke(s, session); CheckOnChampSelect(s, session); CheckOtherUpdatedChamp(s, session); oldSession = session; } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking OnSessionUpdated Event.\n" + ex.ToString()); leagueAPI.logger.Debug(" ----------------- DEBUG DATA -------------"); leagueAPI.logger.Debug(e.Data.ToString()); leagueAPI.logger.Debug("----------------- END DEBUG DATA -------------"); } }; _MatchMakingUpdated += (s, e) => { try { QueueInfo _info = JsonConvert.DeserializeObject <QueueInfo>(e.Data.ToString(), JsonSettings); MatchmakingUpdated?.Invoke(this, _info); } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking MatchMakingUpdated Event.\n" + ex.ToString()); } }; _PartyUpdated += (s, e) => { try { if (e == null) { return; } Party _party = JsonConvert.DeserializeObject <Party>(e.Data.ToString(), JsonSettings); if (_party == null) { return; } PartyUpdated?.Invoke(this, _party); } catch (Exception ex) { leagueAPI.logger.Error("An exception occured while invoking PartyUpdated Event.\n" + ex.ToString()); } }; }