Skip to content

Commit

Permalink
Basic functionality done
Browse files Browse the repository at this point in the history
The task system and resource now has basic functionality
  • Loading branch information
TheSecondReal0 committed Nov 28, 2020
1 parent 3fb0016 commit bac94c2
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 203 deletions.
4 changes: 2 additions & 2 deletions src/addons/opensusinteraction/opensusinteraction.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +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("Task", "Resource", task_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("Task")
remove_custom_type("InteractTask")
remove_custom_type("InteractUI")
16 changes: 15 additions & 1 deletion src/addons/opensusinteraction/resources/interact/interact.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extends Resource
#class_name Interact

enum type {task = 0, ui = 1, map = 2}
export(type) var interact_type = 1
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")
Expand Down Expand Up @@ -68,6 +68,13 @@ func _set(property, value):
# #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 @@ -88,6 +95,8 @@ func _set(property, value):
#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":
Expand All @@ -98,6 +107,11 @@ 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
25 changes: 23 additions & 2 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=5 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.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 @@ -13,10 +15,29 @@ interact_data = {

}

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

}
advanced/reinstance = false

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

[resource]
resource_local_to_scene = true
resource_name = "Interact"
script = ExtResource( 3 )
interact_type = 1
interact_type = 0
task_resource = SubResource( 14 )
ui_resource = ExtResource( 2 )
map_resource = SubResource( 1 )
108 changes: 55 additions & 53 deletions src/addons/opensusinteraction/resources/interacttask/interacttask.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,39 @@ var ui_res: Resource = base_ui_resource.duplicate()
#node this task is attached to
var attached_to: Node

func init_task(_from: Node = null):
print(task_text)
#assigned by TaskManager
var task_id: int

func interact(_from: Node = null):
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("Task resource trying to be used with no defined node")
return
pass
push_error("InteractTask resource trying to be used with no defined node")
ui_res.interact(_from)

func init_resource(_from: Node):
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("Task resource trying to be initiated with no defined node")
push_error("InteractTask resource trying to be initiated with no defined node")
task_id = TaskManager.register_task(gen_task_info())

func get_interact_data(_from: Node = null) -> Dictionary:
if attached_to == null and _from != null:
attached_to = _from
if attached_to == null:
push_error("Task resource trying to be used with no defined node")
push_error("InteractTask resource trying to be used with no defined node")
return gen_task_info()

func gen_task_info() -> Dictionary:
var info:Dictionary = {}
var info: Dictionary = {}
info["task_text"] = task_text
# info["ui_name"] = ui_name
info["item_inputs"] = item_inputs
info["item_outputs"] = item_outputs
info["task_outputs"] = task_outputs
info["attached_node"] = attached_to
info["task_resource"] = self
#info["ui_resource"] = ui_res
return info

func _init():
Expand Down Expand Up @@ -148,8 +152,6 @@ func _get(property):

#overrides get_property_list(), tells editor to show more properties in inspector
func _get_property_list():
# if not Engine.editor_hint:
# return []
var property_list: Array = []

property_list.append({"name": "ui_resource",
Expand All @@ -159,36 +161,36 @@ func _get_property_list():
})

#item input toggle
property_list.append({
"name": "inputs/toggle_items",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
#item input array field
if item_inputs_on:
property_list.append({
"name": "inputs/input_items",
"type": TYPE_STRING_ARRAY,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
# property_list.append({
# "name": "inputs/toggle_items",
# "type": TYPE_BOOL,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_NONE,
# })
# #item input array field
# if item_inputs_on:
# property_list.append({
# "name": "inputs/input_items",
# "type": TYPE_STRING_ARRAY,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_NONE,
# })

#item output toggle
property_list.append({
"name": "outputs/toggle_items",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
#item output array field
if item_outputs_on:
property_list.append({
"name": "outputs/output_items",
"type": TYPE_STRING_ARRAY,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
# property_list.append({
# "name": "outputs/toggle_items",
# "type": TYPE_BOOL,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_NONE,
# })
# #item output array field
# if item_outputs_on:
# property_list.append({
# "name": "outputs/output_items",
# "type": TYPE_STRING_ARRAY,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_NONE,
# })

#item output toggle
property_list.append({
Expand All @@ -207,18 +209,18 @@ func _get_property_list():
})

#task output toggle
property_list.append({
"name": "outputs/toggle_tasks",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_NONE,
})
if task_outputs_on:
property_list.append({
"name": "outputs/output_tasks",
"type": TYPE_ARRAY,
"usage": PROPERTY_USAGE_DEFAULT,
"hint": PROPERTY_HINT_DIR,
"hint_string": ""
})
# property_list.append({
# "name": "outputs/toggle_tasks",
# "type": TYPE_BOOL,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_NONE,
# })
# if task_outputs_on:
# property_list.append({
# "name": "outputs/output_tasks",
# "type": TYPE_ARRAY,
# "usage": PROPERTY_USAGE_DEFAULT,
# "hint": PROPERTY_HINT_DIR,
# "hint_string": ""
# })
return property_list
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[ext_resource path="res://addons/opensusinteraction/resources/interacttask/interacttask.gd" type="Script" id=1]
[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=2]

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

}
Expand All @@ -18,8 +18,5 @@ resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 1 )
task_text = ""
ui_resource = SubResource( 1 )
inputs/toggle_items = false
outputs/toggle_items = false
ui_resource = SubResource( 13 )
outputs/toggle_map_interactions = false
outputs/toggle_tasks = false
23 changes: 6 additions & 17 deletions src/assets/autoload/taskmanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,11 @@ var task_transitions: Dictionary = {task_state.HIDDEN: [task_state.NOT_STARTED],
task_state.COMPLETED: []
}

#stores info of each task, for instance it's type (see task_type)
#var tasks: Dictionary = {"clockset": {"type": task_type.BINARY}}
#array with all names of tasks that can be assigned, most likely used for map specific tasks
#var enabled_tasks: Array = ["clockset"]
#dictionary that stores the task IDs corresponding to the tasks assigned to the player
var player_tasks: Dictionary = {}
#stores task info corresponding to task IDs
#format: {<task id>: {name: <task_name>, type: <task type>, state: <task state>, assigned_to: [<network IDs of players task is assigned to>]}
var task_dict: Dictionary = {}

signal init_tasks

func _ready():
randomize()
#print(gen_unique_id())
Expand Down Expand Up @@ -56,19 +49,15 @@ func transition_task(task_id: int, new_state: int) -> bool:
task_dict[task_id].state = new_state
return true

func new_task(players: Array, task_info: Dictionary):
#register task
var new_task_id = register_task(task_info)

#assign task to players
for i in players:
assign_task(i, new_task_id)

func register_task(task_info: Dictionary) -> int:
func register_task(task_data: Dictionary) -> int:
var new_task_id: int = gen_unique_id()
var new_task_dict: Dictionary = {"state": task_state.NOT_STARTED, "assigned_to": []}
print("registering task with ID ", new_task_id)
var new_task_dict: Dictionary = task_data
new_task_dict["state"] = task_state.NOT_STARTED
new_task_dict["assigned_to"] = []
#do stuff with task info here
task_dict[new_task_id] = new_task_dict
print("task registered: ", new_task_dict)
return new_task_id

func assign_task(player_id: int, task_id: int) -> void:
Expand Down
1 change: 0 additions & 1 deletion src/assets/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ master func _on_maps_spawn(spawnPositions: Array):
spawnPointDict[players.keys()[i]] = spawn_pos
#spawn players
rpc("createPlayers", Network.get_player_names(), spawnPointDict)
TaskManager.emit_signal("init_tasks")
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
extends StaticBody2D

export(Resource) var interact
export(Resource) var interact_resource
export(String) var display_text

var interact_data: Dictionary = {} setget , get_interact_data

func _ready():
interact.init_resource(self)
interact_resource.init_resource(self)
# print(interact.get_interact_data())

func get_interact_data():
#var interact_resource: Interact = interact
interact_data = interact.get_interact_data()
interact_data = interact_resource.get_interact_data()
interact_data["display_text"] = display_text
#interact_data["interact_resource"] = interact_resource
interact_data["interact_node"] = self
return interact_data

func interact():
#print(interact_data)
interact.interact(self)
interact_resource.interact(self)
Loading

0 comments on commit bac94c2

Please sign in to comment.