-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDB.cpp
104 lines (83 loc) · 2.85 KB
/
DB.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include"DB.h"
namespace db {
void DB::setCharacter(character::Character& character) {
this->character = character;
}
void DB::load() {
//info
this->user.name = character.getName();
this->user.pointX = character.getPoint().x;
this->user.pointY = character.getPoint().y;
//property
this->user.money = character.getMoney();
/*
* vector struct ¾î¶»°Ô json¿¡ ´ãÀ»Áö
*/
this->user.stock = character.getStock();
//state
this->user.hp = character.getHP();
this->user.level = character.getLevel();
this->user.exp = this->character.getExp();
this->user.damage = this->character.getDamage();
this->user.armor = this->character.getArmor();
this->user.step = this->character.getStep();
}
void DB::fromJsonStock(std::string structName, screen::Stock& stock) {
static int i = 0;
this->data[structName]["Name"][std::to_string(i++)] = stock.getName();
this->data[structName]["CurrentPrice"][std::to_string(i++)] = stock.getCurrentPrice();
}
void DB::fromJsonItem(std::string structName, items::Items& items) {
static int i = 0;
this->data[structName]["Name"][std::to_string(i++)] = items.getName();
this->data[structName]["Authority"][std::to_string(i++)] = items.getAuthority();
}
void DB::fromJsonEquipments(std::string structName, equipments::Equipments& equipments) {
static int i = 0;
//this->data[structName]["Name"][std::to_string(i++)] = equipments.getName();
}
void DB::read(std::string fileName) {
fileName += ".json";
std::ifstream ifs(fileName);
ifs >> this->data;
}
void DB::serialization() {
load();
// [User]
std::string text = "User";
//info
data[text + "Name"] = this->user.name;
data[text + "PointX"] = this->user.pointX;
data[text + "PointY"] = this->user.pointY;
//property
data[text + "Money"] = this->user.money;
for (auto itr=this->user.stock.begin(); itr!=this->user.stock.end(); ++ itr){
this->fromJsonStock(text + "Stock", *itr);
}
//state
data[text + "HP"] = this->user.hp;
data[text + "Level"] = this->user.level;
data[text + "Exp"] = this->user.exp;
data[text + "Damage"] = this->user.damage;
data[text + "Armor"] = this->user.armor;
data[text + "Step"] = this->user.step;
//the others
data[text + "Job"]["Name"] = this->user.jobName;
data[text + "Job"]["Field"] = this->user.kindOfField;
data[text + "Job"]["Rate"] = this->user.rate;
data[text + "Job"]["Level"] = this->user.jobLevel;
data[text + "Job"]["Exp"] = this->user.jobExp;
for (auto itr = this->user.items.begin(); itr != this->user.items.end(); ++itr) {
this->fromJsonItem(text + "Item", *itr);
}
for (auto itr = this->user.equipments.begin(); itr != this->user.equipments.end(); ++itr) {
this->fromJsonEquipments(text + "Equipments", *itr);
}
std::ofstream o("TEST.json");
o << std::setw(4) << data << std::endl;
}
void DB::deserialization() {
}
void DB::write() {
}
}