@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() 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 Engine.is_editor_hint(): _switch_gaslight(debug_light_switch) return if interacted_times > 0: _switch_gaslight() else: _switch_gaslight(false) interacted.connect(_gaslight_interacted) interact_mismatch_failed.connect(_on_mismatch) func _on_mismatch(): SceneManager.pop_center_notification(tr("ui_switch_prop")) # 永久打开煤油灯 func turn_on(gradually := true): # 如果已经亮了,退出 if interacted_times > 0: return # 保存打开次数 interacted_times = 1 _switch_gaslight(true, gradually) _check_sign_display() func _switch_gaslight(state := true, gradually := false): var engrgy1 = gaslight_energy var engrgy2 = gaslight_ground_energy if not gradually or not is_node_ready(): point_light.enabled = state point_light_ground.enabled = state light_sprite2d.visible = state return var tween = create_tween() if state: light_sprite2d.modulate.a = 0.0 point_light.energy = 0.0 point_light_ground.energy = 0.0 point_light.enabled = state point_light_ground.enabled = state light_sprite2d.visible = state tween.tween_property(point_light, "energy", engrgy1, 1.0) tween.parallel().tween_property(point_light_ground, "energy", engrgy2, 1.0) tween.parallel().tween_property(light_sprite2d, "modulate:a", 1.0, 1.0) else: tween.tween_property(point_light, "energy", 0.0, 1.0) tween.parallel().tween_property(point_light_ground, "energy", 0.0, 1.0) tween.parallel().tween_property(light_sprite2d, "modulate:a", 0.0, 1.0) tween.tween_callback(func(): point_light.enabled = false point_light_ground.enabled = false light_sprite2d.visible = false point_light.energy = engrgy1 point_light_ground.energy = engrgy2 light_sprite2d.modulate.a = 1.0 ) func _gaslight_interacted(): # 播放点亮煤油灯的动画 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(true, true) lighted.emit()