You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.6 KiB
68 lines
2.6 KiB
extends Node3D
|
|
|
|
@onready var ground = $Ground
|
|
@onready var camera =$Camera
|
|
@onready var highlighter = $Highlighter
|
|
|
|
var highlight = {}
|
|
var selection = {}
|
|
|
|
func _ready():
|
|
highlight = reset_highlight()
|
|
selection = reset_highlight()
|
|
|
|
func _process(delta):
|
|
if Input.is_action_just_pressed("alt_command"):
|
|
if highlight.type == 1:
|
|
selection = highlight
|
|
else:
|
|
selection = reset_highlight()
|
|
var entity = Global.world.add_entity(Vector2i(highlight.grid_position.x, highlight.grid_position.y))
|
|
if Input.is_action_just_pressed("main_command"):
|
|
if selection.type == 1:
|
|
Global.world.entities[selection.data.id].path_create(Global.world.get_real_coordinates(Vector2i(round(highlight.data.position.x), round(highlight.data.position.z))))
|
|
Global.world.entities[selection.data.id].path_start()
|
|
func _unhandled_input(event):
|
|
if event is InputEventMouseMotion:
|
|
highlight = get_highlight()
|
|
if highlight.type == 0:
|
|
highlighter.transparency = 0.0
|
|
# var sprite_position = Vector3(round(highlight.board_position.x), ceil(highlight.board_position.y), round(highlight.board_position.z)) + Vector3(0, 0.01, 0)
|
|
var sprite_position = Vector3((highlight.board_position.x), (highlight.board_position.y), (highlight.board_position.z)) + Vector3(0, 0.05, 0)
|
|
highlighter.position = sprite_position
|
|
else:
|
|
highlighter.transparency = 1.0
|
|
|
|
func get_highlight():
|
|
var result = reset_highlight()
|
|
var mouse_pos = get_viewport().get_mouse_position()
|
|
var ray_length = 1000
|
|
var from = camera.project_ray_origin(mouse_pos)
|
|
var to = from + camera.project_ray_normal(mouse_pos) * ray_length
|
|
var space = get_world_3d().direct_space_state
|
|
var ray_query = PhysicsRayQueryParameters3D.new()
|
|
ray_query.from = from
|
|
ray_query.to = to
|
|
ray_query.collide_with_areas = true
|
|
var raycast_result = space.intersect_ray(ray_query)
|
|
if raycast_result:
|
|
var collider = raycast_result.collider
|
|
if "Chunk" in raycast_result.collider.name or "Ocean" in raycast_result.collider.name:
|
|
var position = round(raycast_result.position)
|
|
position.y = Global.world.get_height(Vector2i(position.x, position.z))
|
|
if "Ocean" in raycast_result.collider.name:
|
|
position.y += ground.WATER_HEIGHT
|
|
result["type"] = 0
|
|
result["board_position"] = position
|
|
result["grid_position"] = Global.world.get_real_coordinates(Vector2i(position.x, position.z))
|
|
result["data"] = Global.world.get_bloc(result["grid_position"])
|
|
elif "id" in raycast_result.collider:
|
|
result["type"] = 1
|
|
result["data"] = Global.world.entities[raycast_result.collider.id].get_data()
|
|
return result
|
|
|
|
func reset_highlight():
|
|
return {
|
|
"type": -1,
|
|
"data": null
|
|
}
|
|
|