public Previewer(IReadOnlyReactiveProperty <IReport> report) { Report = report; Pages = Report.CombineLatest( MediaSizeSelector.SelectedSize, (r, pageSize) => r.Paginate(pageSize) ) .ToReadOnlyReactiveProperty(); // 印刷ボタンが押されたら印刷する。 printCommand.Subscribe(_ => Print()); }
public Robot(RobotTemplate template, Game game) { _template = template; _game = game; MemorySize = MemoryUpgrades .Select(upgradesCount => template.InitialMemorySize + upgradesCount * template.MemoryUpgradeSize) .ToReactiveProperty(); Programs = new ReactiveCollection <Program>(); ProgramBytes = Programs.ObserveCountChanged(true) .SelectMany(_ => Programs .Select(x => x.MemorySize) .CombineLatest() .Select(y => y.Sum())) .ToReactiveProperty(initialValue: 0); TotalUsedBytes = ProgramBytes.CombineLatest(LeakedBytes, ProducedBytes, (programs, leaked, produced) => programs + leaked + produced) .ToReactiveProperty(); FreeSpace = TotalUsedBytes.CombineLatest(MemorySize, (used, memory) => memory - used) .ToReactiveProperty(); Status = Programs.ObserveCountChanged(true).CombineLatest(FreeSpace, (programCount, freeSpace) => freeSpace <= 0 ? RobotStatus.OutOfMemory : programCount == 0 ? RobotStatus.BootError : RobotStatus.Ok) .ToReactiveProperty(); HasSyncProgram = Programs.ObserveCountChanged(true) .Select(_ => Programs.Any(x => x.Template.Type == ProgramType.Sync)) .ToReactiveProperty(); //TODO: stop sync on game over Observable.CombineLatest(HasSyncProgram, Status.Select(x => x == RobotStatus.OutOfMemory), (hasSync, outOfMemory) => hasSync && !outOfMemory) .DistinctUntilChanged() .Select(shouldSync => shouldSync ? Observable.Interval(TimeSpan.FromSeconds(10)) : Observable.Empty <long>()) .Switch() .Subscribe(_ => { _game.GameProgress.DataCollected.Value += ProducedBytes.Value; ProducedBytes.Value = 0; }); }