2020-07-18 22:42:50 +02:00
|
|
|
extends StaticBody
|
|
|
|
|
2022-02-13 15:52:19 +01:00
|
|
|
export(Material) var default_material : Material = null
|
|
|
|
export(Material) var hover_material : Material = null
|
|
|
|
|
2021-08-27 23:07:58 +02:00
|
|
|
export(float) var use_range : float = 5
|
|
|
|
|
|
|
|
export(PackedScene) var dungeon : PackedScene
|
|
|
|
export(PackedScene) var dungeon_back_teleporter : PackedScene
|
|
|
|
|
2021-08-28 00:55:59 +02:00
|
|
|
var min_level : int = 1
|
|
|
|
var max_level : int = 2
|
2021-08-29 19:38:58 +02:00
|
|
|
var dungeon_seed : int = 0
|
2021-08-29 23:38:15 +02:00
|
|
|
var spawn_mobs : bool = true
|
2021-08-28 00:55:59 +02:00
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
var owner_chunk : TerrainChunk = null
|
2021-08-27 23:07:58 +02:00
|
|
|
var _dungeon : Spatial = null
|
|
|
|
var _dungeon_back_teleporter : Spatial = null
|
2020-07-18 22:42:50 +02:00
|
|
|
|
|
|
|
var teleport_to : Vector3 = Vector3()
|
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
var _world : TerrainWorld = null
|
2021-08-28 00:29:24 +02:00
|
|
|
|
2021-08-28 12:06:10 +02:00
|
|
|
var _is_windows : bool = false
|
|
|
|
var _mouse_hover : bool = false
|
|
|
|
|
2020-07-18 22:42:50 +02:00
|
|
|
func _ready():
|
2021-08-28 12:06:10 +02:00
|
|
|
_is_windows = OS.get_name() == "Windows"
|
|
|
|
|
2020-07-18 22:42:50 +02:00
|
|
|
connect("mouse_entered", self, "on_mouse_entered")
|
|
|
|
connect("mouse_exited", self, "on_mouse_exited")
|
|
|
|
|
2022-02-13 15:52:19 +01:00
|
|
|
if default_material:
|
|
|
|
$MeshDataInstance.material = default_material
|
2020-07-18 22:42:50 +02:00
|
|
|
|
|
|
|
func on_mouse_entered():
|
2022-02-13 15:52:19 +01:00
|
|
|
if hover_material:
|
|
|
|
$MeshDataInstance.material = hover_material
|
2020-07-18 22:42:50 +02:00
|
|
|
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
|
2021-08-28 12:06:10 +02:00
|
|
|
|
|
|
|
_mouse_hover = true
|
2020-07-18 22:42:50 +02:00
|
|
|
|
|
|
|
func on_mouse_exited():
|
2022-02-13 15:52:19 +01:00
|
|
|
if default_material:
|
|
|
|
$MeshDataInstance.material = default_material
|
2020-07-18 22:42:50 +02:00
|
|
|
|
|
|
|
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
|
2021-08-28 12:06:10 +02:00
|
|
|
|
|
|
|
_mouse_hover = false
|
2020-07-18 22:42:50 +02:00
|
|
|
|
2021-08-28 00:29:24 +02:00
|
|
|
func _enter_tree():
|
|
|
|
_world = get_node("..")
|
|
|
|
|
|
|
|
if _world:
|
|
|
|
_world.connect("chunk_removed", self, "on_chunk_removed")
|
2021-08-27 23:07:58 +02:00
|
|
|
|
|
|
|
func _exit_tree():
|
2021-08-28 00:29:24 +02:00
|
|
|
if _world:
|
|
|
|
_world.disconnect("chunk_removed", self, "on_chunk_removed")
|
|
|
|
|
2021-08-27 23:07:58 +02:00
|
|
|
if _dungeon:
|
|
|
|
_dungeon.queue_free()
|
|
|
|
|
|
|
|
if _dungeon_back_teleporter:
|
|
|
|
_dungeon_back_teleporter.queue_free()
|
|
|
|
|
2021-08-28 12:06:10 +02:00
|
|
|
# workaround
|
|
|
|
func _unhandled_input(event):
|
|
|
|
# _input_event does not get InputEventMouseButtons (on wine) / it only gets them sometimes (on windows)
|
|
|
|
# might be an engine bug
|
|
|
|
if _is_windows && _mouse_hover && event is InputEventMouseButton && !event.pressed:
|
|
|
|
teleport()
|
|
|
|
|
2020-07-18 22:42:50 +02:00
|
|
|
func _input_event(camera: Object, event: InputEvent, click_position: Vector3, click_normal: Vector3, shape_idx: int):
|
2021-08-28 12:06:10 +02:00
|
|
|
if !_is_windows && event is InputEventMouseButton && !event.pressed:
|
2020-07-18 22:42:50 +02:00
|
|
|
teleport()
|
|
|
|
|
|
|
|
if event is InputEventScreenTouch && !event.pressed:
|
|
|
|
teleport()
|
|
|
|
|
|
|
|
func teleport():
|
2021-08-28 00:29:24 +02:00
|
|
|
if _world && _world._player:
|
|
|
|
var p : Entity = _world._player
|
2021-08-27 23:07:58 +02:00
|
|
|
|
2020-07-18 22:50:10 +02:00
|
|
|
if (p.get_body().transform.origin - transform.origin).length() > use_range:
|
|
|
|
return
|
2021-08-27 23:07:58 +02:00
|
|
|
|
|
|
|
if !_dungeon:
|
|
|
|
_dungeon = dungeon.instance() as Spatial
|
|
|
|
var t : Transform = global_transform
|
|
|
|
t = t.translated(Vector3(0, -500, 0))
|
|
|
|
_dungeon.transform = t
|
2021-08-28 00:55:59 +02:00
|
|
|
_dungeon.min_level = min_level
|
|
|
|
_dungeon.max_level = max_level
|
2021-08-29 23:38:15 +02:00
|
|
|
_dungeon.spawn_mobs = spawn_mobs
|
2021-08-29 19:38:58 +02:00
|
|
|
_dungeon.dungeon_seed = dungeon_seed
|
2021-08-27 23:07:58 +02:00
|
|
|
get_parent().add_child(_dungeon)
|
|
|
|
|
|
|
|
teleport_to = t.xform(Vector3())
|
|
|
|
#todo add this into the dungeon and just query
|
|
|
|
teleport_to -= Vector3(-5, -1, 5)
|
|
|
|
|
|
|
|
_dungeon_back_teleporter = dungeon_back_teleporter.instance() as Spatial
|
|
|
|
var tdb : Transform = global_transform
|
|
|
|
tdb = tdb.translated(Vector3(0, -500, 0))
|
2022-02-13 17:52:33 +01:00
|
|
|
tdb = tdb.translated(Vector3(1, 0, -1))
|
2021-08-27 23:07:58 +02:00
|
|
|
_dungeon_back_teleporter.transform = tdb
|
|
|
|
_dungeon_back_teleporter.teleport_to = global_transform.xform(Vector3())
|
|
|
|
get_parent().add_child(_dungeon_back_teleporter)
|
|
|
|
|
|
|
|
#turn off world
|
2021-08-28 00:29:24 +02:00
|
|
|
_world.active = false
|
2021-08-27 23:07:58 +02:00
|
|
|
#turn on dungeon
|
|
|
|
_dungeon.show()
|
2020-07-18 22:50:10 +02:00
|
|
|
|
2020-07-23 00:12:19 +02:00
|
|
|
p.get_body().teleport(teleport_to)
|
|
|
|
# p.get_body().transform.origin = teleport_to
|
2021-08-28 00:29:24 +02:00
|
|
|
|
|
|
|
|
2022-02-08 14:44:37 +01:00
|
|
|
func on_chunk_removed(chunk : TerrainChunk) -> void:
|
2021-08-28 00:29:24 +02:00
|
|
|
if chunk == owner_chunk:
|
|
|
|
queue_free()
|
|
|
|
|