From c2b43f33da1461939df43657752ffd3651933b6e Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 31 Oct 2011 21:30:14 +0000 Subject: Player data is saved and loaded as human readable JSON now. cFileFormatUpdate will loop through old files and convert them to new files (should replace legacy old format loading code) cItem has two new functions to load from Json and output Json, this will keep the items in Json standard ChestEntity and FurnaceEntity use the new functions in cItem git-svn-id: http://mc-server.googlecode.com/svn/trunk@35 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cInventory.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source/cInventory.cpp') 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 + #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; } -- cgit v1.2.3