void LoadHotbar(PlayerHotbar hotbar) { for (int i = 0; i < hotbar.size; ++i) { hotbar.slots.Add(new ItemSlot()); } foreach (character_hotbar row in connection.Query <character_hotbar>("SELECT * FROM character_hotbar WHERE character=?", hotbar.name)) { if (row.slot < hotbar.size) { if (ScriptableItem.dict.TryGetValue(row.name.GetStableHashCode(), out ScriptableItem itemData)) { Item item = new Item(itemData); item.ammo = row.ammo; item.durability = Mathf.Min(row.durability, item.maxDurability); hotbar.slots[row.slot] = new ItemSlot(item, row.amount); } else { Debug.LogWarning("LoadHotbar: skipped item " + row.name + " for " + hotbar.name + " because it doesn't exist anymore. If it wasn't removed intentionally then make sure it's in the Resources folder."); } } else { Debug.LogWarning("LoadHotbar: skipped slot " + row.slot + " for " + hotbar.name + " because it's bigger than size " + hotbar.size); } } }
void LoadHotbarSelection(PlayerHotbar hotbar) { character_hotbar_selection row = connection.FindWithQuery <character_hotbar_selection>("SELECT * FROM character_hotbar_selection WHERE character=?", hotbar.name); if (row != null) { hotbar.selection = row.selection; } }
void SaveHotbar(PlayerHotbar hotbar) { connection.Execute("DELETE FROM character_hotbar WHERE character=?", hotbar.name); for (int i = 0; i < hotbar.slots.Count; ++i) { ItemSlot slot = hotbar.slots[i]; if (slot.amount > 0) { connection.InsertOrReplace(new character_hotbar { character = hotbar.name, slot = i, name = slot.item.name, amount = slot.amount, ammo = slot.item.ammo, durability = slot.item.durability }); } } }
void SaveHotbarSelection(PlayerHotbar hotbar) { connection.InsertOrReplace(new character_hotbar_selection { character = hotbar.name, selection = hotbar.selection }); }