-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecipe.cpp
More file actions
46 lines (38 loc) · 1.16 KB
/
recipe.cpp
File metadata and controls
46 lines (38 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "recipe.h"
#include <iostream>
Recipe readRecipe(Json::Value root)
{
Recipe recipe;
recipe.name = root["name"].asString();
recipe.maxQuality = root["maxQuality"].asInt();
recipe.level = root["level"].asInt();
recipe.durability = root["durability"].asInt();
recipe.difficulty = root["difficulty"].asInt();
return recipe;
}
bool readRecipe(Json::Value root, CraftingClass craftingClass, std::string recipeName, Recipe & recipe)
{
std::string craftingClassString = craftingClassToString(craftingClass);
bool found = false;
if(root.isMember(craftingClassString))
{
Json::Value classRecipes = root[craftingClassString];
for(int i = 0; i < classRecipes.size(); ++i)
{
if(classRecipes[i]["name"]==recipeName)
{
recipe = readRecipe(classRecipes[i]);
found = true;
}
}
}
if(!found)
{
return false;
}
return true;
}
void Recipe::print()
{
std::cout << "Recipe: " << name << " level: " << level << " difficulty: " << difficulty << " max quality: " << maxQuality << " durability: " << durability << std::endl;
}