A game about forced loneliness, made by TACStudios
1using System.Collections;
2
3namespace Unity.VisualScripting
4{
5 /// <summary>
6 /// Sets the value of a dictionary item with the specified key.
7 /// </summary>
8 [UnitCategory("Collections/Dictionaries")]
9 [UnitSurtitle("Dictionary")]
10 [UnitShortTitle("Set Item")]
11 [UnitOrder(1)]
12 [TypeIcon(typeof(IDictionary))]
13 public sealed class SetDictionaryItem : 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 [PortLabelHidden]
27 public ValueInput dictionary { get; private set; }
28
29 /// <summary>
30 /// The key of the item to set.
31 /// </summary>
32 [DoNotSerialize]
33 public ValueInput key { get; private set; }
34
35 /// <summary>
36 /// The value to assign to the item.
37 /// </summary>
38 [DoNotSerialize]
39 public ValueInput value { get; private set; }
40
41 /// <summary>
42 /// The action to execute once the item has been assigned.
43 /// </summary>
44 [DoNotSerialize]
45 [PortLabelHidden]
46 public ControlOutput exit { get; private set; }
47
48 protected override void Definition()
49 {
50 enter = ControlInput(nameof(enter), Set);
51 dictionary = ValueInput<IDictionary>(nameof(dictionary));
52 key = ValueInput<object>(nameof(key));
53 value = ValueInput<object>(nameof(value));
54 exit = ControlOutput(nameof(exit));
55
56 Requirement(dictionary, enter);
57 Requirement(key, enter);
58 Requirement(value, enter);
59 Succession(enter, exit);
60 }
61
62 public ControlOutput Set(Flow flow)
63 {
64 var dictionary = flow.GetValue<IDictionary>(this.dictionary);
65 var key = flow.GetValue<object>(this.key);
66 var value = flow.GetValue<object>(this.value);
67
68 dictionary[key] = value;
69
70 return exit;
71 }
72 }
73}