-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.cs
More file actions
209 lines (180 loc) · 9.86 KB
/
API.cs
File metadata and controls
209 lines (180 loc) · 9.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.Linq;
using static ExtraSlots.Slots;
namespace ExtraSlots;
public static class API
{
/// <summary>
/// Returns list of all slots
/// </summary>
public static List<Slot> GetExtraSlots() => slots.ToList();
/// <summary>
/// Returns list of corresponding slots
/// </summary>
public static List<Slot> GetEquipmentSlots() => slots.Where(slot => slot.IsEquipmentSlot).ToList();
/// <summary>
/// Returns list of corresponding slots
/// </summary>
public static List<Slot> GetQuickSlots() => slots.Where(slot => slot.IsQuickSlot).ToList();
/// <summary>
/// Returns list of corresponding slots
/// </summary>
public static List<Slot> GetFoodSlots() => slots.Where(slot => slot.IsFoodSlot).ToList();
/// <summary>
/// Returns list of corresponding slots
/// </summary>
public static List<Slot> GetAmmoSlots() => slots.Where(slot => slot.IsAmmoSlot).ToList();
/// <summary>
/// Returns list of corresponding slots
/// </summary>
public static List<Slot> GetMiscSlots() => slots.Where(slot => slot.IsMiscSlot).ToList();
/// <summary>
/// Returns slot with given ID
/// </summary>
/// <param name="slotID"></param>
public static Slot FindSlot(string slotID) => slots.FirstOrDefault(slot => slot.ID == slotID || slot.ID == CustomSlot.GetSlotID(slotID));
/// <summary>
/// Returns list of items located in extra slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetAllExtraSlotsItems() => slots.Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns list of items located in corresponding slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetEquipmentSlotsItems() => GetEquipmentSlots().Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns list of items located in corresponding slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetQuickSlotsItems() => GetQuickSlots().Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns list of items located in corresponding slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetFoodSlotsItems() => GetFoodSlots().Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns list of items located in corresponding slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetAmmoSlotsItems() => GetAmmoSlots().Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns list of items located in corresponding slots
/// </summary>
/// <returns>List of not null ItemDrop.ItemData</returns>
public static List<ItemDrop.ItemData> GetMiscSlotsItems() => GetMiscSlots().Select(slot => slot.Item).Where(item => item != null).ToList();
/// <summary>
/// Returns amount of extra rows added to player available inventory
/// </summary>
public static int GetExtraRows() => ExtraRowsPlayer;
/// <summary>
/// Returns full height of inventory
/// </summary>
public static int GetInventoryHeightFull() => InventoryHeightFull;
/// <summary>
/// Returns full height of inventory
/// </summary>
public static int GetInventoryHeightPlayer() => InventoryHeightPlayer;
/// <summary>
/// Returns if given position is extra slot
/// </summary>
/// <param name="gridPos">Position in inventory grid</param>
public static bool IsGridPositionASlot(Vector2i gridPos) => Slots.IsGridPositionASlot(gridPos);
/// <summary>
/// Returns if given item is in extra slot
/// </summary>
/// <param name="item"></param>
public static bool IsItemInSlot(ItemDrop.ItemData item) => Slots.IsItemInSlot(item);
/// <summary>
/// Returns if given item is in equipment slot
/// </summary>
/// <param name="item"></param>
public static bool IsItemInEquipmentSlot(ItemDrop.ItemData item) => Slots.IsItemInEquipmentSlot(item);
/// <summary>
/// Returns if any global key or player unique key from comma-separated string is enabled.
/// Respects if slots progression is enabled
/// </summary>
/// <param name="requiredKeys">Comma-separated list of global keys and player unique keys</param>
public static bool IsAnyGlobalKeyActive(string requiredKeys) => SlotsProgression.IsAnyGlobalKeyActive(requiredKeys);
/// <summary>
/// Returns if any global key or player unique key from comma-separated string is enabled.
/// Respects if slots progression is enabled
/// </summary>
/// <param name="itemType"></param>
public static bool IsItemTypeKnown(ItemDrop.ItemData.ItemType itemType) => SlotsProgression.IsItemTypeKnown(itemType);
/// <summary>
/// Returns if any global key or player unique key from comma-separated string is enabled.
/// Respects if slots progression is enabled
/// </summary>
/// <param name="itemNames">Comma-separated list of item names (m_shared.m_name)</param>
public static bool IsAnyMaterialDiscovered(string itemNames) => SlotsProgression.IsAnyMaterialDiscovered(itemNames);
/// <summary>
/// Adds new custom equipment slot at first available position
/// </summary>
/// <param name="slotID">To add new slot ID should be unique. If given ID is not unique returns true if slot is already created</param>
/// <param name="getName">function that return slot name how it should be seen in the UI. Localization is recommended.</param>
/// <param name="itemIsValid">function to check of item fits the slot</param>
/// <param name="isActive">function to check if slot should be available in equipment panel. If you need live update - call UpdateSlots.</param>
/// <returns></returns>
public static bool AddSlot(string slotID, Func<string> getName, Func<ItemDrop.ItemData, bool> itemIsValid, Func<bool> isActive)
{
return CustomSlot.TryAddNewSlotWithIndex(slotID, slotIndex: -1, getName, itemIsValid, isActive);
}
/// <summary>
/// Adds new custom equipment slot with set position
/// </summary>
/// <param name="slotID">To add new slot ID should be unique. If given ID is not unique returns true if slot is already created</param>
/// <param name="slotIndex">-1 to take first available empty slot. Otherwise shift other slots to the right and insert into position after vanilla equipment slots</param>
/// <param name="getName">function that return slot name how it should be seen in the UI. Localization is recommended.</param>
/// <param name="itemIsValid">function to check of item fits the slot</param>
/// <param name="isActive">function to check if slot should be available in equipment panel. If you need live update - call UpdateSlots.</param>
/// <returns></returns>
public static bool AddSlotWithIndex(string slotID, int slotIndex, Func<string> getName, Func<ItemDrop.ItemData, bool> itemIsValid, Func<bool> isActive)
{
return CustomSlot.TryAddNewSlotWithIndex(slotID, slotIndex, getName, itemIsValid, isActive);
}
/// <summary>
/// Adds new custom equipment slot with set position
/// </summary>
/// <param name="slotID">To add new slot ID should be unique. If given ID is not unique returns true if slot is already created</param>
/// <param name="getName">function that return slot name how it should be seen in the UI. Localization is recommended.</param>
/// <param name="itemIsValid">function to check of item fits the slot</param>
/// <param name="isActive">function to check if slot should be available in equipment panel. If you need live update - call UpdateSlots.</param>
/// <param name="slotIDs">slot IDs to add the slot before</param>
/// <returns></returns>
[Obsolete("Use AddSlotAfter instead.")]
public static bool AddSlotBefore(string slotID, Func<string> getName, Func<ItemDrop.ItemData, bool> itemIsValid, Func<bool> isActive, params string[] slotIDs)
{
return AddSlotAfter(slotID, getName, itemIsValid, isActive, slotIDs);
}
/// <summary>
/// Adds new custom equipment slot with set position
/// </summary>
/// <param name="slotID">To add new slot ID should be unique. If given ID is not unique returns true if slot is already created</param>
/// <param name="getName">function that return slot name how it should be seen in the UI. Localization is recommended.</param>
/// <param name="itemIsValid">function to check of item fits the slot</param>
/// <param name="isActive">function to check if slot should be available in equipment panel. If you need live update - call UpdateSlots.</param>
/// <param name="slotIDs">slot IDs after which the slot should be added</param>
/// <returns></returns>
public static bool AddSlotAfter(string slotID, Func<string> getName, Func<ItemDrop.ItemData, bool> itemIsValid, Func<bool> isActive, params string[] slotIDs)
{
return CustomSlot.TryAddNewSlotAfter(slotIDs, slotID, getName, itemIsValid, isActive);
}
/// <summary>
/// Tries to remove custom slot with given ID
/// </summary>
/// <param name="slotID"></param>
public static bool RemoveSlot(string slotID) => CustomSlot.TryRemoveSlot(slotID);
/// <summary>
/// Calls an update to slots layout and equipment panel
/// Should be called if slot active state was changed to update panel
/// </summary>
public static void UpdateSlots()
{
UpdateSlotsGridPosition();
EquipmentPanel.UpdatePanel();
LightenedSlots.UpdateState();
HotBars.PreventSimilarHotkeys.FillSimilarHotkey();
}
}