2025-01-12 12:15:18 +00:00
|
|
|
@tool
|
2025-01-12 11:36:41 +00:00
|
|
|
extends Sprite2D
|
2024-12-30 13:19:10 +00:00
|
|
|
|
2025-01-12 12:15:18 +00:00
|
|
|
signal interacted(success: bool)
|
|
|
|
|
2025-01-03 08:07:35 +00:00
|
|
|
@export var entity_name: String = ""
|
|
|
|
@export var texture_before: Texture2D
|
|
|
|
@export var texture_after: Texture2D
|
2025-01-12 12:15:18 +00:00
|
|
|
@export var one_shot := true
|
|
|
|
@export var interacted_times := 0
|
|
|
|
var prop_key := ""
|
2025-01-03 08:07:35 +00:00
|
|
|
|
2025-01-12 12:15:18 +00:00
|
|
|
@onready var sfx = $Sfx as Sfx
|
2025-01-08 00:51:09 +00:00
|
|
|
@onready var sign_mark = %Sign as Sign
|
2025-01-03 08:07:35 +00:00
|
|
|
@onready var area2d = %Area2D as Area2D
|
|
|
|
|
2025-01-12 12:15:18 +00:00
|
|
|
static var item_config_res = preload("res://asset/dialogue/item_description.dialogue")
|
|
|
|
var items: PackedStringArray
|
|
|
|
|
|
|
|
|
|
|
|
func _reload_items() -> void:
|
|
|
|
var id = item_config_res.titles["PropItems"]
|
|
|
|
var current_line = item_config_res.lines[id]
|
|
|
|
while current_line:
|
|
|
|
if current_line.has("translation_key"):
|
|
|
|
items.append(current_line.translation_key)
|
|
|
|
if not current_line.has("next_id") or current_line.next_id == "end":
|
|
|
|
break
|
|
|
|
current_line = item_config_res.lines[current_line.next_id]
|
|
|
|
|
2025-01-03 08:07:35 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
2025-01-12 12:15:18 +00:00
|
|
|
if Engine.is_editor_hint():
|
|
|
|
_reload_items()
|
|
|
|
notify_property_list_changed()
|
|
|
|
return
|
|
|
|
if interacted_times and texture_after:
|
|
|
|
texture = texture_after
|
|
|
|
else:
|
|
|
|
texture = texture_before
|
2025-01-03 08:07:35 +00:00
|
|
|
area2d.body_entered.connect(_reset)
|
|
|
|
area2d.body_exited.connect(_on_cancel)
|
|
|
|
sign_mark.interacted.connect(_on_interacted)
|
|
|
|
sign_mark.cancel.connect(_on_cancel)
|
|
|
|
|
|
|
|
|
|
|
|
func _reset(_body = null) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _on_cancel(_body = null) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func _on_interacted() -> void:
|
2025-01-12 12:15:18 +00:00
|
|
|
if one_shot and interacted_times:
|
|
|
|
return
|
|
|
|
sfx.play()
|
2025-01-12 11:36:41 +00:00
|
|
|
var key = SceneManager.get_current_selected_prop()
|
2025-01-12 12:15:18 +00:00
|
|
|
# print("prop_key", key)
|
|
|
|
if key != prop_key:
|
|
|
|
return
|
|
|
|
interacted_times += 1
|
|
|
|
if texture_after:
|
|
|
|
texture = texture_after
|
|
|
|
interacted.emit()
|
|
|
|
print("%s interacted with %s" % [entity_name, prop_key])
|
|
|
|
|
|
|
|
|
|
|
|
func _get_property_list() -> Array[Dictionary]:
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
"name": "prop_key",
|
|
|
|
"type": TYPE_STRING,
|
|
|
|
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
|
|
|
|
"hint_string": ",".join(items),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
func _get(property: StringName) -> Variant:
|
|
|
|
if property == "prop_key":
|
|
|
|
return prop_key
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
|
|
func _set(property: StringName, value: Variant) -> bool:
|
|
|
|
if property == "prop_key":
|
|
|
|
prop_key = value
|
|
|
|
return true
|
|
|
|
return false
|