public IObservable <UniRx.Unit> Run() { IUnitData[] unitDatas = _unitSpawnSettings.GetUnits(_data.unitCommandData.UnitType); if (_data.unitCommandData.UnitIndex >= unitDatas.Length) { string errorMsg = string.Format("Unit Index not in unit datas range: {0}", _data.unitCommandData.UnitIndex); _logger.LogError(LoggedFeature.Units, errorMsg); return(Observable.Throw <UniRx.Unit>(new IndexOutOfRangeException(errorMsg))); } IUnitData unitData = unitDatas[(int)_data.unitCommandData.UnitIndex]; // First, spawn the pets recursively. // We create commands that we execute directly, because // we don't want to treat these as standalone commands (they are only ever children of this command) IUnit[] pets = new IUnit[_data.unitCommandData.pets.Length]; for (var i = 0; i < _data.unitCommandData.pets.Length; i++) { SpawnUnitData petSpawnUnitData = new SpawnUnitData(_data.unitCommandData.pets[i], _data.tileCoords, _data.isInitialSpawn); ICommand petSpawnCommand = _commandFactory.Create(typeof(SpawnUnitCommand), typeof(SpawnUnitData), petSpawnUnitData); petSpawnCommand.Run(); pets[i] = _unitRegistry.GetUnit(_data.unitCommandData.pets[i].unitId); } // Now, spawn the unit itself. IUnit unit = _unitPool.Spawn(_data.unitCommandData.unitId, unitData, pets); _gridUnitManager.PlaceUnitAtTile(unit, _data.tileCoords); _logger.Log(LoggedFeature.Units, "Spawned: {0}. Id: {1}", unitData.Name, unit.UnitId); return(Observable.ReturnUnit()); }
private void Update() { if (_lock == null && _isShown && !_inputLock.IsLocked) { _logger.Log(LoggedFeature.Network, "ModalViewController acquiring input lock."); _lock = _inputLock.Lock(); } }
private void HandleSaveButtonPressed() { if (_mapDataStore.Commit(_mapStoreId)) { _logger.Log(LoggedFeature.MapEditor, "Successfully saved map data."); } else { _logger.LogError(LoggedFeature.MapEditor, "Error saving map data."); } }
private void CommitUnitMovement(IUnit unit, IntVector2 moveDistance) { if (moveDistance == IntVector2.Zero) { _logger.Log(LoggedFeature.Units, "MoveDistance is 0. Will not commit command."); return; } _commandQueue.Enqueue <MoveUnitCommand, MoveUnitData>(new MoveUnitData(unit.UnitId, moveDistance), CommandSource.Game); }
protected override void Reinitialize(IntVector2 tileCoords, Sprite sprite, string label, MapElementTileRenderer item) { if (_spawnedRenderers.ContainsKey(tileCoords)) { _logger.Log(LoggedFeature.MapEditor, "Spawning map element renderer already in tile"); Despawn(_spawnedRenderers[tileCoords]); } item.Initialize(tileCoords, sprite, label); _spawnedRenderers[tileCoords] = item; }
public Vector2?GetLocalPosition(Vector2 worldPosition) { IntVector2?tileCoords = _gridPositionCalculator.GetTileContainingWorldPosition(worldPosition); if (tileCoords == null) { _logger.Log(LoggedFeature.Drawing, "TileCoords not found for world position: {0}", worldPosition); return(null); } IntVector2 bottomLeftTileCoords = GetBottomLeftGridTileCoords(tileCoords.Value); Vector2 tileOrigin = _gridPositionCalculator.GetTileOriginWorldPosition(bottomLeftTileCoords); return(worldPosition - tileOrigin); }
private async void HandleBatchSelectPressed() { using (_inputLock.Lock()) { Show(); // See essay above. ShowCancelButton(); CancellableTaskResult <IUnit[]> taskResult = await _batchUnitSelectionDetector .GetSelectedUnitsObservable() .ToButtonCancellableTask(_cancelButton); if (!taskResult.isCanceled) { _logger.Log(LoggedFeature.Units, "Selected {0} Units", taskResult.result.ToString()); Hide(); await _batchUnitMenuViewController.ShowAndWaitForAction(taskResult.result); Show(); } ShowToolbar(); } }
public CommandHistorySaveInfo SaveCommandHistory(string name) { CreateReplaysDirectoryIfNecessary(); string savePath = Path.Combine(Application.persistentDataPath, _settings.savePath, name); int duplicateIndex = 1; while (File.Exists(savePath)) { savePath = Path.Combine(Application.persistentDataPath, _settings.savePath, string.Format(_settings.duplicateFormat, name, duplicateIndex)); duplicateIndex++; } BinaryFormatter binaryFormatter = new BinaryFormatter(); using (FileStream fileStream = File.Open(savePath, FileMode.OpenOrCreate)) { binaryFormatter.Serialize(fileStream, _serializableCommandHistory); } _logger.Log(LoggedFeature.Replays, "Successfully saved replay to: {0}", savePath); return(new CommandHistorySaveInfo(Path.GetFileName(savePath))); }