aboutsummaryrefslogtreecommitdiff
path: root/game/menus/shop/ButtonBuySelectBubbleScript.cpp
blob: 741afde9ca9d72dde7d566891c5ee5921e5470f4 (plain)
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
#include "ButtonBuySelectBubbleScript.h"
#include "../MenusConfig.h"
#include "Config.h"
#include "ValueBroker.h"
#include "manager/SaveManager.h"
#include "menus/shop/Shopconfig.h"

using namespace crepe;
using namespace std;

void ButtonBuySelectBubbleScript::init() {
	IButtonScript::init();
	this->subscribe<ButtonPressEvent>([this](const ButtonPressEvent & e) {
		return this->on_button_press(e);
	});
}

bool ButtonBuySelectBubbleScript::on_button_press(const ButtonPressEvent & e) {
	SaveManager & save = this->get_save_manager();
	ValueBroker<int> buy_bullet = save.get<int>(BUY_BUBBLE_SAVE, 0);
	if (!buy_bullet.get()) {
		ValueBroker<int> coins = save.get<int>(TOTAL_COINS_GAME, 0);
		if (coins.get() >= 1000) {
			int coin = coins.get();
			coin -= 1000;
			save.set(TOTAL_COINS_GAME, coin);
			save.set(BUY_BUBBLE_SAVE, 1);
		}
	} else {
		save.set(JETPACK_PARTICLES, 1);
	}
	this->trigger_event<ShopUpdate>();
	return false;
}