Skip to content

Commit

Permalink
Cleaned up and preparation
Browse files Browse the repository at this point in the history
* Generally cleaned up code in standbutton and interactpoint
* Cleaned up a little in interacttask
* Added methods to interacttask for consistency
* Added init_resource to all resources. This should be called under ready of the nodes they are attached to. Self should be passed as an input to this function.
* init_resource will be used to register tasks with the taskmanager, there is very little use for it for other resources, except resources that need access to the scene tree like InteractMap and tasks
  • Loading branch information
TheSecondReal0 committed Nov 27, 2020
1 parent 2fe4f7d commit 3fb0016
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 69 deletions.
17 changes: 16 additions & 1 deletion src/addons/opensusinteraction/resources/interact/interact.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ extends Resource

#class_name Interact

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

#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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends Resource

#class_name InteractTask

export(String) var task_name
export(String) var task_text

#export(Resource) var ui_name = base_ui_resource.duplicate()

Expand All @@ -26,26 +26,47 @@ var base_map_resource:Resource = ResourceLoader.load("res://addons/opensusintera
#changed in the editor via overriding get(), set(), and get_property_list()
var ui_res: Resource = base_ui_resource.duplicate()

func init_task():
TaskManager.add_task_resource(self)
#node this task is attached to
var attached_to: Node

func init_task(_from: Node = null):
print(task_text)
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

func get_task_info() -> Dictionary:
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")

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")
return gen_task_info()

func gen_task_info() -> Dictionary:
var info:Dictionary = {}
info["task_name"] = task_name
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
return info

func _init():
#print("task init ", task_name)
#ensures customizing this resource won't change other resources
if Engine.editor_hint:
resource_local_to_scene = true
#else:
# TaskManager.connect("init_tasks", self, "init_task")

#EDITOR STUFF BELOW THIS POINT, DO NOT TOUCH UNLESS YOU KNOW WHAT YOU'RE DOING
#---------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ advanced/reinstance = false
resource_local_to_scene = true
resource_name = "InteractTask"
script = ExtResource( 1 )
task_name = ""
task_text = ""
ui_resource = SubResource( 1 )
inputs/toggle_items = false
outputs/toggle_items = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var interact_data: Dictionary = {}
func interact(_from: Node = null):
UIManager.open_menu(ui_name, get_interact_data(_from), reinstance)

func init_resource(_from: Node = null):
pass

func get_interact_data(_from: Node = null) -> Dictionary:
var reported_interact_data = interact_data
for i in ui_data.keys():
Expand Down
6 changes: 3 additions & 3 deletions src/assets/autoload/taskmanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var player_tasks: Dictionary = {}
#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 @@ -65,9 +67,7 @@ func new_task(players: Array, task_info: Dictionary):
func register_task(task_info: Dictionary) -> int:
var new_task_id: int = gen_unique_id()
var new_task_dict: Dictionary = {"state": task_state.NOT_STARTED, "assigned_to": []}
for i in task_info.keys():
#do stuff with task info
pass
#do stuff with task info here
task_dict[new_task_id] = new_task_dict
return new_task_id

Expand Down
1 change: 1 addition & 0 deletions src/assets/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ 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
Expand Up @@ -2,30 +2,12 @@ extends StaticBody2D

export(Resource) var interact
export(String) var display_text
#export(type) var node_or_ui
#export(NodePath) var node_path
#export(String) var ui_name
#export(Dictionary) var interact_info

var interact_data: Dictionary = {} setget , get_interact_data

#func _enter_tree():
# if node_or_ui == type.node:
# interact_info["linkedNode"] = get_node(node_path)

func _ready():
pass
#if interact != null and interact.has_method("get_interact_data"):
#interact_data = interact.get_interact_data()
#interact_data["display_text"] = display_text
#interact_data["interact"] = test_resource.ui_name
# print(interact_data)
# interact_data["display_text"] = display_text
# match node_or_ui:
# type.node:
# interact_data["interact"] = get_node(node_path)
# type.ui:
# interact_data["interact"] = ui_name
interact.init_resource(self)
# print(interact.get_interact_data())

func get_interact_data():
#var interact_resource: Interact = interact
Expand All @@ -34,12 +16,5 @@ func get_interact_data():
return interact_data

func interact():
print(interact_data)
#print(interact_data)
interact.interact(self)
# match node_or_ui:
# type.node:
# if not get_node(node_path):
# return
# MapManager.interact_with(get_node(node_path), self, interact_info)
# type.ui:
# UIManager.open_menu(ui_name, interact_info)
18 changes: 3 additions & 15 deletions src/assets/maps/common/interactables/standbutton/standbutton.gd
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
extends Area2D

export(Resource) var interact
#enum type {node, ui}
#export(type) var node_or_ui
#export(NodePath) var node_path
#export(String) var ui_name
#export(Dictionary) var interact_info
export(bool) var only_main_player = false
export(int, 1, 10000) var players_to_activate = 1
export(bool) var interact_on_exit = true
var overlappingBodies: Array = []
var pressed: bool = false

#func _enter_tree():
# if node_or_ui == type.node:
# interact_info["linkedNode"] = get_node(node_path)
func _ready():
interact.init_resource(self)
# print(interact.get_interact_data())

func interact():
interact.interact(self)
# match node_or_ui:
# type.node:
# if not get_node(node_path):
# return
# MapManager.interact_with(get_node(node_path), self, interact_info)
# type.ui:
# UIManager.open_menu(ui_name, interact_info)

func update():
if overlappingBodies.size() < players_to_activate:
Expand Down
59 changes: 43 additions & 16 deletions src/assets/maps/test/test.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=2]
[gd_scene load_steps=23 format=2]

[ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1]
[ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2]
Expand All @@ -7,21 +7,23 @@
[ext_resource path="res://assets/maps/common/interactables/interactpoint/interactpoint.tscn" type="PackedScene" id=5]
[ext_resource path="res://assets/maps/common/elements/walls/wallhorizontal/wallhorizontal.tscn" type="PackedScene" id=6]
[ext_resource path="res://assets/maps/common/elements/walls/wallvertical/wallvertical.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/opensusinteraction/resources/interacttask/interacttask.gd" type="Script" id=8]
[ext_resource path="res://addons/opensusinteraction/resources/interact/interact.gd" type="Script" id=9]
[ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=10]
[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=11]

[sub_resource type="Resource" id=10]
[sub_resource type="Resource" id=13]
resource_local_to_scene = true
resource_name = "InteractMap"
script = ExtResource( 10 )
interact_with = NodePath("../testdoor")
interact_with = NodePath("")
interact_data = {

}

[sub_resource type="Resource" id=11]
[sub_resource type="Resource" id=14]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = ""
ui_data = {
Expand All @@ -33,20 +35,21 @@ advanced/reinstance = false
resource_local_to_scene = true
script = ExtResource( 9 )
interact_type = 2
ui_resource = SubResource( 11 )
map_resource = SubResource( 10 )
ui_resource = SubResource( 14 )
map_resource = SubResource( 13 )

[sub_resource type="Resource" id=12]
[sub_resource type="Resource" id=15]
resource_local_to_scene = true
resource_name = "InteractMap"
script = ExtResource( 10 )
interact_with = NodePath("clocktext")
interact_with = NodePath("")
interact_data = {

}

[sub_resource type="Resource" id=13]
[sub_resource type="Resource" id=16]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = ""
ui_data = {
Expand All @@ -58,10 +61,10 @@ advanced/reinstance = false
resource_local_to_scene = true
script = ExtResource( 9 )
interact_type = 2
ui_resource = SubResource( 13 )
map_resource = SubResource( 12 )
ui_resource = SubResource( 16 )
map_resource = SubResource( 15 )

[sub_resource type="Resource" id=14]
[sub_resource type="Resource" id=17]
resource_local_to_scene = true
resource_name = "InteractMap"
script = ExtResource( 10 )
Expand All @@ -70,10 +73,11 @@ interact_data = {

}

[sub_resource type="Resource" id=15]
[sub_resource type="Resource" id=18]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = "chatbox"
ui_name = ""
ui_data = {

}
Expand All @@ -83,8 +87,28 @@ advanced/reinstance = false
resource_local_to_scene = true
script = ExtResource( 9 )
interact_type = 1
ui_resource = SubResource( 15 )
map_resource = SubResource( 14 )
ui_resource = SubResource( 18 )
map_resource = SubResource( 17 )

[sub_resource type="Resource" id=19]
resource_local_to_scene = true
resource_name = "InteractUI"
script = ExtResource( 11 )
ui_name = ""
ui_data = {

}
advanced/reinstance = false

[sub_resource type="Resource" id=11]
resource_local_to_scene = true
script = ExtResource( 8 )
task_text = "sup doggy"
ui_resource = SubResource( 19 )
inputs/toggle_items = false
outputs/toggle_items = false
outputs/toggle_map_interactions = false
outputs/toggle_tasks = false

[node name="test" type="YSort"]

Expand Down Expand Up @@ -179,6 +203,9 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="tasktest" parent="." instance=ExtResource( 5 )]
interact = SubResource( 11 )

[node name="spawnpoints" type="Node2D" parent="."]

[node name="Position2D" type="Position2D" parent="spawnpoints"]
Expand Down

0 comments on commit 3fb0016

Please sign in to comment.