Skip to content

Commit dba9b61

Browse files
committed
Merge branch 'master' into main_refactor
Conflicts: resources/graphics.conf
2 parents 6736720 + 268eb2c commit dba9b61

File tree

7 files changed

+239
-92
lines changed

7 files changed

+239
-92
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ $(EXECUTABLE): $(ALLFILES)
2020
.PHONY: tests
2121
tests: $(EXECUTABLE)
2222
cd tests && $(MAKE)
23+
tests/main.test
2324

2425
.PHONY: clean
2526
clean:

include/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConfigValue {
2727
operator std::string() const;
2828
operator Coordinate() const;
2929
operator ScreenCoordinate() const;
30+
operator std::pair<ScreenCoordinate, ScreenCoordinate>() const;
3031
};
3132

3233
/**

include/GameController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GameController {
2525
GameBoard& model;
2626
GameView& view;
2727

28-
std::vector<ControlState> stateStack;
28+
ControlState state;
2929
std::vector<Coordinate> clickHistory;
3030

3131
GameController(const GameController& o) : model(o.model), view(o.view) {} //deleted

resources/graphics.conf

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,93 @@
11
# Font settings
2-
font.path=resources/ComicNeue-Bold.ttf
3-
font.size=50
2+
font.path = resources/ComicNeue-Bold.ttf
3+
font.size = 50
44

55
# General window settings
66
screen.x=100
77
screen.y=100
88

9-
screen.width=1280
10-
screen.height=720
9+
screen.width = 1280
10+
screen.height = 720
11+
12+
# Buttons
13+
screen.roadButton.text=Road |
14+
screen.roadButton.area=((0,0),(0.1,0.1))
15+
16+
screen.cityButton.text=City |
17+
screen.cityButton.area=((0.1,0),(0.2,0.1))
18+
19+
screen.settlementButton.text=Settlement
20+
screen.settlementButton.area=((0.20,0.0),(0.33,0.1))
21+
22+
screen.wonderButton.text=|Wonder
23+
screen.wonderButton.area=((0.55,0.0),(0.65,0.1))
24+
25+
screen.endTurnButton.text=End Turn
26+
screen.endTurnButton.area=((0,0.3),(0.1,0.4))
27+
28+
screen.players.topY=0.82
29+
screen.players.width=0.15
30+
screen.players.height=0.05
31+
screen.players.right=1.0
32+
33+
screen.bankButton.text=Bank
34+
screen.bankButton.area=((0,0.8),(0.1,0.9))
35+
36+
screen.cancelButton.text=Cancel
37+
screen.cancelButton.area=((.92,.96),(1.0,1.0))
38+
39+
screen.developmentCardButton.text=Development Cards
40+
screen.developmentCardButton.area=((.85,.23),(1,.30))
41+
42+
screen.roadBuildingButton.text=Road Building
43+
screen.roadBuildingButton.area=((0.85,0.0),(0.97,0.05))
44+
45+
screen.knightButton.text=Knight
46+
screen.knightButton.area=((0.85,0.05),(0.97,0.10))
47+
48+
screen.yearOfPlentyButton.text=Year of Plenty
49+
screen.yearOfPlentyButton.area=((0.85,0.10),(0.97,0.15))
50+
51+
screen.monopolyButton.text=Monopoly
52+
screen.monopolyButton.area=((0.85,0.15),(0.97,0.20))
53+
54+
screen.victoryPointButton.text=Victory Point
55+
screen.victoryPointButton.area=((0.85,0.20),(0.97,0.25))
56+
57+
screen.woodButton.text=Wood
58+
screen.woodButton.area=((.85,.30),(.97,.35))
59+
60+
screen.sheepButton.text=Sheep
61+
screen.sheepButton.area=((.85,.35),(.97,.40))
62+
63+
screen.oreButton.text=Ore
64+
screen.oreButton.area=((.85,.40),(.97,.45))
65+
66+
screen.brickButton.text=Brick
67+
screen.brickButton.area=((.85,.45),(.97,.50))
68+
69+
screen.wheatButton.text=Wheat
70+
screen.wheatButton.area=((.85,.50),(.97,.55))
71+
72+
screen.showTotalButton.text=Show Totals
73+
screen.showTotalButton.area=((.85,.55),(.97,.60))
74+
75+
screen.board.area=((0,0),(1,1))
1176

1277
# Trading view screen coordinates
13-
screen.tradingView.bottomLeft=(0.1,0.1)
14-
screen.tradingView.topRight=(0.9,0.9)
78+
screen.tradingView.bottomLeft = (0.1,0.1)
79+
screen.tradingView.topRight = (0.9,0.9)
1580

16-
screen.tradingView.tradeButton.bottomLeft=(0.7,0.1)
17-
screen.tradingView.tradeButton.topRight=(0.9,0.2)
81+
screen.tradingView.tradeButton.bottomLeft = (0.7,0.1)
82+
screen.tradingView.tradeButton.topRight = (0.9,0.2)
1883

19-
screen.tradingView.cancelButton.bottomLeft=(0.1,0.1)
20-
screen.tradingView.cancelButton.topRight=(0.3,0.2)
84+
screen.tradingView.cancelButton.bottomLeft = (0.1,0.1)
85+
screen.tradingView.cancelButton.topRight = (0.3,0.2)
2186

22-
screen.tradingView.resources.height=0.13
23-
screen.tradingView.resources.leftX=0.3
24-
screen.tradingView.resources.rightX=0.6
25-
screen.tradingView.resources.bottomY=0.2
87+
screen.tradingView.resources.height = 0.13
88+
screen.tradingView.resources.leftX = 0.3
89+
screen.tradingView.resources.rightX = 0.6
90+
screen.tradingView.resources.bottomY = 0.2
2691

27-
screen.tradingView.players.bottomLeft=(0.1,0.8)
28-
screen.tradingView.players.topRight=(0.9,0.9)
92+
screen.tradingView.players.bottomLeft = (0.1,0.8)
93+
screen.tradingView.players.topRight = (0.9,0.9)

src/Config.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ ConfigValue::operator string() const {
3535
return value;
3636
}
3737

38+
3839
/**
39-
* Convert the ConfigValue into a game Coordinate.
40-
* @throws runtime_error If the value cannot be converted.
41-
* @return The text of the ConfigValue, interpreted as a game Coordinate.
40+
* Read a pair (S,T) in from a stream.
41+
* @throws runtime_error If the pair is not in the form (S,T).
42+
* @param stream The stream to read in from.
43+
* @param ret The pair to read into.
4244
*/
43-
ConfigValue::operator Coordinate() const {
44-
stringstream stream(value);
45-
Coordinate ret;
45+
template<class S, class T>
46+
void readPair(std::stringstream& stream, std::pair<S, T>& ret) {
4647
char c = stream.get();
4748
if(c != '(') {
4849
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
@@ -53,6 +54,21 @@ ConfigValue::operator Coordinate() const {
5354
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
5455
}
5556
stream >> ret.second;
57+
c = stream.get();
58+
if(c != ')') {
59+
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
60+
}
61+
}
62+
63+
/**
64+
* Convert the ConfigValue into a game Coordinate.
65+
* @throws runtime_error If the value cannot be converted.
66+
* @return The text of the ConfigValue, interpreted as a game Coordinate.
67+
*/
68+
ConfigValue::operator Coordinate() const {
69+
stringstream stream(value);
70+
Coordinate ret;
71+
readPair(stream, ret);
5672
return ret;
5773
}
5874

@@ -64,16 +80,28 @@ ConfigValue::operator Coordinate() const {
6480
ConfigValue::operator ScreenCoordinate() const {
6581
stringstream stream(value);
6682
ScreenCoordinate ret;
83+
readPair(stream, ret);
84+
return ret;
85+
}
86+
87+
/**
88+
* Convert the ConfigValue into a pair of ScreenCoordinates.
89+
* @throws runtime_error If the value cannot be converted.
90+
* @return The text of the ConfigValue, interpreted as a pair of ScreenCoordinates.
91+
*/
92+
ConfigValue::operator std::pair<ScreenCoordinate, ScreenCoordinate>() const {
93+
stringstream stream(value);
94+
std::pair<ScreenCoordinate, ScreenCoordinate> ret;
6795
char c = stream.get();
6896
if(c != '(') {
6997
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
7098
}
71-
stream >> ret.first;
99+
readPair(stream, ret.first);
72100
c = stream.get();
73101
if(c != ',') {
74102
throw runtime_error("Attempt to read a coordinate out of a non-coordinate value");
75103
}
76-
stream >> ret.second;
104+
readPair(stream, ret.second);
77105
return ret;
78106
}
79107

@@ -114,7 +142,13 @@ void Config::init(istream& source) {
114142
continue;
115143
}
116144
string name = line.substr(0, line.find('='));
145+
while(name[name.size()-1] == ' ' || name[name.size()-1] == '\t') {
146+
name = name.substr(0, name.size()-1);
147+
}
117148
string value = line.substr(line.find('=') + 1);
149+
while(value[0] == ' ' || value[0] == '\t') {
150+
value = value.substr(1);
151+
}
118152
values.insert(std::make_pair(name, ConfigValue(value)));
119153
}
120154
}
@@ -128,7 +162,7 @@ void Config::init(istream& source) {
128162
const ConfigValue& Config::operator[](const string& name) const {
129163
auto it = values.find(name);
130164
if(it == values.end()) {
131-
throw runtime_error("No such key in the config");
165+
throw runtime_error("No such key in the config: \"" + name + "\"");
132166
} else {
133167
return it->second;
134168
}

0 commit comments

Comments
 (0)