def get_tips(game_id):
game = games[game_id]
- return {'tips': game.shown_tips}
+ has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+ return {'tips': game.shown_tips, 'hasMore': has_more}
@post('/api/games/<game_id>/ask-tip')
game = games[game_id]
show_tips(game, 1)
- return {'tips': game.shown_tips}
+
+ has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+ return {'tips': game.shown_tips, 'hasMore': has_more}
@post('/api/games/<game_id>/move/<direction>')
show_tips(game, 1)
- return {'tips': game.shown_tips}
+ has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+
+ return {'tips': game.shown_tips, 'hasMore': has_more}
@post('/api/games/<game_id>/finish/<latitude>/<longitude>')
def filter_sightseeings(objects):
return list(filter(lambda o:
o['data']['tag'] != {}
+ and 'lat' in o['data']
+ and 'lon' in o['data']
and
(('tourism' in o['data']['tag']
and ('attraction' in o['data']['tag']['tourism']
this.gameController = new GameController(this.notification);
this.state = {
tips: this.gameController.tips(),
- loading: true
+ loading: true,
+ hasMoreTips: this.gameController.hasMoreTips()
};
}
this.gameController.createGame().then(() => this.gameController.loadTips()).then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
loading: false,
inProcess: false
}, () => {
this.gameController.getMoreTips().then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
inProcess: false
})
}).catch(error => {
this.gameController.goNorth().then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
inProcess: false
})
}).catch(error => {
this.gameController.goWest().then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
inProcess: false
})
}).catch(error => {
this.gameController.goSouth().then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
inProcess: false
})
}).catch(error => {
this.gameController.goEast().then(() => {
this.setState({
tips: this.handleVarlamov(this.gameController.tips()),
+ hasMoreTips: this.gameController.hasMoreTips(),
inProcess: false
})
}).catch(error => {
<div className="Game-controls">
<div className="Get-button">
- <Button onClick={this.askTip} size="medium" disabled={this.state.inProcess}>
+ <Button onClick={this.askTip} size="medium" disabled={this.state.inProcess || !this.state.hasMoreTips}>
Осмотреться
</Button>
</div>
loadTips() {
return api.get(`/games/${this.gameId}/tips`).then(json => {
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
});
}
goNorth() {
return api.post(`/games/${this.gameId}/move/north`).then(json => {
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
})
}
goWest() {
return api.post(`/games/${this.gameId}/move/west`).then(json => {
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
})
}
goSouth() {
return api.post(`/games/${this.gameId}/move/south`).then(json => {
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
})
}
goEast() {
return api.post(`/games/${this.gameId}/move/east`).then(json => {
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
})
}
return this._tips;
}
+ hasMoreTips() {
+ if(!this._tips) {
+ return true;
+ }
+ return this._hasMoreTips;
+ }
+
getMoreTips() {
return api.post(`/games/${this.gameId}/ask-tip`).then(json => {
if(deepEq(json.data.tips, this.tips())) {
return;
}
this._tips = json.data.tips;
+ this._hasMoreTips = json.data.hasMore;
});
}