Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ModItemList.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using UnityEngine;
4
5public class ModItemList<T> where T : Object
6{
8
9 public List<ModItem<T>> list = new List<ModItem<T>>();
10
11 public Dictionary<string, ModItem<T>> dict = new Dictionary<string, ModItem<T>>();
12
13 public int catLength;
14
15 public ModItemList(int _catLength = 0)
16 {
17 catLength = _catLength;
18 }
19
20 public string GetRandomID(string category = null)
21 {
22 if (list.Count == 0)
23 {
24 return null;
25 }
26 ModItem<T> modItem;
27 do
28 {
29 modItem = list[Rand.rnd(list.Count)];
30 }
31 while (category != null && !(modItem.category == category));
32 return modItem.id;
33 }
34
35 public string GetNextID(string currentId, int a, bool ignoreCategory = true)
36 {
37 int num = IndexOf(currentId) + a;
38 if (num >= list.Count)
39 {
40 num = 0;
41 }
42 if (num < 0)
43 {
44 num = list.Count - 1;
45 }
46 return list[num].id;
47 }
48
49 public int IndexOf(string id)
50 {
51 for (int i = 0; i < list.Count; i++)
52 {
53 if (list[i].id == id)
54 {
55 return i;
56 }
57 }
58 return -1;
59 }
60
61 public ModItem<T> GetItem(string id, bool returnNull = false)
62 {
63 ModItem<T> value = null;
64 if (dict.TryGetValue(id, out value))
65 {
66 return value;
67 }
68 if (!returnNull)
69 {
70 return list[0];
71 }
72 return null;
73 }
74
75 public T GetObject(string id, object option = null)
76 {
77 ModItem<T> item = GetItem(id, returnNull: true);
78 if (item != null)
79 {
80 return item.GetObject();
81 }
82 return null;
83 }
84
85 public void Add(FileInfo fi, string path = null, string prefix = "")
86 {
87 Add(Path.GetFileNameWithoutExtension(prefix + ((fi != null) ? fi.Name : path)), fi, path);
88 }
89
90 public void Add(string id, FileInfo fi, string path = null)
91 {
92 if (dict.ContainsKey(id))
93 {
94 dict[id].Set(fi, path);
95 return;
96 }
97 list.Add(new ModItem<T>(fi, path, this, id));
98 dict.Add(id, list[list.Count - 1]);
99 }
100}
ModItemList(int _catLength=0)
Definition: ModItemList.cs:15
List< ModItem< T > > list
Definition: ModItemList.cs:9
void Add(FileInfo fi, string path=null, string prefix="")
Definition: ModItemList.cs:85
T GetObject(string id, object option=null)
Definition: ModItemList.cs:75
int IndexOf(string id)
Definition: ModItemList.cs:49
string GetNextID(string currentId, int a, bool ignoreCategory=true)
Definition: ModItemList.cs:35
ResourceCache< T > cache
Definition: ModItemList.cs:7
Dictionary< string, ModItem< T > > dict
Definition: ModItemList.cs:11
void Add(string id, FileInfo fi, string path=null)
Definition: ModItemList.cs:90
string GetRandomID(string category=null)
Definition: ModItemList.cs:20
ModItem< T > GetItem(string id, bool returnNull=false)
Definition: ModItemList.cs:61
string id
Definition: ModItem.cs:10
string category
Definition: ModItem.cs:8
Definition: Rand.cs:4
static int rnd(int max)
Definition: Rand.cs:52