Add post-move action menu flow
This commit is contained in:
@@ -639,7 +639,7 @@ func clear_selection() -> void:
|
||||
_notify_changed()
|
||||
|
||||
|
||||
func try_move_selected(cell: Vector2i) -> bool:
|
||||
func try_move_selected(cell: Vector2i, defer_reach_events := false) -> bool:
|
||||
var unit := get_selected_unit()
|
||||
if unit.is_empty() or battle_status != STATUS_ACTIVE:
|
||||
return false
|
||||
@@ -660,9 +660,40 @@ func try_move_selected(cell: Vector2i) -> bool:
|
||||
unit["moved"] = true
|
||||
unit_motion_requested.emit(str(unit.get("id", "")), from_cell, cell)
|
||||
_emit_log("%s moved to %s." % [unit["name"], _format_cell(cell)])
|
||||
if not defer_reach_events:
|
||||
_run_events("unit_reaches_tile", str(unit.get("team", "")), turn_number, unit)
|
||||
_check_battle_status()
|
||||
_notify_changed()
|
||||
return true
|
||||
|
||||
|
||||
func commit_pending_move_events(unit_id: String) -> bool:
|
||||
var unit := get_unit(unit_id)
|
||||
if unit.is_empty() or battle_status != STATUS_ACTIVE:
|
||||
return false
|
||||
_run_events("unit_reaches_tile", str(unit.get("team", "")), turn_number, unit)
|
||||
_check_battle_status()
|
||||
_notify_changed()
|
||||
return battle_status == STATUS_ACTIVE
|
||||
|
||||
|
||||
func cancel_pending_move(unit_id: String, from_cell: Vector2i, to_cell: Vector2i) -> bool:
|
||||
var unit := get_unit(unit_id)
|
||||
if unit.is_empty() or battle_status != STATUS_ACTIVE:
|
||||
return false
|
||||
if bool(unit.get("acted", false)) or not bool(unit.get("moved", false)):
|
||||
return false
|
||||
if unit.get("pos", Vector2i(-1, -1)) != to_cell:
|
||||
return false
|
||||
var blocker := get_unit_at(from_cell)
|
||||
if not blocker.is_empty() and str(blocker.get("id", "")) != unit_id:
|
||||
return false
|
||||
|
||||
unit["pos"] = from_cell
|
||||
unit["moved"] = false
|
||||
unit_motion_requested.emit(unit_id, to_cell, from_cell)
|
||||
_emit_log("%s cancels movement." % unit["name"])
|
||||
_notify_changed()
|
||||
return true
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user