Prepared Movement behaviour. Fixed multi-tile placement bug
This commit is contained in:
parent
62eef907d3
commit
397082f966
17 changed files with 395 additions and 75 deletions
|
|
@ -198,6 +198,7 @@ func debug_label(pos, text) -> void:
|
|||
var label = Label3D.new()
|
||||
label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
label.text = text
|
||||
label.no_depth_test = true
|
||||
var p = cube_to_world_pos(pos)
|
||||
label.position = Vector3(p.x, 0.2, p.y)
|
||||
add_child(label)
|
||||
|
|
@ -233,7 +234,7 @@ func can_reach(start: Vector4i, target: Vector4i, exclude: Array[Vector4i] = [])
|
|||
|
||||
return is_cell_empty(left_coord) or is_cell_empty(right_coord)
|
||||
|
||||
func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
|
||||
func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
|
||||
var positions = get_placeable_positions(button)
|
||||
|
||||
for child in placement_visualizer.get_children():
|
||||
|
|
@ -289,23 +290,37 @@ func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) ->
|
|||
place_insect_tile.rpc(resource_path, is_black, pos)
|
||||
|
||||
func can_move(tile: InsectTile) -> bool:
|
||||
return can_hive_exist_without_tile(tile)
|
||||
if not can_hive_exist_without_tile(tile):
|
||||
return false
|
||||
|
||||
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
|
||||
|
||||
if spaces.is_empty():
|
||||
return false
|
||||
|
||||
return true
|
||||
|
||||
func has_action_targets(tile: InsectTile) -> bool:
|
||||
if tile.resource.action_behaviour == null:
|
||||
return false
|
||||
|
||||
var targets: Array[InsectTile] = tile.resource.action_behaviour.get_targets(tile.coordinates, self)
|
||||
|
||||
return !targets.is_empty()
|
||||
|
||||
func _on_insect_tile_selected(tile: InsectTile) -> void:
|
||||
func _on_insect_tile_action_started(tile: InsectTile) -> void:
|
||||
do_action(tile)
|
||||
|
||||
func _on_insect_tile_move_started(tile: InsectTile) -> void:
|
||||
do_move(tile)
|
||||
|
||||
func do_action(tile: InsectTile) -> void:
|
||||
pass
|
||||
|
||||
func do_move(tile: InsectTile) -> void:
|
||||
for child in placement_visualizer.get_children():
|
||||
child.queue_free()
|
||||
|
||||
if not can_hive_exist_without_tile(tile):
|
||||
print("Would break hive")
|
||||
return
|
||||
|
||||
if tile.resource.movement_behaviour == null:
|
||||
#print("no movement behaviour")
|
||||
return
|
||||
|
||||
#if tile.resource.action_behaviour != null:
|
||||
#tile.resource.action_behaviour.select_targets(tile.coordinates, self)
|
||||
|
||||
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
|
||||
|
||||
if spaces.is_empty():
|
||||
|
|
@ -355,6 +370,26 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
|
|||
outline.is_black = tile.is_black
|
||||
placement_visualizer.add_child(outline)
|
||||
placements[space] = outline
|
||||
|
||||
func _on_insect_tile_selected(tile: InsectTile) -> void:
|
||||
# check the following:
|
||||
# if the insect is selectable for an action (has action_callback data set) -> do that action
|
||||
# else:
|
||||
# if the unit has no action
|
||||
# try moving
|
||||
# else:
|
||||
# show action/move panel, grey out action/or move if there are no target or can't move?
|
||||
if tile.action_callback.is_valid():
|
||||
tile.action_callback.call()
|
||||
return
|
||||
else:
|
||||
# if tile has an action
|
||||
if tile.resource.action_behaviour != null:
|
||||
GameEvents.choose_action_or_move.emit(tile, has_action_targets(tile), can_move(tile))
|
||||
return
|
||||
|
||||
if can_move(tile):
|
||||
do_move(tile)
|
||||
|
||||
func get_tile(pos: Vector4i) -> InsectTile:
|
||||
return used_cells.get(pos)
|
||||
|
|
@ -458,3 +493,5 @@ func _ready() -> void:
|
|||
GameEvents.insect_placed.connect(_on_insect_placed)
|
||||
GameEvents.insect_tile_selected.connect(_on_insect_tile_selected)
|
||||
GameEvents.insect_tile_moved.connect(_on_insect_tile_moved)
|
||||
GameEvents.insect_tile_action_started.connect(_on_insect_tile_action_started)
|
||||
GameEvents.insect_tile_move_started.connect(_on_insect_tile_move_started)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue