2021-06-12 17:48:58 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const WIDTH=1024
|
|
|
|
const HEIGHT=1024
|
|
|
|
const GRID_SIZE=float(64.0)
|
|
|
|
const GRID_COLOR="#000000"
|
|
|
|
const SHOVEL_DURATION=1
|
|
|
|
|
2021-07-18 22:28:18 +02:00
|
|
|
onready var HexGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
|
|
|
|
onready var HexCell = preload("res://addons/gdhexgrid/HexCell.gd").new()
|
|
|
|
onready var OceanNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
|
|
|
|
onready var IslandNavGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new()
|
|
|
|
|
2021-06-12 17:48:58 +02:00
|
|
|
var DebugLabel = null
|
2021-06-28 21:51:09 +02:00
|
|
|
|
|
|
|
var hex_size = 128
|
2021-07-16 12:07:11 +02:00
|
|
|
var debug_nav = false
|
2021-07-20 22:51:38 +02:00
|
|
|
var draw_grid = false
|
|
|
|
var draw_island_bbox = false
|
2021-06-12 17:48:58 +02:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-06-28 21:51:09 +02:00
|
|
|
HexGrid.hex_scale = Vector2(hex_size, hex_size)
|
2021-07-11 16:09:04 +02:00
|
|
|
OceanNavGrid.hex_scale = Vector2(hex_size, hex_size)
|
|
|
|
IslandNavGrid.hex_scale = Vector2(hex_size, hex_size)
|
2021-07-09 14:17:25 +02:00
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
HexTileDrawer.hex_scale = Vector2(hex_size, hex_size)
|
|
|
|
|
2021-06-12 17:48:58 +02:00
|
|
|
|
|
|
|
func ClearDebugLabel():
|
|
|
|
if DebugLabel == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
DebugLabel.text = ""
|
|
|
|
|
2021-07-07 22:22:07 +02:00
|
|
|
|
2021-06-12 17:48:58 +02:00
|
|
|
func DebugLabelAdd(text):
|
|
|
|
if DebugLabel == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
DebugLabel.text = DebugLabel.text + text + "\n"
|
|
|
|
|
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
func ScreenToWorld(pos: Vector2, camera: Camera2D):
|
|
|
|
pos = pos - OS.get_window_safe_area().size * 0.5
|
|
|
|
return camera.offset + pos * camera.zoom
|
2021-06-12 17:48:58 +02:00
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
|
|
|
|
func ScreenToHex(pos: Vector2, camera: Camera2D):
|
|
|
|
return Globals.HexGrid.get_hex_at(ScreenToWorld(pos, camera)).axial_coords
|
|
|
|
|
|
|
|
|
2021-07-07 22:22:07 +02:00
|
|
|
func HexToWorld(coord: Vector2):
|
|
|
|
return Globals.HexGrid.get_hex_center(coord)
|
|
|
|
|
|
|
|
|
|
|
|
func WorldToHex(pos: Vector2):
|
|
|
|
return Globals.HexGrid.get_hex_at(pos).axial_coords
|
|
|
|
|
|
|
|
|
2021-07-09 14:17:25 +02:00
|
|
|
func WorldToHexCenter(pos: Vector2):
|
|
|
|
return Globals.HexGrid.get_hex_center(Globals.HexGrid.get_hex_at(pos).axial_coords)
|
|
|
|
|
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
func WorldToScreen(pos: Vector2, camera: Camera2D):
|
|
|
|
return pos * camera.zoom + camera.offset
|
2021-07-10 14:18:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
func WorldLineToHexTiles (start: Vector2, target: Vector2):
|
|
|
|
var start_cell = HexCell.new_hex(WorldToHex(start))
|
|
|
|
var target_coord = WorldToHex(target)
|
|
|
|
var path_cells = start_cell.line_to(target_coord)
|
|
|
|
|
|
|
|
var path = []
|
|
|
|
for cell in path_cells:
|
|
|
|
path.append(HexToWorld(cell.axial_coords))
|
|
|
|
|
|
|
|
return path
|
|
|
|
|