Setup Items, item categories, and item scripts, and all associated configuration files for them.

pull/28/head
sigonasr2 1 year ago
parent c1d64e7bd1
commit 877c44c372
  1. 8
      Crawler/Crawler.cpp
  2. 7
      Crawler/Crawler.vcxproj
  3. 24
      Crawler/Crawler.vcxproj.filters
  4. 1
      Crawler/DEFINES.h
  5. 38
      Crawler/Item.cpp
  6. 39
      Crawler/Item.h
  7. 19
      Crawler/ItemComponent.h
  8. 25
      Crawler/Menu.cpp
  9. 6
      Crawler/Menu.h
  10. 2
      Crawler/Version.h
  11. 6
      Crawler/assets/config/configuration.txt
  12. 2
      Crawler/assets/config/gfx/themes.txt
  13. 19
      Crawler/assets/config/items/ItemCategory.txt
  14. 67
      Crawler/assets/config/items/ItemDatabase.txt
  15. 14
      Crawler/assets/config/items/ItemScript.txt
  16. 6
      Crawler/assets/config/items/items.txt
  17. BIN
      Crawler/assets/items/Bandages.png
  18. BIN
      Crawler/assets/items/Blue Slime Remains.png
  19. BIN
      Crawler/assets/items/Green Slime Remains.png
  20. BIN
      Crawler/assets/items/Large Health Potion.png
  21. BIN
      Crawler/assets/items/Large Mana Potion.png
  22. BIN
      Crawler/assets/items/Medium Health Potion.png
  23. BIN
      Crawler/assets/items/Medium Mana Potion.png
  24. BIN
      Crawler/assets/items/Red Slime Remains.png
  25. BIN
      Crawler/assets/items/Small Health Potion.png
  26. BIN
      Crawler/assets/items/Small Mana Potion.png
  27. 1
      Crawler/safemap.h

@ -72,6 +72,14 @@ Crawler::Crawler()
std::string THEMES_CONFIG = CONFIG_PATH + "themes_config"_S;
utils::datafile::Read(DATA,THEMES_CONFIG);
std::string ITEM_CONFIG = CONFIG_PATH + "item_config"_S;
utils::datafile::Read(DATA,ITEM_CONFIG);
for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key.first].GetString();
utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config);
}
DEBUG_PATHFINDING="debug_pathfinding"_I;
for(std::string&cl:DATA.GetProperty("class_list").GetValues()){

@ -272,6 +272,8 @@
<ClInclude Include="Effect.h" />
<ClInclude Include="Emitter.h" />
<ClInclude Include="GameState.h" />
<ClInclude Include="Item.h" />
<ClInclude Include="ItemComponent.h" />
<ClInclude Include="MenuIconButton.h" />
<ClInclude Include="MenuLabel.h" />
<ClInclude Include="MenuType.h" />
@ -314,6 +316,7 @@
<ClCompile Include="FallingDebris.h" />
<ClCompile Include="FireBolt.cpp" />
<ClCompile Include="GameState.cpp" />
<ClCompile Include="Item.cpp" />
<ClCompile Include="Key.cpp" />
<ClCompile Include="LightningBolt.cpp" />
<ClCompile Include="LightningBoltEmitter.cpp" />
@ -359,6 +362,10 @@
<Text Include="assets\config\configuration.txt" />
<Text Include="assets\config\gfx\gfx.txt" />
<Text Include="assets\config\gfx\themes.txt" />
<Text Include="assets\config\items\ItemCategory.txt" />
<Text Include="assets\config\items\ItemDatabase.txt" />
<Text Include="assets\config\items\items.txt" />
<Text Include="assets\config\items\ItemScript.txt" />
<Text Include="assets\config\levels.txt" />
<Text Include="assets\config\Monsters.txt" />
<Text Include="assets\config\MonsterStrategies.txt" />

@ -52,6 +52,9 @@
<Filter Include="Source Files\Game States">
<UniqueIdentifier>{f36af2ba-e884-4e50-b7bd-7e6aa9a8528c}</UniqueIdentifier>
</Filter>
<Filter Include="Configurations\Items">
<UniqueIdentifier>{09fc0cbe-06f7-4fdf-944c-9833066bb9c8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="olcPixelGameEngine.h">
@ -177,6 +180,12 @@
<ClInclude Include="GameState.h">
<Filter>Header Files\Game States</Filter>
</ClInclude>
<ClInclude Include="ItemComponent.h">
<Filter>Header Files\Interface</Filter>
</ClInclude>
<ClInclude Include="Item.h">
<Filter>Configurations</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">
@ -308,6 +317,9 @@
<ClCompile Include="State_MainMenu.cpp">
<Filter>Source Files\Game States</Filter>
</ClCompile>
<ClCompile Include="Item.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
@ -362,6 +374,18 @@
<Text Include="assets\config\gfx\themes.txt">
<Filter>Configurations\GFX</Filter>
</Text>
<Text Include="assets\config\items\ItemDatabase.txt">
<Filter>Configurations\Items</Filter>
</Text>
<Text Include="assets\config\items\ItemScript.txt">
<Filter>Configurations\Items</Filter>
</Text>
<Text Include="assets\config\items\ItemCategory.txt">
<Filter>Configurations\Items</Filter>
</Text>
<Text Include="assets\config\items\items.txt">
<Filter>Configurations\Items</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<Image Include="assets\heart.ico">

@ -13,6 +13,7 @@
#define INCLUDE_STRATEGY_ID_DATA extern safemap<std::string,int>STRATEGY_ID_DATA;
#define INCLUDE_TILE_ANIMATION_DATA extern std::map<int,std::vector<std::pair<int,float>>>TILE_ANIMATION_DATA;
#define INCLUDE_GFX extern safemap<std::string,Renderable>GFX;
#define INCLUDE_ITEM_DATA extern safemap<Item::ItemName,ItemInfo>ITEM_DATA;
#define ACCESS_PLAYER Player*p=game->GetPlayer();

@ -0,0 +1,38 @@
#pragma once
#include "Item.h"
#include "safemap.h"
#include "DEFINES.h"
#include "Crawler.h"
INCLUDE_game
INCLUDE_DATA
safemap<std::string,ItemInfo>ITEM_DATA;
typedef std::string IT;
void ItemInfo::InitializeItems(){
for(auto&key:DATA["ItemDatabase"].GetKeys()){
std::cout<<key.first<<std::endl;
}
ITEM_DATA.SetInitialized();
}
void Inventory::AddItem(IT it,int amt){
}
void Inventory::GetItemCount(IT it){
}
void Inventory::UseItem(IT it,int amt)
{
}
void Inventory::RemoveItem(IT it,int amt)
{
}

@ -0,0 +1,39 @@
#pragma once
#include <string>
#include <functional>
#include <map>
#include "olcPixelGameEngine.h"
class Crawler;
class ItemInfo;
class Item{
private:
int amt;
ItemInfo*it;
};
class Inventory{
public:
void AddItem(std::string it,int amt=1);
void GetItemCount(std::string it);
void UseItem(std::string it,int amt=1);
void RemoveItem(std::string it,int amt=1);
private:
static std::map<std::string,Item>inventory;
};
class ItemInfo{
std::string name;
std::string displayName;
Decal*img;
//Returns true if the item can be used, false otherwise
std::function<bool(Crawler*)>useFunc;
public:
static void InitializeItems();
/*
For the useFunc, return true if the item can be used, false otherwise.
*/
ItemInfo(std::string name,std::string displayName,Decal*img,std::function<bool(Crawler*)>useFunc);
};

@ -0,0 +1,19 @@
#pragma once
#include "MenuIconButton.h"
#include "Item.h"
INCLUDE_game
class ItemComponent:public MenuIconButton{
Item::ItemName item;
public:
inline ItemComponent(geom2d::rect<float>rect,Item::ItemName*item,MenuFunc onClick)
:MenuIconButton(rect,,onClick){}
protected:
virtual void inline Update(Crawler*game)override{
MenuIconButton::Update(game);
}
virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{
MenuIconButton::Draw(game,parentPos,focused);
}
};

@ -45,6 +45,23 @@ void Menu::AddComponent(std::string key,MenuComponent*button){
components[key]=button;
}
void Menu::CheckClickAndPerformMenuSelect(Crawler*game){
if(game->GetMouse(Mouse::LEFT).bReleased||game->GetKey(SPACE).bReleased||game->GetKey(ENTER).bReleased){
MenuSelect(game);
}
}
void Menu::HoverMenuSelect(Crawler*game){
if(selection==vi2d{-1,-1})return;
if(buttons[selection.y][selection.x]->draggable)
if(buttonHoldTime<0.3)CheckClickAndPerformMenuSelect(game);
else{
draggingComponent=buttons[selection.y][selection.x];
buttons[selection.y].erase(buttons[selection.y].begin()+selection.x);
}
else CheckClickAndPerformMenuSelect(game);
}
void Menu::MenuSelect(Crawler*game){
if(selection==vi2d{-1,-1})return;
buttons[selection.y][selection.x]->onClick(*this,game);
@ -60,6 +77,10 @@ void Menu::MenuSelect(Crawler*game){
void Menu::Update(Crawler*game){
buttonHoldTime+=game->GetElapsedTime();
HoverMenuSelect(game);
for(auto&key:buttons){
for(auto&button:key.second){
button->hovered=false;
@ -207,7 +228,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
if(game->GetMouse(0).bPressed||game->GetKey(ENTER).bPressed||game->GetKey(SPACE).bPressed){
MOUSE_NAVIGATION=game->GetMouse(0).bPressed; //If a click occurs we use mouse controls.
if(!MOUSE_NAVIGATION){
MenuSelect(game);
buttonHoldTime=0;
//Key presses automatically highlight the first button if it's not highlighted.
if(selection==vi2d{-1,-1}&&buttons.size()>0){
//Find the first possible button entry in the map...
@ -234,7 +255,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
index++;
}
}
MenuSelect(game);
buttonHoldTime=0;
}
}
}

@ -14,12 +14,16 @@ class Menu:IAttributable{
static bool MOUSE_NAVIGATION;
static std::map<MenuType,Menu>menus;
float buttonHoldTime=0;
std::map<int/*Y*/,std::vector<MenuComponent*>>buttons; //Buttons are stored in rows followed by their column order.
std::map<int/*Y*/,std::vector<MenuComponent*>>newButtonArrangement; //The new setup that the buttons will be at if a drag operation completes.
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in.
vi2d selection={-1,-1};
vf2d pos; //Specify the upper-left corner of the window. Using CENTERED will always put this where the upper-left corner would center the window.
vf2d size; //Size in tiles (24x24), every menu will be tile-based
MenuComponent*draggingComponent=nullptr;
public:
Menu();
Menu(vf2d pos,vf2d size);
@ -33,7 +37,9 @@ public:
static safeunorderedmap<std::string,Theme>themes;
static const vf2d CENTERED;
private:
void HoverMenuSelect(Crawler*game);
void MenuSelect(Crawler*game);
void CheckClickAndPerformMenuSelect(Crawler*game);
static const Menu InitializeTestMenu();
static const Menu InitializeTestSubMenu();
//X (0-3), Y (0-2) for specific 9-patch tile (tiled version).

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 1782
#define VERSION_BUILD 1796
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -39,6 +39,12 @@ class_directory = classes/
# Class list to be loaded into the game.
class_list = Warrior, Thief, Ranger, Trapper, Wizard, Witch
# Items Config
item_config = items/items.txt
# Path to items configuration
item_directory = items/
# Whether or not to show individual data accesses from config data structure.
debug_access_options = 0

@ -4,6 +4,8 @@ ThemeGlobal
HighlightTime = 0.2
# How much the R,G,B color components of a menu are multiplied to unfocused windows.
MenuUnfocusedColorMult = 0.4
# Amount of time to hold down an element before a press becomes a drag.
MenuHoldTime = 0.3
}
Themes

@ -0,0 +1,19 @@
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.
}
}

@ -0,0 +1,67 @@
ItemDatabase
{
Small Health Potion
{
ItemScript = Restore
Description = Restores 40 health points.
HP Restore = 40
ItemCategory = Consumables
}
Medium Health Potion
{
ItemScript = Restore
Description = Restores 100 health points.
HP Restore = 100
ItemCategory = Consumables
}
Large Health Potion
{
ItemScript = Restore
Description = Restores 320 health points.
HP Restore = 320
ItemCategory = Consumables
}
Small Mana Potion
{
ItemScript = Restore
Description = Restores 40 mana points.
MP Restore = 40
ItemCategory = Consumables
}
Medium Mana Potion
{
ItemScript = Restore
Description = Restores 100 mana points.
MP Restore = 100
ItemCategory = Consumables
}
Large Mana Potion
{
ItemScript = Restore
Description = Restores 320 mana points.
MP Restore = 320
ItemCategory = Consumables
}
Bandages
{
ItemScript = Restore
Description = Restores 10% health points.
HP % Restore = 10%
ItemCategory = Consumables
}
Green Slime Remains
{
Description = The remains of a green slime. It stares at you intently.
ItemCategory = Materials
}
Blue Slime Remains
{
Description = The remains of a blue slime. It stares at you intently.
ItemCategory = Materials
}
Red Slime Remains
{
Description = The remains of a red slime. It stares at you intently.
ItemCategory = Materials
}
}

@ -0,0 +1,14 @@
ItemScript
{
# Used with the Item Database.
# Any of these properties can be overwritten by specifying them in the main item.
# Restores stats.
Restore
{
HP Restore = 0
HP % Restore = 0
MP Restore = 0
MP % Restore = 0
}
}

@ -0,0 +1,6 @@
ItemConfiguration
{
Item Database = "ItemDatabase.txt"
Item Scripts = "ItemScript.txt"
Item Categories = "ItemCategory.txt"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

@ -1,5 +1,4 @@
#pragma once
#include "olcPixelGameEngine.h"
//A class that has an initialization lock so that when the lock is activated, any further gets that are missing items in it will report themselves for easier debugging detection.
template<typename T,typename O>

Loading…
Cancel
Save