Done refactoring
This commit is contained in:
parent
3a136ff215
commit
2176e9d798
88 changed files with 821 additions and 880 deletions
67
scripts/menu/BuyMenuButton.gd
Normal file
67
scripts/menu/BuyMenuButton.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
extends NinePatchRect
|
||||
|
||||
@export var data : Dictionary = {"id" : ""} ## Contains all buy options. Must have "id" key.
|
||||
@export var price : float
|
||||
@export var clickable : BaseButton
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
|
||||
func _ready():
|
||||
clickable.button_up.connect(_button_up)
|
||||
|
||||
func _button_up():
|
||||
if ship.money >= price:
|
||||
ship.money -= price
|
||||
bought_action()
|
||||
|
||||
func bought_action():
|
||||
match data["id"]:
|
||||
"hp":
|
||||
if ship.hull.hp >= ship.hull.max_hp:
|
||||
ship.hull.hp = ship.hull.max_hp
|
||||
ship.money += price
|
||||
return
|
||||
ship.hull.hp += 1
|
||||
while(ship.hull.hp < ship.hull.max_hp and ship.money >= price):
|
||||
ship.hull.hp += 1
|
||||
ship.money -= price
|
||||
if ship.hull.hp > ship.hull.max_hp: ship.hull.hp = ship.hull.max_hp
|
||||
"rockets":
|
||||
if ship.hull.ammunition["Rockets"] == ship.hull.max_ammunition["Rockets"]:
|
||||
ship.money += price
|
||||
return
|
||||
var rocket_price : float = price / data["amount"]
|
||||
if ship.hull.ammunition["Rockets"] + data["amount"] > ship.hull.max_ammunition["Rockets"]:
|
||||
var rockets_left = ship.hull.max_ammunition["Rockets"] - ship.hull.ammunition["Rockets"]
|
||||
for i in range(rockets_left + 1):
|
||||
ship.money += rocket_price
|
||||
ship.hull.ammunition["Rockets"] = ship.hull.max_ammunition["Rockets"]
|
||||
else:
|
||||
ship.hull.ammunition["Rockets"] += data["amount"]
|
||||
"fuel":
|
||||
if ship.hull.fuel == ship.hull.max_fuel:
|
||||
ship.money += price
|
||||
return
|
||||
if ship.hull.fuel + data["amount"] > ship.hull.max_fuel:
|
||||
ship.hull.fuel = ship.hull.max_fuel
|
||||
else:
|
||||
ship.hull.fuel += data["amount"]
|
||||
"weapon":
|
||||
var primary_slot = ship.get_node("PrimaryWeapon")
|
||||
var secondary_slot = ship.get_node("SecondaryWeapon")
|
||||
var bought_weapon = get_tree().current_scene.bought_weapon
|
||||
var weapon_dict = get_tree().current_scene.weapon_dict
|
||||
var slot = primary_slot if data["slot"] == "primary" else secondary_slot
|
||||
if !bought_weapon[data["weapon"]]:
|
||||
bought_weapon[data["weapon"]] = true
|
||||
else:
|
||||
ship.money += price
|
||||
if slot.get_child_count() == 0:
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
else:
|
||||
for node in slot.get_children():
|
||||
node.queue_free()
|
||||
var weapon_inst = load(weapon_dict[data["weapon"]]).instantiate()
|
||||
slot.add_child(weapon_inst)
|
||||
slot.position = data["position"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue