2024-03-05 15:47:11 +01:00
|
|
|
extends Area3D
|
|
|
|
|
|
|
|
|
|
var hovered: bool = false
|
|
|
|
|
|
2024-03-14 19:30:18 +01:00
|
|
|
var coordinates: Vector4i
|
2024-03-06 19:55:13 +01:00
|
|
|
|
2024-03-05 15:47:11 +01:00
|
|
|
var insect_resource: TileResource
|
|
|
|
|
var is_black: bool = false
|
|
|
|
|
|
2024-03-06 04:00:54 +01:00
|
|
|
var insect_tile: InsectTile
|
|
|
|
|
|
2024-03-05 15:47:11 +01:00
|
|
|
var tile: Node3D
|
|
|
|
|
|
2024-03-06 04:00:54 +01:00
|
|
|
var is_moving: bool = false
|
|
|
|
|
|
2024-03-14 19:30:18 +01:00
|
|
|
var map_reference: HexGrid
|
|
|
|
|
|
2024-03-29 02:51:06 +01:00
|
|
|
var is_active: bool = true
|
|
|
|
|
|
2025-06-10 01:32:17 +02:00
|
|
|
const BUILD_GHOST: PackedScene = preload("res://InsectTiles/BuildGhost.tscn")
|
2024-03-05 15:47:11 +01:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready():
|
|
|
|
|
if insect_resource == null:
|
2024-03-15 18:05:58 +01:00
|
|
|
#print("Should not happen!")
|
2024-03-05 15:47:11 +01:00
|
|
|
return
|
|
|
|
|
|
2024-03-06 04:00:54 +01:00
|
|
|
if is_moving:
|
|
|
|
|
GameEvents.insect_tile_moved.connect(_on_insect_tile_moved)
|
|
|
|
|
else:
|
|
|
|
|
GameEvents.insect_placed.connect(_on_insect_placed)
|
2025-06-10 01:32:17 +02:00
|
|
|
|
|
|
|
|
tile = BUILD_GHOST.instantiate()
|
|
|
|
|
tile.resource = insect_resource
|
|
|
|
|
tile.is_black = is_black
|
|
|
|
|
tile.map_reference = map_reference
|
|
|
|
|
|
|
|
|
|
add_child(tile)
|
|
|
|
|
tile.visible = false
|
2024-03-06 04:00:54 +01:00
|
|
|
|
2024-03-14 19:30:18 +01:00
|
|
|
func _on_insect_tile_moved(tile: InsectTile, to: Vector4i) -> void:
|
2024-03-29 02:51:06 +01:00
|
|
|
is_active = false
|
2024-03-06 04:00:54 +01:00
|
|
|
queue_free()
|
2024-03-05 15:47:11 +01:00
|
|
|
|
2024-03-14 19:30:18 +01:00
|
|
|
func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) -> void:
|
2024-03-29 02:51:06 +01:00
|
|
|
is_active = false
|
2024-03-05 15:47:11 +01:00
|
|
|
queue_free()
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
2024-03-29 02:51:06 +01:00
|
|
|
#func _process(delta):
|
2025-06-10 01:32:17 +02:00
|
|
|
|
|
|
|
|
func _on_mouse_entered():
|
|
|
|
|
hovered = true
|
|
|
|
|
tile.visible = true
|
|
|
|
|
|
|
|
|
|
func _on_input_event(camera, event, position, normal, shape_idx):
|
2024-03-29 02:51:06 +01:00
|
|
|
if Input.is_action_just_pressed("place_tile") and is_active:
|
2024-03-05 15:47:11 +01:00
|
|
|
if hovered:
|
2024-03-06 04:00:54 +01:00
|
|
|
if is_moving:
|
2024-03-06 19:55:13 +01:00
|
|
|
GameEvents.insect_tile_moved.emit(insect_tile, coordinates)
|
2024-03-06 04:00:54 +01:00
|
|
|
else:
|
2024-03-06 19:55:13 +01:00
|
|
|
GameEvents.insect_placed.emit(insect_resource, is_black, coordinates)
|
2024-03-05 15:47:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_mouse_exited():
|
|
|
|
|
hovered = false
|
2025-06-10 01:32:17 +02:00
|
|
|
tile.visible = false
|
|
|
|
|
#if tile:
|
|
|
|
|
#tile.queue_free()
|
|
|
|
|
#tile = null
|