Exemple #1
0
        private void HandlePreviousSectionButtonCLicked()
        {
            if (_inputLock.IsLocked)
            {
                return;
            }

            var commandData = new LoadMapSectionCommandData(_mapSectionContext.CurrentSectionIndex - 1, _loadMapCommandData);

            _commandQueue.Enqueue <LoadMapSectionCommand, LoadMapSectionCommandData>(commandData, CommandSource.Game);
        }
        public IObservable <Unit> Run()
        {
            IUnit unit = _unitRegistry.GetUnit(_data.unitId);

            if (unit == null)
            {
                _logger.LogError(LoggedFeature.Units,
                                 "MoveUnitSectionCommand called on unit not in registry: {0}",
                                 _data.unitId);
                return(Observable.Empty <Unit>());
            }

            uint?unitIndex = _unitDataIndexResolver.ResolveUnitIndex(unit.UnitData);

            if (unitIndex == null)
            {
                _logger.LogError(LoggedFeature.Units,
                                 "Failed to resolve unit index: {0}",
                                 _data.unitId);
                return(Observable.Empty <Unit>());
            }

            _despawnCommand =
                _commandFactory.Create <DespawnUnitCommand, DespawnUnitData>(new DespawnUnitData(_data.unitId));
            _despawnCommand.Run();

            var sectionLoadedSubject = new Subject <Unit>();
            var commandData          =
                new LoadMapSectionCommandData(_data.toSectionIndex, new LoadMapCommandData(_mapStoreId.index));
            ICommand loadMapSectionCommand =
                _commandFactory.Create <LoadMapSectionCommand, LoadMapSectionCommandData>(commandData);

            loadMapSectionCommand.Run().Subscribe(_ => {
                // We need to wait 1 frame in order to avoid race conditions between listeners on new section
                Observable.IntervalFrame(1).First().Subscribe(__ => {
                    IntVector2 entryTileCoords =
                        _entryTileFinder.GetEntryTile(_data.toSectionIndex, _data.fromSectionIndex);
                    // We don't spawn pets (which also are not despawn on despawn command)
                    var unitCommandData = new UnitCommandData(unit.UnitId, unitIndex.Value, unit.UnitData.UnitType);
                    var spawnUnitData   = new SpawnUnitData(unitCommandData, entryTileCoords, isInitialSpawn: false);
                    _spawnCommand       = _commandFactory.Create <SpawnUnitCommand, SpawnUnitData>(spawnUnitData);
                    _spawnCommand.Run();

                    sectionLoadedSubject.OnNext(Unit.Default);
                });
            });

            return(sectionLoadedSubject);
        }
        private void HandleMapSceneLoaded(DiContainer container, IMutableMapData mapData, MapStoreId mapStoreId)
        {
            // MapSection command may inject mutable map data if on editor mode.
            container.Bind <IMapData>().FromInstance(mapData);
            container.Bind <MapStoreId>().FromInstance(mapStoreId);
            container.Bind <IMutableMapData>().FromInstance(mapData).WhenInjectedInto <LoadMapSectionCommand>();
            container.Bind <LoadMapCommandData>().FromInstance(_data);

            // This needs to happen after 1 frame because we are currently still loading the next scene.
            // Otherwise, the dependency graph cannot be yet built.
            Observable.NextFrame().Subscribe(onNext => {
                // This needs to be created directly since the section command is dependant on this command.
                LoadMapSectionCommandData loadMapSectionCommandData = new LoadMapSectionCommandData(0, _data);
                ICommand loadMapSectionCommand = _commandFactory.Create(typeof(LoadMapSectionCommand),
                                                                        typeof(LoadMapSectionCommandData),
                                                                        loadMapSectionCommandData);
                loadMapSectionCommand.Run().Subscribe(next => {
                    _modalViewController.Hide();
                    _sceneLoadedSubject.OnNext(Unit.Default);
                });
            });
        }