void init_visible(){
		if (obs_visible == null){
			init_status();
			init_parent();
			obs_visible = obs_parent.SelectMany((parent)=>{
				if (parent == null)
					return Observable.Return<bool>(true);
				parent.init_visible();
				return parent.obs_visible;
			}).CombineLatest(obs_status, (bool p_visible, VisibilityStatus stat)=>{
				if (stat == VisibilityStatus.AlwaysVisible) return true;
				if (stat == VisibilityStatus.NeverVisible) return false;
				return p_visible;
			}).ToReadOnlyReactiveProperty();
			obs_visible.DistinctUntilChanged().Subscribe(update);
		};
	}
Esempio n. 2
0
    public TournamentRunner()
    {
        SceneLoader instance = SceneLoader.Instance;

        Singleton <PropertyManager> .Instance.AddRootContext(this);

        PFIDsUsed.Add("D1E872B9C9DA0648");
        LoggedInPlayfab = (from id in PersistentSingleton <PlayFabService> .Instance.LoggedOnPlayerId.StartWith(string.Empty)
                           select id != string.Empty).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        TimeTillTournament      = TickerService.MasterTicksSlow.CombineLatest(ServerTimeService.IsSynced, (long tick, bool sync) => (!sync) ? (-1) : GetTimeTillTournament()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        TimeTillTournamentClock = (from time in TimeTillTournament.DistinctUntilChanged()
                                   select(time <= 0) ? string.Empty : TextUtils.FormatSecondsShortWithDays(time)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        (from till in TimeTillTournament
         where till == 0
         select till).Subscribe(delegate
        {
            ResetIfDifferentDevice();
        }).AddTo(instance);
        TournamentAccessable  = TimeTillTournament.CombineLatest(PlayerData.Instance.TournamentIdCurrent, TournamentFetched, ConnectivityService.InternetConnectionAvailable, (long time, int id, bool fetched, bool connected) => connected && time == 0 && id < 0 && fetched).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        CurrentlyInTournament = (from id in PlayerData.Instance.TournamentIdCurrent
                                 select id >= 0 && CheckIfSameDevice()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        (from should in TournamentFetched.CombineLatest(TimeTillTournament, FetchAttempt, LoggedInPlayfab, (bool fetched, long till, int attempt, bool loggedIn) => !fetched && attempt == 0 && till == 0)
         where should
         select should).Subscribe(delegate
        {
            TryToFetchTournament();
        }).AddTo(instance);
        (from timestamp in PlayerData.Instance.TournamentTimeStamp
         where timestamp + 10000000L * (long)PersistentSingleton <GameSettings> .Instance.TournamentDurationSeconds >= ServerTimeService.NowTicks() && ServerTimeService.NowTicks() >= timestamp && CheckIfSameDevice()
         select timestamp).Subscribe(delegate
        {
            TournamentRuns.SetValueAndForceNotify(LoadTournamentRuns());
            TournamentActive.SetValueAndForceNotify(value: true);
        }).AddTo(instance);
        TimeTillTournamentEnd = (from should in TickerService.MasterTicks.CombineLatest(ServerTimeService.IsSynced, PlayerData.Instance.TournamentIdCurrent, (long tick, bool sync, int id) => sync && id >= 0 && CheckIfSameDevice())
                                 where should
                                 select should into _
                                 select GetTimeTillTournamentEnd()).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        TournamentEndClock = (from time in TimeTillTournamentEnd.DistinctUntilChanged()
                              select(time <= 0) ? string.Empty : TextUtils.FormatSecondsShort(time)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        TournamentEnded = TimeTillTournamentEnd.CombineLatest(PlayerData.Instance.TournamentIdCurrent, (long time, int id) => time < 0 && id >= 0).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        (from ended in TournamentEnded
         where ended
         select ended).Subscribe(delegate
        {
            LoadTournamentEndedValues();
        }).AddTo(instance);
        TournamentWorldReached = (from world in PlayerData.Instance.MainChunk
                                  select world >= 70).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        DisplayNameGiven = (from name in PlayerData.Instance.DisplayName
                            select name != string.Empty).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        TournamentsUnlocked = PlayerData.Instance.LifetimePrestiges.CombineLatest(PlayerData.Instance.LifetimeChunk, (int prest, int chunk) => prest > 0 || chunk >= 45).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
        (from unlocked in TournamentsUnlocked.Pairwise()
         where !unlocked.Previous && unlocked.Current
         select unlocked).Subscribe(delegate
        {
            BindingManager.Instance.TournamentUnlockedParent.ShowInfo();
        }).AddTo(instance);
        PlayerData.Instance.Medals.Take(1).Subscribe(delegate
        {
            TryToBuyTrophy(showUnlocking: false);
        }).AddTo(instance);
        PlayerData.Instance.Trophies.Subscribe(delegate(int trophies)
        {
            CalculateTrophiesMultiplier(trophies);
        }).AddTo(instance);
        InternetConnectionAvailable = (from avail in ConnectivityService.InternetConnectionAvailable
                                       select(avail)).TakeUntilDestroy(instance).ToReadOnlyReactiveProperty();
    }