Пример #1
0
        public UnitViewModel(UnitConfig config, UnitModel model, ResourcePackViewModel resources)
        {
            Assert.IsNotNull(config, nameof(config));
            Assert.IsNotNull(model, nameof(model));
            Assert.IsNotNull(resources, nameof(resources));

            _config       = config;
            _model        = model;
            _resources    = resources;
            _sprite       = new ReactiveProperty <Sprite>();
            Sprite        = _sprite.ToReadOnlyReactiveProperty();
            _level        = new ReactiveProperty <int>(_model.Level);
            Level         = _level.ToReadOnlyReactiveProperty();
            Income        = new ResourceViewModel(model.Income);
            _upgradePrice = new ReactiveProperty <ResourceViewModel>(GetUpgradePrice());
            UpgradePrice  = _upgradePrice.ToReadOnlyReactiveProperty();
            _canUpgrade   = new ReactiveProperty <bool>(IsUpgradeAvailable());
            CanUpgrade    = _canUpgrade.ToReadOnlyReactiveProperty();
            foreach (var resource in resources.Resources)
            {
                resource.Value.Amount
                .Select(_ => IsUpgradeAvailable())
                .Subscribe(isAvailable => _canUpgrade.Value = isAvailable);
            }

            Level
            .Do(l => _model.Level = l)
            .Subscribe(OnLevelUpdated);
        }
Пример #2
0
 GameViewModel(GameConfig config, GameModel model)
 {
     _config   = config;
     Model     = model;
     Time      = new TimeProvider();
     Resources = new ResourcePackViewModel(model.Resources);
     Units     = new ReactiveCollection <UnitViewModel>(model.Units.Select(CreateViewModel));
 }