public InGameEditorCameraViewModel(IInGameEditorCameraSizeInViewService cameraSizeInViewService,
                                           Transform mapTransform,
                                           CameraConfig config,
                                           ITilesPositionService tilesPositionService,
                                           ICameraGetRepository getCameraRepository)
        {
            _cameraSizeInViewService = cameraSizeInViewService;
            _mapTransform            = mapTransform;
            _config = config;

            var mapPosition = mapTransform.position;

            _minCameraY = _config.MinDistanceToMap + mapPosition.y;

            CameraPositionLiveData = new LiveData <Vector3>();
            CameraLiveData         = new LiveData <Camera>();


            /*
             * we are trying to avoid having a whole bunch of setting and getting service/repo for the camera
             * but if more class need this thing we will need to refactor
             */
            _cameraYPositionSubject = new Subject <float>();
            _disposable             = new CompositeDisposable
            {
                _cameraYPositionSubject.Subscribe(OnZoomingLevelUpdated),
                getCameraRepository.GetObservableStream().Subscribe(CameraLiveData.PostValue),
                tilesPositionService
                .GetObservableStream(mapPosition.y)
                .CombineLatest(_cameraYPositionSubject, (positions, _) => positions)     //update bounds whenever the camera's height is updated
                .Subscribe(CalculateCameraRelatedMetrics)
            };
        }
Ejemplo n.º 2
0
        public GridOverlayViewModel(ICoordinateService coordinateService,
                                    IWorldConfigRepository loadedWorldConfigRepository,
                                    IMapConfigRepository mapConfigRepository,
                                    ITilesPositionService tilesPositionService,
                                    Transform centerTransform)
        {
            CoordinateVisibilityLiveData = new LiveData <bool>(true);
            GridVisibilityLiveData       = new LiveData <bool>(true);
            CellsCountLiveData           = new LiveData <int>();
            CellsPositionLiveData        = new LiveData <IReadOnlyList <Vector3> >();
            WorldConfigLiveData          = new LiveData <WorldConfig>();
            CoordinatesLiveData          = new LiveData <IReadOnlyList <Coordinate> >();

            _compositeDisposable = new CompositeDisposable
            {
                mapConfigRepository.GetObservableStream()
                .CombineLatest(
                    loadedWorldConfigRepository.GetObservableStream(),
                    tilesPositionService.GetObservableStream(centerTransform.position.y),
                    (mapConfig, worldConfig, positions) => (mapConfig, worldConfig, positions)
                    )
                .Subscribe(
                    tuple =>
                {
                    var(mapConfig, worldConfig, positions) = tuple;
                    var coordinates = coordinateService.GetFlattenCoordinates(mapConfig);

                    UpdateCellsCountsWhenNeeded(coordinates.Count);
                    UpdateCellsPositionWhenNeeded(positions);
                    UpdateWorldConfigWhenNeeded(worldConfig);
                    UpdateCoordinatesWhenNeeded(coordinates);
                }
                    )
            };
        }
Ejemplo n.º 3
0
 public LoadBoardItemsHolderService(ITilesPositionService tilesPositionService,
                                    IBoardItemsGetRepository <TBoardItem> boardItemsRepository,
                                    IGameObjectAndComponentFactory <THolder> holderFactory,
                                    ICoordinateService coordinateService)
 {
     _tilesPositionService       = tilesPositionService;
     _boardItemsRepository       = boardItemsRepository;
     _holderFactory              = holderFactory;
     _coordinateService          = coordinateService;
     _finishedLoadingEventStream = new ReplaySubject <Unit>(1);
 }