PirateTreasureHunt/scenes/Editor.gd

76 lines
1.7 KiB
GDScript
Raw Normal View History

2021-06-27 12:26:44 +02:00
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# UI elements
onready var EditorUI = get_node("UI/Editor")
onready var TileTypes = get_node("UI/TileTypes")
onready var NoneButton = get_node("UI/Editor/NoneButton")
# World objects
onready var world = get_node("../World")
onready var world_camera = get_node("../World/Camera")
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func handle_editor_event(event):
if (Input.get_mouse_button_mask() & BUTTON_LEFT) == BUTTON_LEFT:
# if event.pressed and event.button_index == BUTTON_LEFT:
var pressed_button = NoneButton.group.get_pressed_button()
var tile_type = "None"
if pressed_button:
tile_type = pressed_button.text
2021-06-28 21:51:09 +02:00
var hex_coord = Globals.HexGrid.get_hex_center(Globals.ScreenToHex(event.position,world.WorldCamera))
2021-06-27 12:26:44 +02:00
if tile_type != "None":
world.tile_data[hex_coord] = tile_type
update()
elif hex_coord in world.tile_data.keys():
world.tile_data.erase(hex_coord)
update()
return true
return false
func _unhandled_input(event):
if not EditorUI.visible:
return
if event is InputEventMouseButton:
if handle_editor_event (event):
return
if 'position' in event:
if handle_editor_event (event):
return
update()
func _on_SaveWorldButton_pressed():
world.save_world("user://pirate_game_world.save")
func _on_ClearWorldButton_pressed():
world.tile_data = {}
world.update()
func _on_LoadWorldButton_pressed():
world.load_world("user://pirate_game_world.save")
update()
func _on_EditIslandButton_toggled(button_pressed):
EditorUI.visible = button_pressed
print (button_pressed)