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

Last change on this file since 205 was 199, checked in by alloc, 10 years ago

fixes

File size: 1.7 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 Nullable<ItemValue> GetItemValue (string itemName)
30 {
31 if (items.ContainsKey (itemName)) {
32 return items [itemName];
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;
38 }
39 }
40 return null;
41 }
42 }
43
44 public void Init ()
45 {
46 NGuiInvGridCreativeMenu cm = new NGuiInvGridCreativeMenu ();
47 foreach (InventoryField invF in cm.GetAllItems()) {
48 ItemBase ib = ItemBase.list [invF.itemValue.type];
49 string name = ib.GetItemName (invF.itemValue);
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 (InventoryField invF in cm.GetAllBlocks()) {
59 ItemBase ib = ItemBase.list [invF.itemValue.type];
60 string name = ib.GetItemName (invF.itemValue);
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.