File WfItem.h
File List > game > include > WfItem.h
Go to the documentation of this file
#ifndef WFITEM_H
#define WFITEM_H
#include "HandleDefs.h"
#include <stdbool.h>
#include "WfEnums.h"
#include "ZzFX.h"
#include "DrawContext.h"
#include "InputContext.h"
#include "StringKeyHashMap.h"
#define UI_SPRITE_DIMS_PXLS 32
struct Entity2D;
struct GameFrameworkLayer;
struct WfItemDef;
enum WfItemIndices
{
WfBasicAxe,
WfBasicSword,
WfBasicPickAxe,
WfBasicScythe,
WfBasicFishingRod,
WfBasicHoe,
WfBasicBow,
WfWoodItem,
WfNumBuiltinItems
};
enum WfEquipSlot
{
Ring1,
Ring2,
Head,
Torso,
Legs,
Arms
};
/* when it is switched to in the menu */
typedef void(*OnMakeItemCurrentFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer);
typedef void(*OnStopBeingCurrentItemFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer);
typedef bool(*OnUseItemFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer); // return false if item is used up
typedef bool(*TryEquipFn)(struct Entity2D* pPlayer, struct GameFrameworkLayer* pLayer, enum WfEquipSlot slot);
typedef void (*ItemDrawDebugLinesFn)(struct Entity2D* pEnt, struct GameFrameworkLayer* pLayer, struct Transform2D* pCam, VECTOR(WorldspaceLineVertex)* outVerts, struct WfItemDef* pItemDef);
// An item definition might use this to initialize data from the atlas such as sprites or named tiles
typedef void(*OnPushGameLayerItemFnItemFn)(struct WfItemDef* pDef, struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);
typedef void(*OnPopGameLayerItemFnItemFn)(struct WfItemDef* pDef, struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);
enum WfItemConfigPropertyType
{
WfItemConfig_Float,
WfItemConfig_Int,
WfItemConfig_Bool,
WfItemConfig_String,
WfItemConfig_Array,
WfItemConfig_Bag,
};
struct WfItemConfigPropertyBag
{
struct HashMap properties;
bool bSet;
};
struct WfItemConfigProperty
{
char* name;
enum WfItemConfigPropertyType type;
union
{
float floatVal;
int intVal;
bool boolVal;
char* stringVal;
struct
{
int length;
struct WfItemConfigProperty* pData;
}propertyArray;
struct WfItemConfigPropertyBag bag;
}val;
};
struct WfItemDef
{
const char* UISpriteName;
void* pUserData;
OnMakeItemCurrentFn onMakeCurrent;
OnStopBeingCurrentItemFn onStopBeingCurrent;
OnUseItemFn onUseItem;
TryEquipFn onTryEquip;
OnPushGameLayerItemFnItemFn onGameLayerPush;
OnPushGameLayerItemFnItemFn onGameLayerPop;
ItemDrawDebugLinesFn drawDebugLines;
enum WfActionAnimation onUseAnimation;
bool bCanUseItem;
const char* pickupSpriteName;
bool bSoundEffectOnPickup;
struct ZZFXSound zzfxPickup;
char* itemName;
struct WfItemConfigPropertyBag config;
};
void WfAddItemDef(struct WfItemDef* pDef);
void WfAddBuiltinItems();
void WfInitItems();
void WfRegisterItemScriptFunctions();
const struct WfItemDef* WfGetItemDef(int itemIndex);
struct WfItemDef* WfGetItemDefs(int* numDefs);
struct WfItemConfigProperty* WfGetItemConfigProperty(struct WfItemConfigPropertyBag* pBag, const char* propertyName);
#endif