PirateTreasureHunt/editor/IslandEditor.gd

41 lines
939 B
GDScript
Raw Normal View History

2021-06-13 15:03:10 +02:00
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var GridLevel
var highlight_hex_coord = Vector2(0,0)
onready var screen_coords = get_node("HBoxContainer/Coords")
onready var hex_coords = get_node("HBoxContainer/GridCoords")
# Called when the node enters the scene tree for the first time.
func _ready():
GridLevel = get_node("GridLevel")
update()
func _input(event):
if 'position' in event:
screen_coords.text = str(event.position)
var coords = GridLevel.WorldToTileCoords (event.position)
hex_coords.text = str(coords)
highlight_hex_coord = GridLevel.GetHexCenter(coords)
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and event.pressed:
GridLevel.SetTile (coords.x, coords.y, GridLevel.TileType.Sand)
update()
func _draw():
draw_set_transform(highlight_hex_coord, 0, Vector2.ONE)
draw_polyline(GridLevel.HexPoints, "#ff0000", 4)