-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.cpp
More file actions
102 lines (87 loc) · 3.04 KB
/
Copy pathedit.cpp
File metadata and controls
102 lines (87 loc) · 3.04 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
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
#include<iostream>
#include<vector>
#include<fstream>
#include "parsing.h"
#include "play.h"
#include "logging.h"
using namespace std;
vector<string> getSitsShortname(vector<Situation> sits) {
vector<string> tempStr;
for (Situation sit : sits) {
tempStr.push_back(to_string(sit.situationNum) + ": " + sit.title);
}
return tempStr;
}
vector<string> getOptsShortname(Situation sit) {
vector<string> tempStr;
for (Option opt : sit.options) {
tempStr.push_back(to_string(opt.referSituationNum) + " <- " + opt.optionText);
}
return tempStr;
}
size_t listOptionsPlus(string title, vector<string> extra, string type, vector<Situation> game, size_t sitnumforopts) {
vector<string> toShow = extra;
if (type == "sits") {
vector<string> sitsShortName = getSitsShortname(game);
toShow.insert(toShow.end(), sitsShortName.begin(), sitsShortName.end());
dbg(LOG_NOTE, "SituationOptions added to list (listOptionsPlus).");
} else if (type == "opts") {
vector<string> optsShortName = getOptsShortname(game[sitnumforopts]);
toShow.insert(toShow.end(), optsShortName.begin(), optsShortName.end());
dbg(LOG_NOTE, "OptionOptions added to list (listOptionsPlus).");
} else {
dbg(LOG_WARNING, "Unknown type in listOptionsPlus: " + type);
}
return showOptions(toShow, title);
}
void addOptToSit(Situation& sit, vector<Situation> game, int optNumm) {
if (optNumm != 0) {
cout << "Option " << optNumm << ": ";
} else {
cout << "Option text: ";
}
string optionText;
if (cin.peek() == '\n') { // Only clear the buffer if necessary
cin.ignore();
}
getline(cin, optionText);
dbg(LOG_NOTE, "(addOptToSit) got optionText: " + optionText);
size_t refSitNum = listOptionsPlus("Choose where this option will lead:", {"0: END GAME"}, "sits", game, 0);
dbg(LOG_NOTE, "Option refers to situation number: " + to_string(refSitNum));
sit.options.push_back({optionText, refSitNum});
dbg(LOG_NOTE, "Added option to situation " + sit.title);
}
void newSit(vector<Situation>& game) {
cout << "\033[2J\033[H"; // clear screen
Situation tempSit;
if (game.size() == 0) { tempSit.situationNum = 1; } else { // Set sitnum to 1 if game is empty (first situation)
tempSit.situationNum = game[game.size() - 1].situationNum + 1;
}
dbg(LOG_NOTE, "New situation number: " + to_string(tempSit.situationNum));
string tempTitle;
cout << "Situation Title: ";
if (cin.peek() == '\n') { // Only clear the buffer if necessary
cin.ignore();
}
getline(cin, tempTitle);
tempSit.title = tempTitle;
dbg(LOG_NOTE, "Got situation title: " + tempTitle);
cout << "amount of options (default 2): ";
string strOptsNum;
getline(cin, strOptsNum);
int amountOpts = 2;
if (!strOptsNum.empty()) {
try {
amountOpts = stoi(strOptsNum);
}
catch (const exception& e) {
dbg(LOG_WARNING, "Error converting options amount, defaulting to 2: " + string(e.what()));
}
}
dbg(LOG_NOTE, "Amount of options to add: " + to_string(amountOpts));
for (int i = 1; i <= amountOpts; i++) {
addOptToSit(tempSit, game, 0);
}
dbg(LOG_NOTE, "New Situation created: " + tempSit.title);
game.push_back(tempSit);
}