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

Last change on this file since 237 was 224, checked in by alloc, 10 years ago

A11 preps

File size: 1.6 KB
RevLine 
[197]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
[224]29 public ItemValue GetItemValue (string itemName)
[197]30 {
31 if (items.ContainsKey (itemName)) {
[224]32 return items [itemName].Clone ();
[197]33 } else {
34 itemName = itemName.ToLower ();
35 foreach (KeyValuePair<string, ItemValue> kvp in items) {
36 if (kvp.Key.ToLower ().Equals (itemName)) {
[224]37 return kvp.Value.Clone ();
[197]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];
[224]49 string name = ib.GetItemName ();
[197]50 if (name != null && name.Length > 0) {
[199]51 if (!items.ContainsKey (name)) {
[197]52 items.Add (name, invF.itemValue);
[199]53 } else {
54 //Log.Out ("Item \"" + name + "\" already in list!");
55 }
[197]56 }
57 }
58 foreach (InventoryField invF in cm.GetAllBlocks()) {
59 ItemBase ib = ItemBase.list [invF.itemValue.type];
[224]60 string name = ib.GetItemName ();
[197]61 if (name != null && name.Length > 0) {
[199]62 if (!items.ContainsKey (name)) {
[197]63 items.Add (name, invF.itemValue);
[199]64 } else {
65 //Log.Out ("Item \"" + name + "\" already in list!");
66 }
[197]67 }
68 }
69 }
70 }
71}
72
Note: See TracBrowser for help on using the repository browser.