diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index ec011f37..f6c92f4a 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -19,6 +19,7 @@ #include "Key.h" #include "Menu.h" #include "GameState.h" +#include "Item.h" INCLUDE_EMITTER_LIST @@ -102,6 +103,8 @@ bool Crawler::OnUserCreate(){ camera.SetTarget(player->GetPos()); camera.SetWorldBoundary({0,0},GetCurrentMap().MapSize*GetCurrentMap().TileSize); camera.EnableWorldBoundary(false); + + ItemInfo::InitializeItems(); InitializeGraphics(); diff --git a/Crawler/DEFINES.h b/Crawler/DEFINES.h index e22db22f..3174e98f 100644 --- a/Crawler/DEFINES.h +++ b/Crawler/DEFINES.h @@ -14,6 +14,7 @@ #define INCLUDE_TILE_ANIMATION_DATA extern std::map>>TILE_ANIMATION_DATA; #define INCLUDE_GFX extern safemapGFX; #define INCLUDE_ITEM_DATA extern safemapITEM_DATA; +#define INCLUDE_ITEM_CATEGORIES extern safemap>ITEM_CATEGORIES; #define ACCESS_PLAYER Player*p=game->GetPlayer(); diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 29286244..38b74cde 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -6,17 +6,105 @@ INCLUDE_game INCLUDE_DATA +INCLUDE_GFX safemapITEM_DATA; +safemap>ITEM_SCRIPTS; +safemap>ITEM_CATEGORIES; typedef std::string IT; +ItemInfo::ItemInfo() + :customProps({nullptr,nullptr}){} + void ItemInfo::InitializeItems(){ + + InitializeScripts(); + + for(auto&key:DATA["ItemCategory"].GetKeys()){ + ITEM_CATEGORIES[key.first]; + } + for(auto&key:DATA["ItemDatabase"].GetKeys()){ - std::cout<HasProperty(prop)) return (*customProps)[prop].GetInt(); + else return (*scriptProps)[prop].GetInt(); +}; +float ItemProps::GetFloatProp(std::string prop){ + if(customProps->HasProperty(prop)) return (*customProps)[prop].GetReal(); + else return (*scriptProps)[prop].GetReal(); +}; +std::string ItemProps::GetStringProp(std::string prop){ + if(customProps->HasProperty(prop)) return (*customProps)[prop].GetString(); + else return (*scriptProps)[prop].GetString(); +}; + +void ItemInfo::InitializeScripts(){ + ITEM_SCRIPTS["Restore"]=[](Crawler*game,ItemProps props){ + game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); + game->GetPlayer()->Heal(props.GetIntProp("HP % Restore")); + game->GetPlayer()->Heal(props.GetIntProp("HP Restore")); + game->GetPlayer()->Heal(props.GetIntProp("HP % Restore")); + return true; + }; + + ITEM_SCRIPTS.SetInitialized(); + std::cout< #include #include "olcPixelGameEngine.h" +#include "olcUTIL_DataFile.h" class Crawler; class ItemInfo; @@ -24,16 +25,36 @@ private: static std::mapinventory; }; +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); +}; + class ItemInfo{ std::string name; - std::string displayName; + std::string description; + std::string category; Decal*img; //Returns true if the item can be used, false otherwise - std::functionuseFunc; + std::string useFunc=""; + //Custom properties for this specific item's script. + static utils::datafile NOPROPS; + std::string script; + ItemProps customProps; + +private: + static void InitializeScripts(); public: static void InitializeItems(); + ItemInfo(); /* For the useFunc, return true if the item can be used, false otherwise. */ - ItemInfo(std::string name,std::string displayName,Decal*img,std::functionuseFunc); + //ItemInfo(std::string name,std::string description,std::string category,Decal*img,utils::datafile&props,std::string useFunc); }; \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 5a7d70c3..d68f14e3 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -701,6 +701,7 @@ void Player::SetIframes(float duration){ iframe_time=duration; } -void Player::SetMana(int mana){ - this->mana=std::clamp(mana,0,maxmana); +bool Player::Heal(int damage){ + hp=std::clamp(hp+damage,0,maxhp); + return true; } \ No newline at end of file diff --git a/Crawler/Player.h b/Crawler/Player.h index af675fe3..238942f7 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -134,7 +134,6 @@ public: bool CanAct(Ability&ability); void Knockback(vf2d vel); void SetIframes(float duration); - void SetMana(int mana); void AddBuff(BuffType type,float duration,float intensity); std::vectorGetBuffs(BuffType buff); @@ -143,6 +142,8 @@ public: void RemoveAllBuffs(); //Remove every buff. bool Hurt(int damage,bool onUpperLevel,float z); + //Return false if healing was not possible. + bool Heal(int damage); //specificClass is a bitwise-combination of classes from the Class enum. It makes sure certain animations only play if you are a certain class. void UpdateAnimation(std::string animState,int specificClass=ANY); Animate2D::Frame GetFrame(); diff --git a/Crawler/Version.h b/Crawler/Version.h index f560b929..2b3340fa 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1796 +#define VERSION_BUILD 1811 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/configuration.txt b/Crawler/assets/config/configuration.txt index 9d2ce96e..ed49527d 100644 --- a/Crawler/assets/config/configuration.txt +++ b/Crawler/assets/config/configuration.txt @@ -45,6 +45,9 @@ item_config = items/items.txt # Path to items configuration item_directory = items/ +# Path to items configuration +item_img_directory = items/ + # Whether or not to show individual data accesses from config data structure. debug_access_options = 0 diff --git a/Crawler/assets/config/items/ItemCategory.txt b/Crawler/assets/config/items/ItemCategory.txt index bcbc3ddf..719c2b5a 100644 --- a/Crawler/assets/config/items/ItemCategory.txt +++ b/Crawler/assets/config/items/ItemCategory.txt @@ -1,19 +1,8 @@ ItemCategory { - Consumables - { - Description = Items that will be consumed after a single use. - } - Equipment - { - Description = Gear that can be placed onto a player. - } - Accesories - { - Description = Items worn as extra items on the player. - } - Materials - { - Description = Items used as crafting materials for the forge. - } + # Random side note, these descriptions aren't used anywhere in-game atm. + Consumables = Items that will be consumed after a single use. + Equipment = Gear that can be placed onto a player. + Accesories = Items worn as extra items on the player. + Materials = Items used as crafting materials for the forge. } \ No newline at end of file