| | 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 : IBIWCompleteAction |
| | 8 | | { |
| | 9 | |
|
| | 10 | | public IBIWCompleteAction.ActionType actionType; |
| 13 | 11 | | public bool isDone = true; |
| | 12 | |
|
| | 13 | | public event IBIWCompleteAction.OnApplyValueDelegate OnApplyValue; |
| | 14 | |
|
| 13 | 15 | | List<BIWEntityAction> entityApplied = new List<BIWEntityAction>(); |
| | 16 | |
|
| | 17 | | public void Redo() |
| | 18 | | { |
| 24 | 19 | | foreach (BIWEntityAction action in entityApplied) |
| | 20 | | { |
| 6 | 21 | | ApplyValue(action.entityId, action.newValue, false); |
| | 22 | | } |
| 6 | 23 | | isDone = true; |
| 6 | 24 | | } |
| 58 | 25 | | public bool IsDone() => isDone; |
| | 26 | |
|
| | 27 | | public void Undo() |
| | 28 | | { |
| 24 | 29 | | foreach (BIWEntityAction action in entityApplied) |
| | 30 | | { |
| 6 | 31 | | ApplyValue(action.entityId, action.oldValue, true); |
| | 32 | | } |
| | 33 | |
|
| 6 | 34 | | isDone = false; |
| | 35 | |
|
| 6 | 36 | | } |
| | 37 | |
|
| 24 | 38 | | private void ApplyValue(string entityToApply, object value, bool isUndo) { OnApplyValue?.Invoke(entityToApply, value |
| | 39 | |
|
| | 40 | | public void CreateChangeFloorAction(CatalogItem oldFloor, CatalogItem newFloor) |
| | 41 | | { |
| 3 | 42 | | BIWEntityAction action = new BIWEntityAction(JsonConvert.SerializeObject(oldFloor), JsonConvert.SerializeObject( |
| 3 | 43 | | List<BIWEntityAction> list = new List<BIWEntityAction>(); |
| 3 | 44 | | list.Add(action); |
| 3 | 45 | | CreateAction(list, IBIWCompleteAction.ActionType.CHANGE_FLOOR); |
| 3 | 46 | | } |
| | 47 | |
|
| | 48 | | public void CreateActionType(BIWEntityAction action, IBIWCompleteAction.ActionType type) |
| | 49 | | { |
| 4 | 50 | | List<BIWEntityAction> list = new List<BIWEntityAction>(); |
| 4 | 51 | | list.Add(action); |
| 4 | 52 | | CreateAction(list, type); |
| 4 | 53 | | } |
| | 54 | |
|
| 12 | 55 | | public void CreateActionType(List<BIWEntityAction> entitiesActions, IBIWCompleteAction.ActionType type) { CreateActi |
| | 56 | |
|
| | 57 | | void CreateAction(List<BIWEntityAction> entitiesActions, IBIWCompleteAction.ActionType type) |
| | 58 | | { |
| 13 | 59 | | actionType = type; |
| 13 | 60 | | entityApplied = entitiesActions; |
| 13 | 61 | | isDone = true; |
| 13 | 62 | | } |
| | 63 | | } |