Skip to content

Commit

Permalink
fix(brackeys13): updated the hud
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lybyte committed Feb 21, 2025
1 parent 5c81664 commit f8c43ba
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions apps/gamejam/brackeys/13/scripts/hud.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,28 @@ func _update_starship_data(data_name: String, value):
if data_name == "coordinates":
update_coordinates(value)

# func _update_starship_resources():
# for resource in Global.resources_list:
# var amount = Global.get_resource(resource)
# if resource_labels.has(resource) and resource_labels[resource]:
# resource_labels[resource].text = "%d" % [amount]

# func _on_resource_changed(resource_name: String, new_value: int):
# if resource_labels.has(resource_name) and resource_labels[resource_name]:
# resource_labels[resource_name].text = "%d" % [new_value]


func _update_starship_resources():
for resource in Global.resources_list:
var amount = Global.get_resource(resource)
if resource_labels.has(resource) and resource_labels[resource]:
#resource_labels[resource].text = "%s: %d" % [resource.capitalize(), amount]
resource_labels[resource].text = "%d" % [amount]
resource_labels[resource].text = _format_resource_amount(amount)


func _on_resource_changed(resource_name: String, new_value: int):
if resource_labels.has(resource_name) and resource_labels[resource_name]:
#resource_labels[resource_name].text = "%s: %d" % [resource_name.capitalize(), new_value]
resource_labels[resource_name].text = "%d" % [new_value]
if resource_labels.has(resource_name) and resource_labels[resource_name]:
resource_labels[resource_name].text = _format_resource_amount(new_value)


func _update_starship_name():
var starship_name = Global.get_starship_data("name")
Expand All @@ -72,3 +83,11 @@ func _update_starship_name():
name_label.text = "Starship: Unknown"
else:
push_warning("Starship name label not found!")

func _format_resource_amount(amount: int) -> String:
if amount >= 1_000_000: # 1M or more
return "%dM" % (amount / 1_000_000)
elif amount >= 10_000: # 10K or more
return "%dK" % (amount / 1_000)
else:
return "%d" % amount

0 comments on commit f8c43ba

Please sign in to comment.