public void CellContentsChange(string name, string contents) { CellChange var = new CellChange(name, contents); undoStack.Push(var); redoStack.Clear(); }
public ICreature this[int x, int y] { get { return(field[x, y]); } set { field[x, y] = value; CellChange?.Invoke(x, y, value); } }
public bool TryRedo(Func <string, string> GetOldCellContents, out string name, out string newContents) { if (!CanRedo()) { name = null; newContents = null; return(false); } else { CellChange temp = redoStack.Pop(); undoStack.Push(new CellChange(temp.Name, GetOldCellContents(temp.Name))); name = temp.Name; newContents = temp.Contents; return(true); } }
public Level(string name) { Name = name; Map = new Map(File.ReadAllLines(GetFolderName() + "\\map.txt")); Map.CellChange += (x, y, creature) => CellChange?.Invoke(x, y, creature); Map.Die += (x, y, creature) => Die?.Invoke(x, y, creature); Map.Damaged += (x, y, creature, damage) => Damaged?.Invoke(x, y, creature, damage); Map.DoingStarted += (x, y, character, doing) => DoingStarted?.Invoke(x, y, character, doing); Map.DoingEnd += (x, y, character, doing) => DoingEnd?.Invoke(x, y, character, doing); Map.Die += (x, y, creature) => { if (creature is Base _base) { EndWin?.Invoke(!_base.IsPlayerCreature); IsEnd = true; } }; }
public Level(string name, Map map) { Name = name; Map = map; Map.CellChange += (x, y, creature) => CellChange?.Invoke(x, y, creature); Map.Die += (x, y, creature) => Die?.Invoke(x, y, creature); Map.Damaged += (x, y, creature, damage) => Damaged?.Invoke(x, y, creature, damage); Map.DoingStarted += (x, y, character, doing) => DoingStarted?.Invoke(x, y, character, doing); Map.DoingEnd += (x, y, character, doing) => DoingEnd?.Invoke(x, y, character, doing); Map.Die += (x, y, creature) => { if (creature is Base _base) { EndWin?.Invoke(!_base.IsPlayerCreature); IsEnd = true; } }; }
private void AdjustPositionStartAt(int startIndex, CellChange cellChange) { var numberOfTargetCells = m_Cells.Count - startIndex; var targets = new NativeArray <Vector3>(numberOfTargetCells, Allocator.TempJob); var transforms = new Transform[numberOfTargetCells]; for (var i = startIndex; i < m_Cells.Count; i++) { var cell = m_Cells[i]; var cellTransform = cell.gameObject.transform; var cellPosition = cellTransform.localPosition; if (cellChange == CellChange.Add) { cell.ItemIndex++; } else { cell.ItemIndex--; } transforms[i - startIndex] = cellTransform; targets[i - startIndex] = new Vector3( cellPosition.x, -cell.ItemIndex * (m_CellItemHeight + m_Spacing), cellPosition.z ); } var warpJob = new WarpToTargetJob { targets = targets }; var transformAccessArray = new TransformAccessArray(transforms); JobHandle handle = warpJob.Schedule(transformAccessArray); handle.Complete(); transformAccessArray.Dispose(); targets.Dispose(); }
public void CellRoleAsign(int cellRole) { switch (cellRole) { case 0: // add IdleCell GameObject AddedCell = Instantiate(Cell); CellBehaviour AddedCellBeh = AddedCell.GetComponent <CellBehaviour>(); AddedCellBeh.body = BodyParts[CurrentBodyPart]; ; AddedCellBeh.CellScriptableObject = CellsScriptableObjects[0]; AddedCell.name = "Cell" + "(" + Stats.stats.cells + ")"; IdleCells.Add(AddedCell); break; // ------------- RED BLOOD CELL ------------// case 1: // add RedBloodCell if (IdleCells.Count > 0) { GameObject CellChange; CellChange = IdleCells[IdleCells.Count - 1]; IdleCells.RemoveAt(IdleCells.Count - 1); CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>(); cellChangeBeh.CellScriptableObject = CellsScriptableObjects[1]; RedBloodCells.Add(CellChange); redBloodCellSystem.AddRedBloodCell(); Debug.Log("addedRedBloodCell"); break; } else { Debug.Log("OutOfIdleCells"); break; } case -1: // remove RedBloodCell if (RedBloodCells.Count > 0) { GameObject CellChange; CellChange = RedBloodCells[RedBloodCells.Count - 1]; RedBloodCells.RemoveAt(RedBloodCells.Count - 1); CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>(); cellChangeBeh.CellScriptableObject = CellsScriptableObjects[0]; IdleCells.Add(CellChange); redBloodCellSystem.RemoveRedBloodCell(); Debug.Log("RemovedRedBloodCell"); break; } else { Debug.Log("noRedBloodCells"); break; } // ------------- WHITE BLOOD CELL ------------// case 2: // add White Blood Cell if (IdleCells.Count > 0) { GameObject CellChange; CellChange = IdleCells[IdleCells.Count - 1]; IdleCells.RemoveAt(IdleCells.Count - 1); CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>(); cellChangeBeh.CellScriptableObject = CellsScriptableObjects[2]; WhiteBloodCells.Add(CellChange); whiteBloodCellSystem.AddWhiteBloodCell(); break; } else { Debug.Log("OutOfIdleCells"); break; } case -2: // Remove White Blood Cell if (WhiteBloodCells.Count > 0) { GameObject CellChange; CellChange = WhiteBloodCells[WhiteBloodCells.Count - 1]; WhiteBloodCells.RemoveAt(WhiteBloodCells.Count - 1); CellBehaviour cellChangeBeh = CellChange.GetComponent <CellBehaviour>(); cellChangeBeh.CellScriptableObject = CellsScriptableObjects[0]; IdleCells.Add(CellChange); whiteBloodCellSystem.RemoveWhiteBloodCell(); break; } else { Debug.Log("no WhiteBloodCells"); break; } } }
/// <summary> /// Notify about the matrix cell changes /// </summary> /// <param name="sender">Sender of event</param> /// <param name="e">Cell change information</param> protected virtual void OnCellChange(object sender, CellChangeEventArgs <T> e) { CellChange?.Invoke(sender, e); }