Adds ItemTableManager class.

This commit is contained in:
Christopher Leggett 2022-07-31 23:26:48 -04:00
parent b98c8b4abb
commit 4a87ed709b
No known key found for this signature in database
GPG Key ID: 7093AE5FF7037D79
4 changed files with 108 additions and 2 deletions

53
soh/ItemTableManager.cpp Normal file
View File

@ -0,0 +1,53 @@
#include "ItemTableManager.h"
ItemTableManager::ItemTableManager() {
}
ItemTableManager::~ItemTableManager() {
this->itemTables.clear();
}
bool ItemTableManager::AddItemTable(std::string tableID) {
ItemTable newItemTable;
return itemTables.emplace(tableID, newItemTable).second;
}
bool ItemTableManager::AddItemEntry(std::string tableID, uint8_t getItemID, uint8_t itemID, uint16_t objectID,
int8_t drawID,
uint8_t textID, uint8_t field, bool chestAnim) {
ItemTable* itemTable = RetrieveItemTable(tableID);
if (itemTable == NULL) {
return false;
}
GetItemEntry getItemEntry = GET_ITEM(itemID, objectID, drawID, textID, field, chestAnim);
return itemTable->emplace(getItemID, getItemEntry).second;
}
GetItemEntry ItemTableManager::RetrieveItemEntry(std::string tableID, uint8_t itemID) {
ItemTable* itemTable = RetrieveItemTable(tableID);
if (itemTable != NULL) {
auto foundItemEntry = itemTable->find(itemID);
if (foundItemEntry != itemTable->end()) {
return foundItemEntry->second;
}
}
return GET_ITEM_NONE;
}
bool ItemTableManager::ClearItemTable(std::string tableID) {
ItemTable* itemTable = RetrieveItemTable(tableID);
if (itemTable != NULL) {
itemTable->clear();
return true;
}
return false;
}
ItemTable* ItemTableManager::RetrieveItemTable(std::string tableID) {
auto foundItemTable = itemTables.find(tableID);
if (foundItemTable == itemTables.end()) {
return nullptr;
}
ItemTable& itemTable = foundItemTable->second;
return &itemTable;
}

40
soh/ItemTableManager.h Normal file
View File

@ -0,0 +1,40 @@
#pragma once
#include <unordered_map>
#include "z64item.h"
#include "z64object.h"
#define CHEST_ANIM_SHORT 0
#define CHEST_ANIM_LONG 1
typedef struct {
/* 0x00 */ uint8_t itemId;
/* 0x01 */ uint8_t field; // various bit-packed data
/* 0x02 */ int8_t gi; // defines the draw id and chest opening animation
/* 0x03 */ uint8_t textId;
/* 0x04 */ uint16_t objectId;
} GetItemEntry; // size = 0x06
#define GET_ITEM(itemId, objectId, drawId, textId, field, chestAnim) \
{ itemId, field, (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId }
#define GET_ITEM_NONE \
{ ITEM_NONE, 0, 0, 0, OBJECT_INVALID }
typedef std::unordered_map<uint8_t, GetItemEntry> ItemTable;
class ItemTableManager {
public:
static ItemTableManager* Instance;
ItemTableManager();
~ItemTableManager();
bool AddItemTable(std::string tableID);
bool AddItemEntry(std::string tableID, uint8_t getItemID, uint8_t itemID, uint16_t objectID, int8_t drawID,
uint8_t textID, uint8_t field, bool chestAnim);
GetItemEntry RetrieveItemEntry(std::string tableID, uint8_t itemID);
bool ClearItemTable(std::string tableID);
private:
std::unordered_map<std::string, ItemTable> itemTables;
ItemTable* RetrieveItemTable(std::string tableID);
};

View File

@ -179,6 +179,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ItemTableManager.cpp" />
<ClCompile Include="soh\Enhancements\cosmetics\CosmeticsEditor.cpp" />
<ClCompile Include="soh\Enhancements\debugger\actorViewer.cpp" />
<ClCompile Include="soh\Enhancements\gfx.c" />
@ -941,9 +942,9 @@
<ClCompile Include="src\overlays\misc\ovl_kaleido_scope\z_lmap_mark.c" />
<ClCompile Include="src\overlays\misc\ovl_kaleido_scope\z_lmap_mark_data.c" />
<ClCompile Include="src\overlays\misc\ovl_map_mark_data\z_map_mark_data.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ItemTableManager.h" />
<ClInclude Include="soh\Enhancements\cosmetics\CosmeticsEditor.h" />
<ClInclude Include="soh\Enhancements\debugger\actorViewer.h" />
<ClCompile Include="soh\Enhancements\randomizer\randomizer.h" />

View File

@ -82,6 +82,12 @@
<Filter Include="Source Files\soh\Enhancements\debugger">
<UniqueIdentifier>{04fc1c52-49ff-48e2-ae23-2c00867374f8}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\soh\Enhancements\item-tables">
<UniqueIdentifier>{01811baa-7b90-4452-8ef0-d4cdc5dbdebd}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\soh\Enhancements\item-tables">
<UniqueIdentifier>{1f217bdc-2227-4079-a077-bcab7f7d1481}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\boot\assert.c">
@ -2373,6 +2379,9 @@
<ClCompile Include="soh\Enhancements\randomizer\randomizer_item_tracker.cpp">
<Filter>Source Files\src</Filter>
</ClCompile>
<ClCompile Include="ItemTableManager.cpp">
<Filter>Source Files\soh\Enhancements\item-tables</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\overlays\actors\ovl_kaleido_scope\z_kaleido_scope.h">
@ -4058,6 +4067,9 @@
<ClInclude Include="soh\Enhancements\randomizer\randomizer_item_tracker.h">
<Filter>Source Files\src</Filter>
</ClInclude>
<ClInclude Include="ItemTableManager.h">
<Filter>Header Files\soh\Enhancements\item-tables</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="SHIPOFHARKINIAN.ico" />
@ -4070,4 +4082,4 @@
<ItemGroup>
<None Include="include\macro.inc" />
</ItemGroup>
</Project>
</Project>