-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnluck.h
69 lines (61 loc) · 1.59 KB
/
Unluck.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
#ifndef UNLUCK_H
#define UNLUCK_H
#include "complication.h"
class Unluck: public Complication
{
public:
Unluck(): Complication() { }
Unluck(const Unluck& ac)
: Complication()
, v(ac.v) { }
Unluck(Unluck&& ac)
: Complication()
, v(ac.v) { }
Unluck(const QJsonObject& json)
: Complication()
, v { json["dice"].toInt(0) } { }
Unluck& operator=(const Unluck& ac) {
if (this != &ac) v = ac.v;
return *this;
}
Unluck& operator=(Unluck&& ac) {
v = ac.v;
return *this;
}
QString description() override {
if (v._dice < 1) return "<incomplete>";
return QString("Unluck: %1d6").arg(v._dice);
}
void form(QWidget* parent, QVBoxLayout* layout) override {
dice = createLineEdit(parent, layout, "How many dice of unluck?", std::mem_fn(&Complication::numeric));
}
Points points(bool noStore = false) override {
if (!noStore) store();
return v._dice * 5_cp;
}
void restore() override {
vars s = v;
dice->setText(QString("%1").arg(s._dice));
v = s;
}
void store() override {
v._dice = dice->text().toInt(0);
}
QJsonObject toJson() override {
QJsonObject obj;
obj["name"] = "Unluck";
obj["dice"] = v._dice;
return obj;
}
private:
struct vars {
int _dice = 0;
} v;
QLineEdit* dice;
void numeric(QString) override {
QString txt = dice->text();
if (txt.isEmpty() || isNumber(txt)) return;
dice->undo();
}
};
#endif // UNLUCK_H