diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-20 12:26:48 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-20 12:26:48 +0200 |
commit | 89723ca94bd21f1ae14592a682e9c0e5c5f04a74 (patch) | |
tree | 7b5c67f9d05f253abc961c901336780755543d6d /Main.gd | |
parent | f3c455fbfb8b28b095c161eb7769ed92f1acb862 (diff) | |
download | godot-hexgrid-89723ca94bd21f1ae14592a682e9c0e5c5f04a74.zip godot-hexgrid-89723ca94bd21f1ae14592a682e9c0e5c5f04a74.tar.gz |
move demo files into subdir demo
Diffstat (limited to 'Main.gd')
-rw-r--r-- | Main.gd | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/Main.gd b/Main.gd deleted file mode 100644 index 42b52a9..0000000 --- a/Main.gd +++ /dev/null @@ -1,65 +0,0 @@ -#warning-ignore-all:return_value_discarded -extends Node2D - -var moved : int = 0 -var drag_map : bool = false - -onready var UI : Control = $CanvasLayer/HBOX/UI -onready var Map : Sprite = $CanvasLayer/HBOX/ViewportContainer/Viewport/Map -onready var Camera : Camera2D = $CanvasLayer/HBOX/ViewportContainer/Viewport/Camera - -func _ready(): - UI.get_node("rotate").connect("pressed", self, "on_rotate") - UI.get_node("zin").connect("pressed", self, "on_zoom", [true]) - UI.get_node("zout").connect("pressed", self, "on_zoom", [false]) - UI.get_node("LOS").connect("pressed", self, "on_toggle") - UI.get_node("Move").connect("pressed", self, "on_toggle") - UI.get_node("Influence").connect("pressed", self, "on_toggle") - Map.connect("hex_touched", self, "on_hex_touched") - $CanvasLayer/HBOX/ViewportContainer.connect("resized", self, "on_viewport_resized") - on_toggle() - yield(get_tree().create_timer(.2), 'timeout') - on_viewport_resized() - UI.get_node("OSInfo").text = "screen\n%s\ndpi %d" % [OS.get_screen_size(), OS.get_screen_dpi()] - -func on_viewport_resized() -> void: - Camera.configure($CanvasLayer/HBOX/ViewportContainer/Viewport.size, Map.center(), Map.texture_size()) - -func on_rotate() -> void: - Map.rotate_map() - on_viewport_resized() - -func on_zoom(b : bool) -> void: - Camera.update_camera(0, 0, -0.05 if b else 0.05) - -func on_toggle() -> void: - Map.set_mode(UI.get_node("LOS").pressed, UI.get_node("Move").pressed, UI.get_node("Influence").pressed) - -func on_hex_touched(pos : Vector2, hex : Hex, key : int) -> void: - var s : String = ("offmap" if key == -1 else hex.inspect()) - UI.get_node("Info").set_text("\n(%d;%d)\n -> %s\n -> %d" % [int(pos.x), int(pos.y), s, 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) - moved += 1 - else: - Map.on_mouse_move() - elif event is InputEventMouseButton: - if event.button_index == 1: - if moved < 5: - drag_map = Map.on_click(event.pressed) - else: - drag_map = false - moved = 0 - elif event.button_index == 3: - drag_map = event.pressed - elif event.button_index == 4: - on_zoom(true) - elif event.button_index == 5: - on_zoom(false) - elif event is InputEventKey: - if event.scancode == KEY_ESCAPE: - get_tree().quit() |