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