Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task manager and task resource #217

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/addons/opensusinteraction/opensusinteraction.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extends EditorPlugin
var interact_resource_script
var interactmap_resource_script
var interactui_resource_script
var task_resource_script

#icons
var object_icon
Expand All @@ -13,6 +14,7 @@ func _enter_tree():
#load custom resources
interact_resource_script = preload("res://addons/opensusinteraction/resources/interact/interact.gd")
interactmap_resource_script = preload("res://addons/opensusinteraction/resources/interactmap/interactmap.gd")
task_resource_script = preload("res://addons/opensusinteraction/resources/interacttask/interacttask.gd")
interactui_resource_script = preload("res://addons/opensusinteraction/resources/interactui/interactui.gd")

#load icons
Expand All @@ -21,10 +23,11 @@ func _enter_tree():
#add custom resources
add_custom_type("Interact", "Resource", interact_resource_script, object_icon)
add_custom_type("InteractMap", "Resource", interactmap_resource_script, object_icon)
add_custom_type("InteractTask", "Resource", task_resource_script, object_icon)
add_custom_type("InteractUI", "Resource", interactui_resource_script, object_icon)


func _exit_tree():
remove_custom_type("Interact")
remove_custom_type("InteractMap")
remove_custom_type("InteractTask")
remove_custom_type("InteractUI")
43 changes: 35 additions & 8 deletions src/addons/opensusinteraction/resources/interact/interact.gd
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
tool
extends Resource

class_name Interact
#class_name Interact

enum type {ui = 1, map = 2}
export(type) var interact_type = 1
enum type {task = 0, ui = 1, map = 2}
export(type) var interact_type

#needed to instance new unique resources in editor
var base_task_resource:Resource = ResourceLoader.load("res://addons/opensusinteraction/resources/interacttask/interacttask.tres")
var base_ui_resource: Resource = ResourceLoader.load("res://addons/opensusinteraction/resources/interactui/interactui.tres")
var base_map_resource:Resource = ResourceLoader.load("res://addons/opensusinteraction/resources/interactmap/interactmap.tres")

#changed in the editor via overriding get(), set(), and get_property_list()
var task_res: Resource = base_task_resource.duplicate()
var ui_res: Resource = base_ui_resource.duplicate()
var map_res: Resource = base_map_resource.duplicate()

Expand All @@ -20,16 +22,29 @@ var interact_data: Dictionary = {}
func interact(_from: Node):
#print(interact_type)
match interact_type:
type.task:
task_res.interact(_from)
type.ui:
ui_res.interact(_from)
type.map:
map_res.interact(_from)

func init_resource(_from):
match interact_type:
type.task:
task_res.init_resource(_from)
type.ui:
ui_res.init_resource(_from)
type.map:
map_res.init_resource(_from)

func get_interact_data(_from: Node = null) -> Dictionary:
var interact_data: Dictionary = {}
var res_interact_data: Dictionary = {}
#print(interact_type)
match interact_type:
type.task:
res_interact_data = task_res.get_interact_data(_from)
type.ui:
res_interact_data = ui_res.get_interact_data(_from)
type.map:
Expand All @@ -47,13 +62,19 @@ func _init():

#EDITOR STUFF BELOW THIS POINT, DO NOT TOUCH UNLESS YOU KNOW WHAT YOU'RE DOING
#---------------------------------------------------------------------------------------------------
#overrides set(), allows for export var groups and display properties that don't
#match actual var names
#overrides set(), for property groups and to display custom/fake properties/vars
func _set(property, value):
# #add custom stuff to inspector and use this to see what it's trying to do
# #so you can figure out how to handle it
#print("setting ", property, " to ", value)
match property:
"task_resource":
#if new resource is a ui interact resource
if value is preload("res://addons/opensusinteraction/resources/interacttask/interacttask.gd"):
task_res = value
else:
#create new ui interact resource
task_res = base_task_resource.duplicate()
"ui_resource":
#if new resource is a ui interact resource
if value is preload("res://addons/opensusinteraction/resources/interactui/interactui.gd"):
Expand All @@ -71,20 +92,26 @@ func _set(property, value):
property_list_changed_notify()
return true

#overrides get(), allows for export var groups and display properties that don't
#match actual var names
#overrides get(), for property groups and to display custom/fake properties/vars
func _get(property):
match property:
"task_resource":
return task_res
"ui_resource":
return ui_res
"map_resource":
return map_res

#overrides get_property_list(), tells editor to show more vars in inspector
#overrides get_property_list(), tells editor to show custom/fake properties/vars in inspector
func _get_property_list():
# #if not Engine.editor_hint:
# # return []
var property_list: Array = []
property_list.append({"name": "task_resource",
"type": TYPE_OBJECT,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_RESOURCE_TYPE,
})
property_list.append({"name": "ui_resource",
"type": TYPE_OBJECT,
"usage": PROPERTY_USAGE_DEFAULT,
Expand Down
24 changes: 18 additions & 6 deletions src/addons/opensusinteraction/resources/interact/interact.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_resource type="Resource" load_steps=6 format=2]
[gd_resource type="Resource" load_steps=9 format=2]

[ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=1]
[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=2]
[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.tres" type="Resource" id=2]
[ext_resource path="res://addons/opensusinteraction/resources/interact/interact.gd" type="Script" id=3]
[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=4]
[ext_resource path="res://addons/opensusinteraction/resources/interacttask/interacttask.gd" type="Script" id=5]

[sub_resource type="Resource" id=1]
resource_local_to_scene = true
Expand All @@ -15,17 +17,27 @@ interact_data = {

[sub_resource type="Resource" id=2]
resource_local_to_scene = true
script = ExtResource( 2 )
ui_name = ""
resource_name = "InteractUI"
script = ExtResource( 4 )
ui_name = "clockset"
ui_data = {

}
advanced/reinstance = false

[sub_resource type="Resource" id=3]
resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 5 )
task_text = ""
ui_resource = SubResource( 2 )
outputs/toggle_map_interactions = false

[resource]
resource_local_to_scene = true
resource_name = "Interact"
script = ExtResource( 3 )
interact_type = 1
ui_resource = SubResource( 2 )
interact_type = 0
task_resource = SubResource( 3 )
ui_resource = ExtResource( 2 )
map_resource = SubResource( 1 )
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tool
extends Resource

class_name InteractMap
#class_name InteractMap

#name of the UI to open
export(NodePath) var interact_with
Expand All @@ -24,6 +24,12 @@ func interact(_from: Node):
#print(attached_to.get_node(interact_with))
MapManager.interact_with(attached_to.get_node(interact_with), attached_to, get_interact_data(_from))

func init_resource(_from: Node):
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("InteractMap resource trying to be initiated with no defined node")

func get_interact_data(_from: Node = null) -> Dictionary:
if attached_to == null and _from != null:
attached_to = _from
Expand Down
Loading