Skip to content

Commit

Permalink
Allow interrupting structure construction, closes #71
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Nov 19, 2023
1 parent d00fc4d commit 6eed7c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions source/match/hud/unit-menus/GenericMenu.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
extends GridContainer

const Structure = preload("res://source/match/units/Structure.gd")

var units = []


func _on_cancel_action_button_pressed():
if len(units) == 1 and units[0] is Structure and units[0].is_under_construction():
units[0].cancel_construction()
return
for unit in units:
unit.action = null
17 changes: 12 additions & 5 deletions source/match/units/Structure.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ func construct(progress):
if expected_hp_after_progressing > expected_hp_before_progressing:
hp += 1
if _construction_progress >= 1.0:
finnish_construction()
_finish_construction()


func finnish_construction():
_change_geometry_material(null)
if is_inside_tree():
constructed.emit()
func cancel_construction():
var scene_path = get_script().resource_path.replace(".gd", ".tscn")
var construction_cost = Constants.Match.Units.CONSTRUCTION_COSTS[scene_path]
player.add_resources(construction_cost)
queue_free()


func is_constructed():
Expand All @@ -52,6 +53,12 @@ func is_under_construction():
return not is_constructed()


func _finish_construction():
_change_geometry_material(null)
if is_inside_tree():
constructed.emit()


func _change_geometry_material(material):
for child in find_child("Geometry").find_children("*"):
if "material_override" in child:
Expand Down

0 comments on commit 6eed7c4

Please sign in to comment.