75 lines
2.0 KiB
GDScript
75 lines
2.0 KiB
GDScript
extends Sprite2D
|
|
|
|
# @export var entity_config: EntityConfig:
|
|
# set(value):
|
|
# entity_config = value
|
|
|
|
@export var entity_name: String = ""
|
|
@export var note_key: String = ""
|
|
@export var texture_cover: Texture2D
|
|
@export var texture_note: Texture2D
|
|
|
|
@onready var sprite2d = %AnimatedSoundSprite2D as AnimatedSoundSprite2D
|
|
@onready var sign_mark = %Sign as Sign
|
|
@onready var area2d = %Area2D as Area2D
|
|
|
|
var content_res = preload("res://asset/dialogue/inspect_content.dialogue") as DialogueResource
|
|
var inspecting = false
|
|
|
|
|
|
func _ready() -> void:
|
|
area2d.body_entered.connect(_reset)
|
|
area2d.body_exited.connect(_on_cancel)
|
|
sign_mark.interacted.connect(_on_interacted)
|
|
sign_mark.cancel.connect(_on_cancel)
|
|
# if GlobalConfig.DEBUG:
|
|
# var label = DebugLabel.new()
|
|
# add_child(label)
|
|
# label.name = "DebugLabel"
|
|
|
|
|
|
func _on_interacted() -> void:
|
|
if not texture_cover or not texture_note:
|
|
push_error("entity/inspectable.gd: texture_cover or texture_note is not set")
|
|
return
|
|
if inspecting:
|
|
return
|
|
%Sfx.play()
|
|
# connect inspector quit signal
|
|
var inspector = SceneManager.get_inspector()
|
|
if inspector:
|
|
inspector.quit.connect(_on_quit_inspector)
|
|
if not texture_note:
|
|
texture_note = texture_cover
|
|
var inspection_note = _get_tr_content()
|
|
inspector.pop_standard_inspection(texture_cover, texture_note, inspection_note)
|
|
inspecting = true
|
|
sign_mark.show_sign = false
|
|
|
|
func _get_tr_content():
|
|
var inspection_note = ""
|
|
# get note content
|
|
var line_id = content_res.titles.get(note_key)
|
|
while line_id and line_id != "end":
|
|
var line = content_res.lines[line_id]
|
|
if line.has("text"):
|
|
inspection_note += tr(line.get("text")) + "\n"
|
|
line_id = line.get("next_id")
|
|
return inspection_note
|
|
|
|
func _on_quit_inspector():
|
|
var inspector = SceneManager.get_inspector()
|
|
if inspector:
|
|
# disconnect inspector quit signal
|
|
inspector.quit.disconnect(_on_quit_inspector)
|
|
inspecting = false
|
|
sign_mark.show_sign = true
|
|
|
|
|
|
func _on_cancel(_body = null):
|
|
inspecting = false
|
|
|
|
|
|
func _reset(_body):
|
|
inspecting = false
|