| | 1 | | using DCL.Models; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using Newtonsoft.Json; |
| | 6 | |
|
| | 7 | | public class BIWCompleteAction |
| | 8 | | { |
| | 9 | | public enum ActionType |
| | 10 | | { |
| | 11 | | MOVE = 0, |
| | 12 | | ROTATE = 1, |
| | 13 | | SCALE = 2, |
| | 14 | | CREATE = 3, |
| | 15 | | DELETE = 4, |
| | 16 | | CHANGE_FLOOR = 5 |
| | 17 | | } |
| | 18 | |
|
| | 19 | | public ActionType actionType; |
| 13 | 20 | | public bool isDone = true; |
| | 21 | |
|
| | 22 | | public delegate void OnApplyValueDelegate(string entityId, object value, ActionType actionType, bool isUndo); |
| | 23 | | public event OnApplyValueDelegate OnApplyValue; |
| | 24 | |
|
| 13 | 25 | | List<BIWEntityAction> entityApplied = new List<BIWEntityAction>(); |
| | 26 | |
|
| | 27 | | public void Redo() |
| | 28 | | { |
| 24 | 29 | | foreach (BIWEntityAction action in entityApplied) |
| | 30 | | { |
| 6 | 31 | | ApplyValue(action.entityId, action.newValue, false); |
| | 32 | | } |
| 6 | 33 | | isDone = true; |
| 6 | 34 | | } |
| | 35 | |
|
| | 36 | | public void Undo() |
| | 37 | | { |
| 24 | 38 | | foreach (BIWEntityAction action in entityApplied) |
| | 39 | | { |
| 6 | 40 | | ApplyValue(action.entityId, action.oldValue, true); |
| | 41 | | } |
| | 42 | |
|
| 6 | 43 | | isDone = false; |
| | 44 | |
|
| 6 | 45 | | } |
| | 46 | |
|
| 24 | 47 | | void ApplyValue(string entityToApply, object value, bool isUndo) { OnApplyValue?.Invoke(entityToApply, value, action |
| | 48 | |
|
| | 49 | | public void CreateChangeFloorAction(CatalogItem oldFloor, CatalogItem newFloor) |
| | 50 | | { |
| 3 | 51 | | BIWEntityAction action = new BIWEntityAction(JsonConvert.SerializeObject(oldFloor), JsonConvert.SerializeObject( |
| 3 | 52 | | List<BIWEntityAction> list = new List<BIWEntityAction>(); |
| 3 | 53 | | list.Add(action); |
| 3 | 54 | | CreateAction(list, ActionType.CHANGE_FLOOR); |
| 3 | 55 | | } |
| | 56 | |
|
| | 57 | | public void CreateActionType(BIWEntityAction action, ActionType type) |
| | 58 | | { |
| 4 | 59 | | List<BIWEntityAction> list = new List<BIWEntityAction>(); |
| 4 | 60 | | list.Add(action); |
| 4 | 61 | | CreateAction(list, type); |
| 4 | 62 | | } |
| | 63 | |
|
| 12 | 64 | | public void CreateActionType(List<BIWEntityAction> entitiesActions, ActionType type) { CreateAction(entitiesActions, |
| | 65 | |
|
| | 66 | | void CreateAction(List<BIWEntityAction> entitiesActions, ActionType type) |
| | 67 | | { |
| 13 | 68 | | actionType = type; |
| 13 | 69 | | entityApplied = entitiesActions; |
| 13 | 70 | | isDone = true; |
| 13 | 71 | | } |
| | 72 | | } |