97 lines
2.5 KiB
GDScript
97 lines
2.5 KiB
GDScript
@tool
|
|
|
|
class_name Gaslight extends Interactable2D
|
|
|
|
# 点燃信号
|
|
signal lighted
|
|
|
|
@export var animation_low_mode := false
|
|
@export var hide_texture := false:
|
|
set(value):
|
|
hide_texture = value
|
|
if is_node_ready():
|
|
place_sprite2d.visible = not hide_texture
|
|
@export var gaslight_texture: Texture2D:
|
|
set(value):
|
|
gaslight_texture = value
|
|
if is_node_ready():
|
|
point_light.texture = gaslight_texture
|
|
@export var ground_light_texture: Texture2D:
|
|
set(value):
|
|
ground_light_texture = value
|
|
if is_node_ready():
|
|
point_light_ground.texture = ground_light_texture
|
|
@export var gaslight_energy := 1.0:
|
|
set(value):
|
|
gaslight_energy = value
|
|
if is_node_ready():
|
|
point_light.energy = gaslight_energy
|
|
@export var gaslight_ground_energy := 1.0:
|
|
set(value):
|
|
gaslight_ground_energy = value
|
|
if is_node_ready():
|
|
point_light_ground.energy = gaslight_ground_energy
|
|
@export var ground_height_offset := 0.0:
|
|
set(value):
|
|
ground_height_offset = value
|
|
if is_node_ready():
|
|
point_light_ground.position.y = ground_height_offset
|
|
@export var debug_light_switch := false:
|
|
set(value):
|
|
debug_light_switch = value
|
|
if Engine.is_editor_hint() and is_node_ready():
|
|
_switch_gaslight(debug_light_switch)
|
|
|
|
@onready var point_light = $PointLight2D as PointLight2D
|
|
@onready var point_light_ground = $PointLightGround2D as PointLight2D
|
|
@onready var light_sprite2d = $"灯光" as AnimatedSprite2D
|
|
@onready var place_sprite2d = $"灯座" as Sprite2D
|
|
|
|
|
|
func _ready() -> void:
|
|
super._ready()
|
|
if Engine.is_editor_hint():
|
|
_switch_gaslight(debug_light_switch)
|
|
|
|
point_light_ground.position.y = ground_height_offset
|
|
place_sprite2d.visible = not hide_texture
|
|
|
|
point_light.texture = gaslight_texture
|
|
point_light.energy = gaslight_energy
|
|
point_light_ground.texture = ground_light_texture
|
|
point_light_ground.energy = gaslight_ground_energy
|
|
|
|
if interacted_times > 0:
|
|
_switch_gaslight()
|
|
else:
|
|
_switch_gaslight(false)
|
|
interacted.connect(_gaslight_interacted)
|
|
|
|
# 永久打开煤油灯
|
|
func turn_on():
|
|
# 保存打开次数
|
|
interacted_times = 1
|
|
_switch_gaslight()
|
|
_check_sign_display()
|
|
|
|
|
|
func _switch_gaslight(state := true):
|
|
point_light.enabled = state
|
|
point_light_ground.enabled = state
|
|
light_sprite2d.visible = state
|
|
|
|
|
|
func _gaslight_interacted():
|
|
# TODO
|
|
SceneManager.pop_debug_dialog_info("音效", "点亮煤油灯")
|
|
# 播放点亮煤油灯的动画
|
|
if animation_low_mode:
|
|
# 低位 6 号
|
|
SceneManager.freeze_player(2.0, 6)
|
|
else:
|
|
# 高位 5 号
|
|
SceneManager.freeze_player(2.0, 5)
|
|
await get_tree().create_timer(1.8).timeout
|
|
_switch_gaslight()
|
|
lighted.emit()
|