-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractable-area.gd
85 lines (67 loc) · 2.7 KB
/
interactable-area.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Attach this script to any Area2D object that represents an interactable
extends Area2D
var entered = false
# Set this to the sprite that this interactable area is related to
# TODO: This is better for testing purposes but we might want to auto grab this in on_ready
@export var sprite : Sprite2D;
# Set the correct type of object this is
enum {CHARACTER, ITEM_C, ITEM_V}
@export_enum("Character", "Item-Collectable", "Item-Viewable") var obj_type
# Set to the file location holding the dialogue if it exists
@export_file("*.json") var dialogue_file
# Set this if you want to manually set dialogue (for small snippets)
@export var text : String = ""
# Set this if this interactable should transition us into another scene
# (This would be for close-ups of items as well as level transitions)
@export_file("*.tscn") var transition_scene
# For debugging purposes:
@export var interactable_area_name : String;
@export var reposition = true
var shader = preload("res://world.gdshader")
func _ready():
# $object.texture = load(image)
if (not sprite):
print("ERROR: You did not attach a sprite to an interactable area")
sprite.material = ShaderMaterial.new()
sprite.material.shader = shader
entered = false
sprite.material.set_shader_parameter("outline_enabled", false)
func _on_body_entered(body):
if (interactable_area_name):
print("Entered interactable area:", interactable_area_name)
entered = true
func _on_body_exited(body):
if (interactable_area_name):
print("Exited interactable area:", interactable_area_name)
entered = false
sprite.material.set_shader_parameter("outline_enabled", false)
func _input(event):
if entered and event.is_action_pressed("ui_accept") and len(get_overlapping_areas()) > 0:
if dialogue_file:
use_dialogue()
if obj_type == ITEM_C:
# TODO: Add to inventory and remove from world
pass
if (interactable_area_name):
if interactable_area_name == "sapling":
print("Activiating exit...")
$"../Sign".dialogue_file = ""
$"../Sign".transition_scene = "res://outside.tscn"
global.darkforestdefeated = true
if interactable_area_name == "witch" and global.darkforestdefeated:
print("Witch dialogue retrigger")
global.witchGone = true
if transition_scene:
print("transitioning to:", transition_scene)
if reposition:
global.returnPosition = $"../Crow".position
get_tree().change_scene_to_file(transition_scene)
func _process(delta):
if entered == true and len(get_overlapping_areas()) > 0:
sprite.material.set_shader_parameter("outline_enabled", true)
pass
func use_dialogue():
var dialogue = get_parent().get_node("Crow").get_node("Dialogue")
dialogue.dialogue_file = dialogue_file
if dialogue_file:
dialogue.start()