-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_data.cpp
157 lines (127 loc) · 6.73 KB
/
app_data.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <cstdio>
#include <cstring>
#include "app.h"
#include "app_data.h"
AppData::AppData() {
filename = "ascii-paint.cfg";
}
AppData::~AppData() {
}
void AppData::load() {
TCODParser parser;
TCODParserStruct *windowTypeStruct = parser.newStructure("window");
windowTypeStruct->addProperty("width", TCOD_TYPE_INT, true);
windowTypeStruct->addProperty("height", TCOD_TYPE_INT, true);
windowTypeStruct->addProperty("fullscreen", TCOD_TYPE_BOOL, true);
windowTypeStruct->addProperty("background_color", TCOD_TYPE_COLOR, true);
windowTypeStruct->addProperty("fps", TCOD_TYPE_INT, true);
TCODParserStruct *canvasTypeStruct = parser.newStructure("canvas");
canvasTypeStruct->addProperty("width", TCOD_TYPE_INT, true);
canvasTypeStruct->addProperty("height", TCOD_TYPE_INT, true);
TCODParserStruct *fontTypeStruct = parser.newStructure("font");
fontTypeStruct->addProperty("file", TCOD_TYPE_STRING, true);
fontTypeStruct->addProperty("layout", TCOD_TYPE_STRING, true);
fontTypeStruct->addProperty("type", TCOD_TYPE_STRING, true);
TCODParserStruct *brushesTypeStruct = parser.newStructure("brushes");
brushesTypeStruct->addProperty("fore1", TCOD_TYPE_COLOR, true);
brushesTypeStruct->addProperty("back1", TCOD_TYPE_COLOR, true);
brushesTypeStruct->addProperty("symbol1", TCOD_TYPE_CHAR, true);
brushesTypeStruct->addProperty("solid1", TCOD_TYPE_BOOL, true);
brushesTypeStruct->addProperty("fore2", TCOD_TYPE_COLOR, true);
brushesTypeStruct->addProperty("back2", TCOD_TYPE_COLOR, true);
brushesTypeStruct->addProperty("symbol2", TCOD_TYPE_CHAR, true);
brushesTypeStruct->addProperty("solid2", TCOD_TYPE_BOOL, true);
TCODParserStruct *guiTypeStruct = parser.newStructure("gui");
guiTypeStruct->addProperty("background_color1", TCOD_TYPE_COLOR, true);
guiTypeStruct->addProperty("background_color2", TCOD_TYPE_COLOR, true);
guiTypeStruct->addProperty("foreground_color1", TCOD_TYPE_COLOR, true);
guiTypeStruct->addProperty("foreground_color2", TCOD_TYPE_COLOR, true);
parser.run(filename.c_str(), NULL);
app->windowWidth = parser.getIntProperty("window.width");
app->windowHeight = parser.getIntProperty("window.height");
app->fullscreen = parser.getBoolProperty("window.fullscreen");
app->windowBackgroundColor = parser.getColorProperty("window.background_color");
app->fpsGoal = parser.getIntProperty("window.fps");
app->fontFilename = parser.getStringProperty("font.file");
if(!strcmp(parser.getStringProperty("font.layout"), "tcod")) {
app->fontLayout = TCOD_FONT_LAYOUT_TCOD;
} else if(!strcmp(parser.getStringProperty("font.layout"), "inrow")) {
app->fontLayout = TCOD_FONT_LAYOUT_ASCII_INROW;
} else {
app->fontLayout = TCOD_FONT_LAYOUT_ASCII_INCOL;
}
if(!strcmp(parser.getStringProperty("font.type"), "greyscale")) {
app->fontType = TCOD_FONT_TYPE_GREYSCALE;
} else {
app->fontType = 0;
}
app->canvasWidth = parser.getIntProperty("canvas.width");
app->canvasHeight = parser.getIntProperty("canvas.height");
app->initBrush1.fore = parser.getColorProperty("brushes.fore1");
app->initBrush1.back = parser.getColorProperty("brushes.back1");
app->initBrush1.symbol = parser.getCharProperty("brushes.symbol1");
app->initBrush1.solid = parser.getBoolProperty("brushes.solid1");
app->initBrush2.fore = parser.getColorProperty("brushes.fore2");
app->initBrush2.back = parser.getColorProperty("brushes.back2");
app->initBrush2.symbol = parser.getCharProperty("brushes.symbol2");
app->initBrush2.solid = parser.getBoolProperty("brushes.solid2");
app->gui->backgroundColor1 = parser.getColorProperty("gui.background_color1");
app->gui->backgroundColor2 = parser.getColorProperty("gui.background_color2");
app->gui->foregroundColor1 = parser.getColorProperty("gui.foreground_color1");
app->gui->foregroundColor2 = parser.getColorProperty("gui.foreground_color2");
}
void AppData::save() {
FILE *fp = fopen(filename.c_str(), "w");
if(fp == NULL) {
printf("Could not write config file.\n");
return;
}
fprintf(fp, "// ASCII-Paint 0.3 config file\n");
fprintf(fp, "window {\n"); {
fprintf(fp, "\twidth = %i\n", app->windowWidth);
fprintf(fp, "\theight = %i\n", app->windowHeight);
fprintf(fp, "\tfullscreen = %s\n", app->fullscreen ? "true" : "false");
fprintf(fp, "\tbackground_color = \"%i, %i, %i\"\n", app->windowBackgroundColor.r, app->windowBackgroundColor.g, app->windowBackgroundColor.b);
fprintf(fp, "\tfps = %i\n", app->fpsGoal);
} fprintf(fp, "}\n");
fprintf(fp, "\n");
fprintf(fp, "font {\n"); {
fprintf(fp, "\tfile = \"%s\"\n", app->fontFilename.c_str());
if(app->fontLayout == TCOD_FONT_LAYOUT_ASCII_INCOL)
fprintf(fp, "\tlayout = \"%s\"\n", "incol");
else if(app->fontLayout == TCOD_FONT_LAYOUT_ASCII_INROW)
fprintf(fp, "\tlayout = \"%s\"\n", "inrow");
else if(app->fontLayout == TCOD_FONT_LAYOUT_TCOD)
fprintf(fp, "\tlayout = \"%s\"\n", "incol");
if(app->fontType == TCOD_FONT_TYPE_GREYSCALE)
fprintf(fp, "\ttype = \"%s\"\n", "greyscale");
else
fprintf(fp, "\ttype = \"%s\"\n", "normal");
} fprintf(fp, "}\n");
fprintf(fp, "\n");
fprintf(fp, "canvas {\n"); {
fprintf(fp, "\twidth = %i\n", app->canvasWidth);
fprintf(fp, "\theight = %i\n", app->canvasHeight);
} fprintf(fp, "}\n");
fprintf(fp, "\n");
fprintf(fp, "brushes {\n"); {
fprintf(fp, "\tfore1 = \"%i, %i, %i\"\n", app->initBrush1.fore.r, app->initBrush1.fore.g, app->initBrush1.fore.b);
fprintf(fp, "\tback1 = \"%i, %i, %i\"\n", app->initBrush1.back.r, app->initBrush1.back.g, app->initBrush1.back.b);
fprintf(fp, "\tsymbol1 = '%c'\n", app->initBrush1.symbol);
fprintf(fp, "\tsolid1 = %s\n", app->initBrush1.solid ? "true" : "false");
fprintf(fp, "\tfore2 = \"%i, %i, %i\"\n", app->initBrush2.fore.r, app->initBrush2.fore.g, app->initBrush2.fore.b);
fprintf(fp, "\tback2 = \"%i, %i, %i\"\n", app->initBrush2.back.r, app->initBrush2.back.g, app->initBrush2.back.b);
fprintf(fp, "\tsymbol2 = '%c'\n", app->initBrush2.symbol);
fprintf(fp, "\tsolid2 = %s\n", app->initBrush2.solid ? "true" : "false");
} fprintf(fp, "}\n");
fprintf(fp, "\n");
fprintf(fp, "gui {\n"); {
fprintf(fp, "\tbackground_color1 = \"%i, %i, %i\"\n", app->gui->backgroundColor1.r, app->gui->backgroundColor1.g, app->gui->backgroundColor1.b);
fprintf(fp, "\tbackground_color2 = \"%i, %i, %i\"\n", app->gui->backgroundColor2.r, app->gui->backgroundColor2.g, app->gui->backgroundColor2.b);
fprintf(fp, "\tforeground_color1 = \"%i, %i, %i\"\n", app->gui->foregroundColor1.r, app->gui->foregroundColor1.g, app->gui->foregroundColor1.b);
fprintf(fp, "\tforeground_color2 = \"%i, %i, %i\"\n", app->gui->foregroundColor2.r, app->gui->foregroundColor2.g, app->gui->foregroundColor2.b);
} fprintf(fp, "}\n");
fclose(fp);
}
void AppData::setFilename(char *name) {
}