tool extends Spatial class_name Island onready var GameTile = preload("res://utils/GameTile.gd") export var generate: bool = false setget do_generate export var level_size: int = 10 signal island_tile_selected signal island_tile_hover func reset(): var tiles = $Tiles for node in tiles.get_children(): tiles.remove_child(node) node.queue_free() func create_tile_for_hex(game_tile): var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() var HexTile3D = preload("res://scenes/HexTile3D.tscn") var tile = HexTile3D.instance() var pos = hexgrid.get_hex_center_from_offset(game_tile.offset_coords) var height = 0.0 if game_tile.type == GameTile.TileType.Sand else 0.1 + rand_range(0.0, 0.05) tile.set_tiletype(game_tile.type) tile.transform.origin = Vector3(pos.x, height, pos.y) tile.connect("tile_selected", self, "on_tile_selected") tile.connect("tile_mouse_entered", self, "on_tile_hover") return tile func generate(): var IslandGenerator = preload("res://utils/IslandGenerator.gd").new() var tiles = $Tiles reset() var generated_tiles = IslandGenerator.random_walk(level_size) generated_tiles = IslandGenerator.extrude_tiles(generated_tiles) generated_tiles = IslandGenerator.mark_sand_tiles(generated_tiles) for island_tile in generated_tiles.values(): var scene_tile = create_tile_for_hex(island_tile) tiles.add_child(scene_tile) print ("Generated island with " + str(tiles.get_child_count()) + " nodes") func do_generate(_flag: bool): print ("Generating Level") generate() func on_tile_selected(tile): emit_signal("island_tile_selected", self, tile) func on_tile_hover(tile): emit_signal("island_tile_hover", self, tile)