1 #include "DefaultIMPPolicy.h"
2 
3 #include "ItemSystem.h"
4 #include "JsonObject.h"
5 #include "JsonUtility.h"
6 
7 #include <string_theory/string>
8 
9 struct ItemModel;
10 
readListOfItems(rapidjson::Value & value,std::vector<const ItemModel * > & items,const ItemSystem * itemSystem)11 static void readListOfItems(rapidjson::Value &value, std::vector<const ItemModel *> &items, const ItemSystem *itemSystem)
12 {
13 	std::vector<ST::string> strings;
14 	JsonUtility::parseListStrings(value, strings);
15 	for (const ST::string &str : strings)
16 	{
17 		items.push_back(itemSystem->getItemByName(str));
18 	}
19 }
20 
DefaultIMPPolicy(rapidjson::Document * json,const ItemSystem * itemSystem)21 DefaultIMPPolicy::DefaultIMPPolicy(rapidjson::Document *json, const ItemSystem *itemSystem)
22 {
23 	JsonUtility::parseListStrings((*json)["activation_codes"], m_activationCodes);
24 
25 	JsonObjectReader r(*json);
26 	m_startingLevel = r.getOptionalUInt("starting_level", 1);
27 
28 	readListOfItems((*json)["inventory"], m_inventory, itemSystem);
29 
30 	readListOfItems((*json)["if_good_shooter"], m_goodShooterItems, itemSystem);
31 	readListOfItems((*json)["if_normal_shooter"], m_normalShooterItems, itemSystem);
32 }
33 
isCodeAccepted(const ST::string & code) const34 bool DefaultIMPPolicy::isCodeAccepted(const ST::string& code) const
35 {
36 	for (auto& s : m_activationCodes)
37 	{
38 		if (s == code) return true;
39 	}
40 	return false;
41 }
42 
getStartingLevel() const43 uint8_t DefaultIMPPolicy::getStartingLevel() const
44 {
45 	return m_startingLevel;
46 }
47 
getInventory() const48 const std::vector<const ItemModel *> & DefaultIMPPolicy::getInventory() const
49 {
50 	return m_inventory;
51 }
52 
getGoodShooterItems() const53 const std::vector<const ItemModel *> & DefaultIMPPolicy::getGoodShooterItems() const
54 {
55 	return m_goodShooterItems;
56 }
57 
getNormalShooterItems() const58 const std::vector<const ItemModel *> & DefaultIMPPolicy::getNormalShooterItems() const
59 {
60 	return m_normalShooterItems;
61 }
62