2023-10-06 17:19:02 -05:00
#pragma once
#include <string>
#include <functional>
#include <map>
#include "olcPixelGameEngine.h"
2023-10-06 18:46:13 -05:00
#include "olcUTIL_DataFile.h"
2023-10-06 17:19:02 -05:00
class Crawler ;
class ItemInfo ;
2023-10-07 15:47:26 -05:00
class ItemProps ;
2023-10-06 17:19:02 -05:00
2023-10-07 13:33:27 -05:00
typedef std :: string IT ;
typedef std :: string ITCategory ;
2023-10-07 15:47:26 -05:00
typedef std :: function < bool ( Crawler * , ItemProps ) > ItemScript ;
2023-10-06 17:19:02 -05:00
class Item {
2023-10-07 13:33:27 -05:00
friend class Inventory ;
2023-10-06 17:19:02 -05:00
private :
2023-10-07 13:33:27 -05:00
uint32_t amt ;
2023-10-06 17:19:02 -05:00
ItemInfo * it ;
2023-10-07 13:33:27 -05:00
public :
2023-10-07 15:47:26 -05:00
Item ();
2023-10-07 13:33:27 -05:00
Item ( uint32_t amt , IT item );
uint32_t Amt ();
std :: string Name ();
std :: string Description ();
ITCategory Category ();
Decal * Decal ();
ItemScript & OnUseAction ();
2023-10-07 15:47:26 -05:00
bool IsBlank ();
static Item BLANK ;
2023-10-06 17:19:02 -05:00
};
class Inventory {
2023-10-07 16:26:03 -05:00
friend class ItemInfo ;
2023-10-06 17:19:02 -05:00
public :
2023-10-07 15:47:26 -05:00
static void AddItem ( IT it , uint32_t amt = 1 );
2023-10-07 13:33:27 -05:00
static uint32_t GetItemCount ( IT it );
2023-10-07 15:47:26 -05:00
static Item GetItem ( IT it );
2023-10-07 13:33:27 -05:00
//Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times.
2023-10-07 15:47:26 -05:00
static void UseItem ( IT it , uint32_t amt = 1 );
static void RemoveItem ( IT it , uint32_t amt = 1 );
2023-10-07 13:33:27 -05:00
static std :: vector < IT >& get ( ITCategory itemCategory );
2023-10-07 13:49:32 -05:00
2023-10-07 18:28:19 -05:00
static bool SwapItems ( ITCategory itemCategory , uint32_t slot1 , uint32_t slot2 );
2023-10-06 17:19:02 -05:00
private :
2023-10-07 13:33:27 -05:00
static void InsertIntoSortedInv ( IT item );
static bool ExecuteAction ( IT item );
static std :: map < IT , Item > _inventory ;
static std :: map < ITCategory , std :: vector < IT >> sortedInv ;
2023-10-06 17:19:02 -05:00
};
2023-10-06 18:46:13 -05:00
class ItemProps {
friend class ItemInfo ;
utils :: datafile * scriptProps ;
utils :: datafile * customProps ;
public :
ItemProps ( utils :: datafile * scriptProps , utils :: datafile * customProps );
int GetIntProp ( std :: string prop );
float GetFloatProp ( std :: string prop );
std :: string GetStringProp ( std :: string prop );
};
2023-10-06 17:19:02 -05:00
class ItemInfo {
2023-10-07 13:33:27 -05:00
friend class Inventory ;
2023-10-06 17:19:02 -05:00
std :: string name ;
2023-10-06 18:46:13 -05:00
std :: string description ;
std :: string category ;
2023-10-06 17:19:02 -05:00
Decal * img ;
//Returns true if the item can be used, false otherwise
2023-10-06 18:46:13 -05:00
std :: string useFunc = "" ;
//Custom properties for this specific item's script.
static utils :: datafile NOPROPS ;
ItemProps customProps ;
private :
static void InitializeScripts ();
2023-10-06 17:19:02 -05:00
public :
static void InitializeItems ();
2023-10-06 18:46:13 -05:00
ItemInfo ();
2023-10-07 15:47:26 -05:00
std :: string Name ();
std :: string Description ();
ITCategory Category ();
Decal * Decal ();
ItemScript & OnUseAction ();
2023-10-06 17:19:02 -05:00
/*
For the useFunc, return true if the item can be used, false otherwise.
*/
};