source: binary-improvements/7dtd-server-fixes/src/ItemList.cs@ 291

Last change on this file since 291 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes
5{
6 public class ItemList
7 {
8 private static ItemList instance;
9
10 public static ItemList Instance {
11 get {
12 if (instance == null) {
13 instance = new ItemList ();
14 }
15 return instance;
16 }
17 }
18
19 private ItemList ()
20 {
21 }
22
23 private SortedDictionary<string, ItemValue> items = new SortedDictionary<string, ItemValue> ();
24
25 public List<string> ItemNames {
26 get { return new List<string> (items.Keys); }
27 }
28
29 public ItemValue GetItemValue (string itemName)
30 {
31 if (items.ContainsKey (itemName)) {
32 return items [itemName].Clone ();
33 } else {
34 itemName = itemName.ToLower ();
35 foreach (KeyValuePair<string, ItemValue> kvp in items) {
36 if (kvp.Key.ToLower ().Equals (itemName)) {
37 return kvp.Value.Clone ();
38 }
39 }
40 return null;
41 }
42 }
43
44 public void Init ()
45 {
46 NGuiInvGridCreativeMenu cm = new NGuiInvGridCreativeMenu ();
47 foreach (ItemStack invF in cm.GetAllItems()) {
48 ItemClass ib = ItemClass.list [invF.itemValue.type];
49 string name = ib.GetItemName ();
50 if (name != null && name.Length > 0) {
51 if (!items.ContainsKey (name)) {
52 items.Add (name, invF.itemValue);
53 } else {
54 //Log.Out ("Item \"" + name + "\" already in list!");
55 }
56 }
57 }
58 foreach (ItemStack invF in cm.GetAllBlocks()) {
59 ItemClass ib = ItemClass.list [invF.itemValue.type];
60 string name = ib.GetItemName ();
61 if (name != null && name.Length > 0) {
62 if (!items.ContainsKey (name)) {
63 items.Add (name, invF.itemValue);
64 } else {
65 //Log.Out ("Item \"" + name + "\" already in list!");
66 }
67 }
68 }
69 }
70 }
71}
72
Note: See TracBrowser for help on using the repository browser.