GodotComponentTest/scenes/HexTile3D.gd

49 lines
1.4 KiB
GDScript

extends Spatial
class_name HexTile3D
onready var is_mouse_over = false
onready var mesh = $Mesh
onready var old_material_override = preload("res://materials/SandTile.tres")
onready var game_tile = preload("res://utils/GameTile.gd").new()
signal tile_selected
signal tile_mouse_entered
#var cube_coords = Vector3(0, 0, 0) setget set_cube_coords, get_cube_coords
func set_tiletype(type):
var GameTile = load("res://utils/GameTile.gd").new()
game_tile.type = type
var _mesh = $Mesh
if type == GameTile.TileType.Sand or type== GameTile.TileType.Water:
_mesh.set_surface_material(0, preload("res://materials/SandTile.tres"))
elif type == GameTile.TileType.Grass:
_mesh.set_surface_material(0, preload("res://materials/GrassTile.tres"))
else:
_mesh.set_surface_material(0, preload("res://materials/DeepGrassTile.tres"))
func _on_Area_mouse_entered():
is_mouse_over = true
old_material_override = mesh.material_override
var material = mesh.get_surface_material(0)
var cloned_material = material.duplicate()
cloned_material.albedo_color = Color (1, 0, 0)
mesh.material_override = cloned_material
emit_signal("tile_mouse_entered", self)
func _on_Area_mouse_exited():
is_mouse_over = false
mesh.material_override = old_material_override
func _on_Area_input_event(_camera, event, position, _normal, _shape_idx):
if is_mouse_over and event is InputEventMouseButton:
if event.button_index == 1 and event.pressed:
emit_signal("tile_selected", self)