summaryrefslogtreecommitdiffstats
path: root/src/Item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Item.cpp')
-rw-r--r--src/Item.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/Item.cpp b/src/Item.cpp
index 9b17f1c37..412c66ec3 100644
--- a/src/Item.cpp
+++ b/src/Item.cpp
@@ -183,6 +183,31 @@ void cItem::GetJson(Json::Value & a_OutValue) const
a_OutValue["FadeColours"] = m_FireworkItem.FadeColoursToString(m_FireworkItem);
}
+ if (
+ !m_BookContent.IsEmpty() &&
+ (
+ (m_ItemType == E_ITEM_WRITTEN_BOOK) || (m_ItemType == E_ITEM_BOOK_AND_QUILL)
+ )
+ )
+ {
+ if (!m_BookContent.GetAuthor().empty())
+ {
+ a_OutValue["author"] = m_BookContent.GetAuthor();
+ }
+ if (!m_BookContent.GetTitle().empty())
+ {
+ a_OutValue["title"] = m_BookContent.GetTitle();
+ }
+ if (!m_BookContent.GetPages().empty())
+ {
+ a_OutValue["pages"] = Json::Value(Json::arrayValue);
+ for (const auto & Page : m_BookContent.GetPages())
+ {
+ a_OutValue["pages"].append(Page);
+ }
+ }
+ }
+
a_OutValue["RepairCost"] = m_RepairCost;
}
}
@@ -229,6 +254,19 @@ void cItem::FromJson(const Json::Value & a_Value)
m_FireworkItem.FadeColoursFromString(a_Value.get("FadeColours", "").asString(), m_FireworkItem);
}
+ if ((m_ItemType == E_ITEM_WRITTEN_BOOK) || (m_ItemType == E_ITEM_BOOK_AND_QUILL))
+ {
+ m_BookContent.SetAuthor(a_Value.get("author", "").asString());
+ m_BookContent.SetTitle(a_Value.get("title", "").asString());
+ if (a_Value.isMember("pages"))
+ {
+ for (Json::Value::ArrayIndex i = 0; i != a_Value["pages"].size(); i++)
+ {
+ m_BookContent.AddPage(a_Value["pages"][i].asString());
+ }
+ }
+ }
+
m_RepairCost = a_Value.get("RepairCost", 0).asInt();
}
}