82 lines
2.1 KiB
GDScript
82 lines
2.1 KiB
GDScript
extends Sprite2D
|
|
|
|
@export_enum("left", "right", "1", "2", "3", "4", "5", "6", "7", "8", "9") var portal_name := "left":
|
|
set(value):
|
|
#if portal_name:
|
|
#remove_from_group("portal_"+portal_name)
|
|
portal_name = value
|
|
#add_to_group("portal_"+value)
|
|
name = "portal_" + value
|
|
@export var target_scene := "c02_s00"
|
|
@export_enum("none", "left", "right", "1", "2", "3", "4", "5", "6", "7", "8", "9")
|
|
var target_portal := "none"
|
|
|
|
|
|
@onready var sign_mark = %Sign as Sign
|
|
@onready var area2d = %Area2D as Area2D
|
|
|
|
var activated := false
|
|
var action_times := 0
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
name = "portal_" + portal_name
|
|
area2d.body_entered.connect(_reset)
|
|
area2d.body_exited.connect(_on_cancel)
|
|
sign_mark.interacted.connect(_on_interacted)
|
|
sign_mark.cancel.connect(_on_cancel)
|
|
if target_portal == "none":
|
|
sign_mark.show_sign = false
|
|
# if GlobalConfig.DEBUG:
|
|
# var label = Label.new()
|
|
# label.text = portal_name
|
|
# label.name = "Label"
|
|
# add_child(label)
|
|
|
|
|
|
func _on_interacted() -> void:
|
|
if target_portal == "none":
|
|
return
|
|
# 传送
|
|
%Sfx.play()
|
|
if GlobalConfig.DEBUG:
|
|
print("传送前往", target_scene, target_portal)
|
|
var ground_loader = SceneManager.get_ground_loader() as GroundLoader
|
|
if ground_loader:
|
|
ground_loader.transition_to_scene(target_scene, target_portal)
|
|
|
|
|
|
func _on_cancel(_body = null):
|
|
activated = false
|
|
|
|
|
|
func _reset(_body):
|
|
activated = true
|
|
|
|
|
|
# 暂时不启用自动传送
|
|
# func _input(event: InputEvent) -> void:
|
|
# # 长按自动传送
|
|
# if activated:
|
|
# if portal_name == "left" and target_portal == "right":
|
|
# if event.is_action("left"):
|
|
# action_times += 1
|
|
# elif event.is_action("right"):
|
|
# action_times = 0
|
|
# if action_times >= 7:
|
|
# activated = false
|
|
# action_times = 0
|
|
# %Sfx.play()
|
|
# _on_interacted()
|
|
# if portal_name == "right" and target_portal == "left":
|
|
# if event.is_action("right"):
|
|
# action_times += 1
|
|
# elif event.is_action("left"):
|
|
# action_times = 0
|
|
# if action_times >= 7:
|
|
# activated = false
|
|
# action_times = 0
|
|
# %Sfx.play()
|
|
# _on_interacted()
|