70 lines
1.6 KiB
GDScript
Executable file
70 lines
1.6 KiB
GDScript
Executable file
extends Node3D
|
|
class_name Item
|
|
|
|
|
|
var item_dialogue: Dictionary
|
|
@export_file('*.json') var item_dialogue_file: String
|
|
|
|
@onready var item_collision = get_node_or_null("collision")
|
|
@onready var item_text = get_node_or_null("text")
|
|
@onready var item_focus = get_node_or_null("focus")
|
|
@onready var item_camera = get_node_or_null("camera")
|
|
|
|
var dialogue_scene = load("res://src/ui/dialogue/dialogue.tscn")
|
|
var dialogue: Control
|
|
|
|
var state_machine: StateMachine = null
|
|
|
|
|
|
func _ready() -> void:
|
|
add_to_group("items")
|
|
|
|
dialogue = dialogue_scene.instantiate()
|
|
add_child(dialogue)
|
|
dialogue.visible = false
|
|
|
|
if item_dialogue_file != "":
|
|
load_dialogue(item_dialogue_file)
|
|
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var tmpCamera: Camera3D = get_viewport().get_camera_3d()
|
|
dialogue.position = tmpCamera.unproject_position(item_text.get_global_transform().origin)
|
|
|
|
|
|
func get_collision() -> StaticBody3D:
|
|
return item_collision
|
|
|
|
|
|
func load_dialogue(path: String) -> void:
|
|
var file = FileAccess.open(item_dialogue_file, FileAccess.READ)
|
|
item_dialogue = JSON.parse_string( file.get_as_text() )
|
|
|
|
|
|
func get_interaction() -> String:
|
|
var action: String
|
|
if not item_dialogue.has("dialogue"):
|
|
action = "none"
|
|
else:
|
|
action = item_dialogue["dialogue"]["init"]["action"]
|
|
return action
|
|
|
|
|
|
func get_dialogue() -> Dictionary:
|
|
if not item_dialogue.has("dialogue"):
|
|
return item_dialogue
|
|
else:
|
|
return {"init":{"text" : "Test Dialogue for %s" % item_dialogue.meta.name, "next":"exit"}}
|
|
|
|
|
|
func dialogue_show() -> void:
|
|
dialogue.visible = true
|
|
|
|
func dialogue_hide() -> void:
|
|
dialogue.visible = false
|
|
|
|
|
|
|
|
|
|
|