forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay_view.h
76 lines (67 loc) · 1.85 KB
/
replay_view.h
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
#ifndef _REPLAY_VIEW
#define _REPLAY_VIEW
template <class T>
class ReplayView : public T {
public:
ReplayView(ifstream& iff) : input(iff) {
}
virtual void close() override {
input.close();
T::close();
}
virtual Action getAction() override {
// T::getAction();
// usleep(300000);
string method;
Action action;
input >> method >> action;
if (method == "exit")
exit(0);
CHECKEQ(method, "getAction");
return action;
}
virtual Optional<int> chooseFromList(const string& title, const vector<View::ListElem>& options, int index,
Optional<ActionId> a) override {
string method;
string action;
input >> method >> action;
CHECKEQ(method, "chooseFromList");
if (action == "nothing")
return Nothing();
else
return convertFromString<int>(action);
}
virtual Optional<Vec2> chooseDirection(const string& message) override {
string method;
string action;
input >> method >> action;
CHECKEQ(method, "chooseDirection");
if (action == "nothing")
return Nothing();
else {
vector<string> s = split(action, ',');
CHECKEQ((int)s.size(), 2);
return Vec2(convertFromString<int>(s[0]), convertFromString<int>(s[1]));
}
}
virtual bool yesOrNoPrompt(const string& message) override {
string method;
bool action;
input >> method >> action;
CHECKEQ(method, "yesOrNoPrompt");
return action;
}
virtual Optional<int> getNumber(const string& title, int max) {
string method;
string action;
input >> method >> action;
CHECKEQ(method, "getNumber");
if (action == "nothing")
return Nothing();
else
return convertFromString<int>(action);
}
private:
ifstream& input;
};
#endif