A game about forced loneliness, made by TACStudios
1using System.Collections; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Removes a dictionary item with a specified key. 7 /// </summary> 8 [UnitCategory("Collections/Dictionaries")] 9 [UnitSurtitle("Dictionary")] 10 [UnitShortTitle("Remove Item")] 11 [UnitOrder(3)] 12 public sealed class RemoveDictionaryItem : Unit 13 { 14 /// <summary> 15 /// The entry point for the node. 16 /// </summary> 17 [DoNotSerialize] 18 [PortLabelHidden] 19 public ControlInput enter { get; private set; } 20 21 /// <summary> 22 /// The dictionary. 23 /// </summary> 24 [DoNotSerialize] 25 [PortLabel("Dictionary")] 26 [PortLabelHidden] 27 public ValueInput dictionaryInput { get; private set; } 28 29 /// <summary> 30 /// The dictionary without the removed item. 31 /// Note that the input dictionary is modified directly and then returned. 32 /// </summary> 33 [DoNotSerialize] 34 [PortLabel("Dictionary")] 35 [PortLabelHidden] 36 public ValueOutput dictionaryOutput { get; private set; } 37 38 /// <summary> 39 /// The key of the item to remove. 40 /// </summary> 41 [DoNotSerialize] 42 public ValueInput key { get; private set; } 43 44 /// <summary> 45 /// The action to execute once the item has been removed. 46 /// </summary> 47 [DoNotSerialize] 48 [PortLabelHidden] 49 public ControlOutput exit { get; private set; } 50 51 protected override void Definition() 52 { 53 enter = ControlInput(nameof(enter), Remove); 54 dictionaryInput = ValueInput<IDictionary>(nameof(dictionaryInput)); 55 dictionaryOutput = ValueOutput<IDictionary>(nameof(dictionaryOutput)); 56 key = ValueInput<object>(nameof(key)); 57 exit = ControlOutput(nameof(exit)); 58 59 Requirement(dictionaryInput, enter); 60 Requirement(key, enter); 61 Assignment(enter, dictionaryOutput); 62 Succession(enter, exit); 63 } 64 65 public ControlOutput Remove(Flow flow) 66 { 67 var dictionary = flow.GetValue<IDictionary>(dictionaryInput); 68 var key = flow.GetValue<object>(this.key); 69 70 flow.SetValue(dictionaryOutput, dictionary); 71 72 dictionary.Remove(key); 73 74 return exit; 75 } 76 } 77}