summaryrefslogtreecommitdiffstats
path: root/Main.gd
blob: 88af7490b9ba4e32a1559b2223a9deaa1de39f00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#warning-ignore-all:return_value_discarded
extends Node2D

var drag_map : bool = false

onready var UI : CanvasLayer = $UI
onready var Map : Sprite = $ViewportContainer/Viewport/Map
onready var Camera : Camera2D = $ViewportContainer/Viewport/Camera

func _ready():
	UI.get_node("rotate").connect("pressed", Map, "on_rotate")
	UI.get_node("LOS").connect("pressed", self, "on_toggle")
	UI.get_node("Move").connect("pressed", self, "on_toggle")
	Map.connect("configure", Camera, "on_configure")
	Map.connect("hex_touched", self, "on_hex_touched")
	Camera.window = $ViewportContainer/Viewport.size
	on_toggle()
	Map.on_rotate()

func on_toggle() -> void:
	Map.config(UI.get_node("LOS").pressed, UI.get_node("Move").pressed)
	Map.update()

func on_hex_touched(pos : Vector2, hex : Hex, key : int) -> void:
	UI.get_node("Info").set_text("\n(%d;%d)\n -> %s\n -> %d" % [int(pos.x), int(pos.y), hex.inspect(), key])

func _unhandled_input(event : InputEvent) -> void:
	if event is InputEventMouseMotion:
		if drag_map:
			var dv : Vector2 = event.relative * Camera.zoom
			Camera.update_camera(-dv.x, -dv.y, 0)
		else:
			Map.on_mouse_move()
	elif event is InputEventMouseButton:
		if event.button_index == 4:
			Camera.update_camera(0, 0, -0.05)
		elif event.button_index == 5:
			Camera.update_camera(0, 0, +0.05)
		elif event.button_index == 3:
			drag_map = event.pressed
		elif event.button_index == 1:
			Map.on_mouse_1(event.pressed)
		elif event.button_index == 2:
			Map.on_mouse_2(event.pressed)
	elif event is InputEventKey:
		if event.scancode == KEY_ESCAPE:
			get_tree().quit()