Work-in-progress Item system code.

This commit is contained in:
2025-03-19 02:48:22 -04:00
parent a599775eee
commit 10e82cd4aa
3 changed files with 65 additions and 22 deletions

View File

@@ -1,7 +1,12 @@
#pragma once
#include <set>
#include <string>
#include <J3ML/Math.hpp>
#include <map>
//#include <Core/Registry.hpp>
#pragma once
namespace CaveGame::Core
{
@@ -20,7 +25,7 @@ namespace CaveGame::Core
/// This enum defines combinatorial category flags to items to enable smart sorting.
enum class ItemCategory: u8
enum class ItemCategory
{
ANY, TILE_ITEM, ORE, TOOL, WEAPON, ARMOR, CLOTHING, FOOD, POTION, INGREDIENT, MEME, PLANT, METAL, ORGANIC, BUILDING_BLOCK,
FLUID, SOIL, GAS, LIGHT_SOURCE, CRAFTING_STATION,
@@ -29,7 +34,7 @@ namespace CaveGame::Core
/// This enum defines a mutually-exclusive (one-at-a-time) 'Modifier' that items may randomly spawn with.
/// It will affect item stats in a variety of ways, and some will even have special coding.
enum class ItemModifiers : u8 {
enum class ItemModifiers {
// These represent low-quality, crappy items, often with comical effects.
FLIMSY, RUSTY, BROKEN, BENDY, RUBBERY, FRAGILE, FILTHY, DRAB, DULL, SCARRED, BURNED,
@@ -59,13 +64,33 @@ namespace CaveGame::Core
ANCIENT, VICTORIOUS, CONDEMNED, CLEAN, LUCKY, POWERFUL, SUPER,
};
class ItemComponent
{
};
class UseCooldown {};
class Consumable {};
class Drinkable {};
class Eatable {};
class Item
{
public:
Item() = default;
explicit Item(const std::string& name);
std::string mnemonic;
std::string display_name;
std::string tooltip;
std::string author;
unsigned int max_stack;
int value = 1;
Item() {}
explicit Item(const std::string& mnemonic);
protected:
private:
};
@@ -75,16 +100,13 @@ namespace CaveGame::Core
void RegisterItem(const std::string& name, Item* item);
Item* GetItem(const std::string& name);
void RegisterItem(const std::string& mnemonic, Item* item);
void RegisterNewItem(const std::string& mnemonic, const Item& item);
Item* GetItem(const std::string& mnemonic);
std::map<std::string, Item*> GetAllItems();
class EmptyBottle : public Item
{
//REGISTER("EmptyBottle", Item);
};
class ItemFilter
{
@@ -103,10 +125,10 @@ namespace CaveGame::Core
static const Item Straw;
static const Item Gel;
//static const Item Gel {"gel", "Gel", };
static const Item Glowstick;
static const Item RoastChicken;
//static const Item RoastChicken {"roast-chicken", "Roast Chicken"};
static const Item PumpkinPie;
static const Item ShepherdsPie;

View File

@@ -3,5 +3,15 @@
namespace CaveGame::Core
{
class ItemStack : PhysicsEntity {};
class ItemStack
{
public:
protected:
private:
};
class ItemStackEntity : public PhysicsEntity, public ItemStack {
public:
protected:
private:
};
}

View File

@@ -4,19 +4,30 @@
namespace CaveGame::Core {
std::map<std::string, Item*> item_registry;
std::map<std::string, Item*> item_registry{};
void RegisterItem(const std::string& name, Item* item)
void RegisterItem(const std::string& mnemonic, Item* item)
{
item_registry.insert({name, item});
item_registry.insert({mnemonic, item});
}
Item* GetItem(const std::string& name)
void RegisterNewItem(const std::string& mnemonic, const Item& item)
{
return item_registry.at(name);
//item_registry.emplace(mnemonic, new Item(item));
}
Item::Item(const std::string& name) {
RegisterItem(name, this);
Item* GetItem(const std::string& mnemonic)
{
return item_registry.at(mnemonic);
}
std::map<std::string, Item*> GetAllItems()
{
return item_registry;
}
Item::Item(const std::string& mnemonic) {
this->mnemonic = mnemonic;
RegisterItem(mnemonic, this);
}
}