summaryrefslogtreecommitdiffstats
path: root/source/cInventory.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-31 22:30:14 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-31 22:30:14 +0100
commitc2b43f33da1461939df43657752ffd3651933b6e (patch)
tree7dd0f79d11496bd04bcebe6d2af83e77b6dbcfa4 /source/cInventory.cpp
parentdenotch map converter can now successfully converter an mcr to a vaild pak file. Takes about 20 seconds per region file. (diff)
downloadcuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar.gz
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar.bz2
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar.lz
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar.xz
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.tar.zst
cuberite-c2b43f33da1461939df43657752ffd3651933b6e.zip
Diffstat (limited to '')
-rw-r--r--source/cInventory.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/source/cInventory.cpp b/source/cInventory.cpp
index e78ac226e..788d38eaa 100644
--- a/source/cInventory.cpp
+++ b/source/cInventory.cpp
@@ -8,6 +8,8 @@
#include "cRecipeChecker.h"
#include "cRoot.h"
+#include <json/json.h>
+
#include "packets/cPacket_WindowClick.h"
#include "packets/cPacket_WholeInventory.h"
#include "packets/cPacket_InventorySlot.h"
@@ -340,25 +342,23 @@ void cInventory::DrawInventory()
}
}
-void cInventory::WriteToFile(FILE* a_File)
+void cInventory::SaveToJson(Json::Value & a_Value)
{
for(unsigned int i = 0; i < c_NumSlots; i++)
{
- cItem & Item = m_Slots[i];
- fwrite( &Item.m_ItemID, sizeof(Item.m_ItemID), 1, a_File );
- fwrite( &Item.m_ItemCount, sizeof(Item.m_ItemCount), 1, a_File );
- fwrite( &Item.m_ItemHealth, sizeof(Item.m_ItemHealth), 1, a_File );
+ Json::Value JSON_Item;
+ m_Slots[i].GetJson( JSON_Item );
+ a_Value.append( JSON_Item );
}
}
-bool cInventory::LoadFromFile(FILE* a_File)
+bool cInventory::LoadFromJson(Json::Value & a_Value)
{
- for(unsigned int i = 0; i < c_NumSlots; i++)
+ int SlotIdx = 0;
+ for( Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr )
{
- cItem & Item = m_Slots[i];
- if( fread( &Item.m_ItemID, sizeof(Item.m_ItemID), 1, a_File) != 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return false; }
- if( fread( &Item.m_ItemCount, sizeof(Item.m_ItemCount), 1, a_File) != 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return false; }
- if( fread( &Item.m_ItemHealth, sizeof(Item.m_ItemHealth), 1, a_File)!= 1 ) { LOGERROR("ERROR READING INVENTORY FROM FILE"); return false; }
+ m_Slots[SlotIdx].FromJson( *itr );
+ SlotIdx++;
}
return true;
}