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

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

Server fixes for A12

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 ();
[238]47 foreach (ItemStack invF in cm.GetAllItems()) {
48 ItemClass ib = ItemClass.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 }
[238]58 foreach (ItemStack invF in cm.GetAllBlocks()) {
59 ItemClass ib = ItemClass.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.