public void AddToGameData(Item i) { if (Application.isEditor && !ItemExists(i.itemName)) { itemData.Add(i); ItemMap.Add(i.itemName, i); } }
public void WriteItems(TextAsset textAsset) { if (textAsset == null) { return; } using (var reader = new StringReader(textAsset.text)) { int lineNum = 0; string line; while ((line = reader.ReadLine()) != null) { var split = line.Split(','); if (split.Length < 3 || split.Length > 4) { Debug.LogError($"Error in syntax at line {lineNum} reading item from asset {textAsset.name}!"); continue; } var x = Convert.ToInt32(split[0]); var y = Convert.ToInt32(split[1]); var name = split[2]; var pos = new int2(x, y); if (ItemMap.ContainsKey(pos)) { Debug.LogError($"Error reading position at line {lineNum} reading item from asset {textAsset.name}. It already exist!"); continue; } ItemMap.Add(pos, name); if (split.Length == 4 && ItemSpecialsMap.ContainsKey(pos) == false) { var special = split[3]; ItemSpecialsMap.Add(pos, special); } lineNum++; } } }
// Suppress the deprecation warning for _SetId, since the DB is intended to use it #pragma warning disable 612, 618 public void UpdateDatabase() { if (!defaultItem) { Debug.LogError("Cannot update the database. A default item MUST be assigned."); return; } // Add the default item registeredItems.Remove(0); defaultItem._SetId(this, 0); registeredItems.Add(0, defaultItem); // Add new items var existingValues = registeredItems.Values; foreach (ItemBase newItem in addItems) { // No double registering if (existingValues.Contains(newItem)) { continue; } newItem._SetId(this, idCounter); registeredItems.Add(idCounter, newItem); idCounter++; } addItems.Clear(); //Remap missing items that have been filled out // // Remove missing items/ids List <uint> missingValues = new List <uint>(10); foreach (var pair in registeredItems) { if (!pair.Value) { missingValues.Add(pair.Key); } } foreach (uint key in missingValues) { registeredItems.Remove(key); } // Add the missing items' ids for remapping foreach (uint id in missingValues) { string name = "Unknown"; nameMap.TryGetValue(id, out name); missingIds.Add(id); missingNameMap.Add(id, name); } // Regenerate name map nameMap.Clear(); foreach (var pair in registeredItems) { nameMap.Add(pair.Key, pair.Value.GetName()); } }
public void PutItemOnMap(IItem item, Coord coord) { ItemMap.Add(item, coord); }