Elin Decompiled Documentation EA 23.346 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 object loadOption;
16
17 public ModItemList(int _catLength = 0)
18 {
19 catLength = _catLength;
20 }
21
22 public ModItemList(int _catLength, object _loadOption)
23 : this(_catLength)
24 {
25 loadOption = _loadOption;
26 }
27
28 public string GetRandomID(string category = null)
29 {
30 if (list.Count == 0)
31 {
32 return null;
33 }
34 ModItem<T> modItem;
35 do
36 {
37 modItem = list[Rand.rnd(list.Count)];
38 }
39 while (category != null && !(modItem.category == category));
40 return modItem.id;
41 }
42
43 public string GetNextID(string currentId, int a, bool ignoreCategory = true)
44 {
45 int num = IndexOf(currentId) + a;
46 if (num >= list.Count)
47 {
48 num = 0;
49 }
50 if (num < 0)
51 {
52 num = list.Count - 1;
53 }
54 return list[num].id;
55 }
56
57 public int IndexOf(string id)
58 {
59 for (int i = 0; i < list.Count; i++)
60 {
61 if (list[i].id == id)
62 {
63 return i;
64 }
65 }
66 return -1;
67 }
68
69 public ModItem<T> GetItem(string id, bool returnNull = false)
70 {
71 ModItem<T> value = null;
72 if (dict.TryGetValue(id, out value))
73 {
74 return value;
75 }
76 if (!returnNull)
77 {
78 return list[0];
79 }
80 return null;
81 }
82
83 public T GetObject(string id, object option = null)
84 {
85 ModItem<T> item = GetItem(id, returnNull: true);
86 if (item != null)
87 {
88 return item.GetObject();
89 }
90 return null;
91 }
92
93 public void Add(FileInfo fi, string path = null, string prefix = "")
94 {
95 Add(Path.GetFileNameWithoutExtension(prefix + ((fi != null) ? fi.Name : path)), fi, path);
96 }
97
98 public void Add(string id, FileInfo fi, string path = null)
99 {
100 if (dict.ContainsKey(id))
101 {
102 dict[id].Set(fi, path);
103 return;
104 }
105 list.Add(new ModItem<T>(fi, path, this, id));
106 dict.Add(id, list[list.Count - 1]);
107 }
108}
ModItemList(int _catLength=0)
Definition: ModItemList.cs:17
object loadOption
Definition: ModItemList.cs:15
List< ModItem< T > > list
Definition: ModItemList.cs:9
void Add(FileInfo fi, string path=null, string prefix="")
Definition: ModItemList.cs:93
ModItemList(int _catLength, object _loadOption)
Definition: ModItemList.cs:22
T GetObject(string id, object option=null)
Definition: ModItemList.cs:83
int IndexOf(string id)
Definition: ModItemList.cs:57
string GetNextID(string currentId, int a, bool ignoreCategory=true)
Definition: ModItemList.cs:43
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:98
string GetRandomID(string category=null)
Definition: ModItemList.cs:28
ModItem< T > GetItem(string id, bool returnNull=false)
Definition: ModItemList.cs:69
string id
Definition: ModItem.cs:10
string category
Definition: ModItem.cs:8
Definition: Rand.cs:4
static int rnd(int max)
Definition: Rand.cs:59