Skip to content

Commit

Permalink
reworking portals
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashScreen committed Jul 12, 2023
1 parent a054827 commit 1d3bda6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
10 changes: 9 additions & 1 deletion Tests/TestAssets/test_network_1.tres
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="Network" load_steps=17 format=3 uid="uid://cgd1gvxr1bf58"]
[gd_resource type="Resource" script_class="Network" load_steps=20 format=3 uid="uid://cgd1gvxr1bf58"]

[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_point.gd" id="1_4qg4f"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_edge.gd" id="2_rcxn3"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_portal.gd" id="3_11pqb"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network.gd" id="4_3g2fr"]
[ext_resource type="Resource" uid="uid://dkcwrbnbaogcb" path="res://tests/TestAssets/portal_1.tres" id="4_i0xf7"]
[ext_resource type="Resource" uid="uid://d064sbijblwy5" path="res://tests/TestAssets/portal_2.tres" id="4_rp2rj"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/portal_edge.gd" id="6_eh3ei"]

[sub_resource type="Resource" id="Resource_sfta3"]
script = ExtResource("1_4qg4f")
Expand Down Expand Up @@ -68,6 +70,11 @@ point_b = SubResource("Resource_3klvo")
cost = 1.0
bidirectional = true

[sub_resource type="Resource" id="Resource_cpm5a"]
script = ExtResource("6_eh3ei")
portal_from = ExtResource("4_i0xf7")
portal_to = ExtResource("4_rp2rj")

[resource]
script = ExtResource("4_3g2fr")
points = Array[ExtResource("1_4qg4f")]([SubResource("Resource_sfta3"), SubResource("Resource_oj3dv"), SubResource("Resource_kgaw4"), SubResource("Resource_ear5g"), SubResource("Resource_3klvo")])
Expand All @@ -80,3 +87,4 @@ SubResource("Resource_ear5g"): [SubResource("Resource_mtfvr"), SubResource("Reso
SubResource("Resource_3klvo"): [SubResource("Resource_dpqe8"), SubResource("Resource_3w0yv"), SubResource("Resource_3w0yv")]
}
portals = Array[ExtResource("3_11pqb")]([ExtResource("4_rp2rj")])
portal_edges = Array[ExtResource("6_eh3ei")]([SubResource("Resource_cpm5a")])
10 changes: 9 additions & 1 deletion Tests/TestAssets/test_network_2.tres
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[gd_resource type="Resource" script_class="Network" load_steps=20 format=3 uid="uid://up8agln3axee"]
[gd_resource type="Resource" script_class="Network" load_steps=23 format=3 uid="uid://up8agln3axee"]

[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_point.gd" id="1_koobd"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_portal.gd" id="2_8mkkq"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network_edge.gd" id="3_03gn3"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/network.gd" id="4_0srh3"]
[ext_resource type="Resource" uid="uid://dkcwrbnbaogcb" path="res://tests/TestAssets/portal_1.tres" id="4_g5ao4"]
[ext_resource type="Resource" uid="uid://d064sbijblwy5" path="res://tests/TestAssets/portal_2.tres" id="4_tm0me"]
[ext_resource type="Script" path="res://addons/network_utility/Scripts/portal_edge.gd" id="6_t8nam"]

[sub_resource type="Resource" id="Resource_74h7t"]
script = ExtResource("1_koobd")
Expand Down Expand Up @@ -83,6 +85,11 @@ point_b = SubResource("Resource_6smmb")
cost = 1.0
bidirectional = true

[sub_resource type="Resource" id="Resource_527bp"]
script = ExtResource("6_t8nam")
portal_from = ExtResource("4_tm0me")
portal_to = ExtResource("4_g5ao4")

[resource]
script = ExtResource("4_0srh3")
points = Array[ExtResource("1_koobd")]([SubResource("Resource_74h7t"), SubResource("Resource_1wfey"), SubResource("Resource_jaep4"), SubResource("Resource_6smmb"), SubResource("Resource_0u4ho"), SubResource("Resource_wyxvg")])
Expand All @@ -97,3 +104,4 @@ SubResource("Resource_0u4ho"): [SubResource("Resource_4qh84"), SubResource("Reso
SubResource("Resource_wyxvg"): [SubResource("Resource_8c0nt")]
}
portals = Array[ExtResource("2_8mkkq")]([ExtResource("4_g5ao4")])
portal_edges = Array[ExtResource("6_t8nam")]([SubResource("Resource_527bp")])
3 changes: 2 additions & 1 deletion addons/network_utility/Scripts/network.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ extends Resource
@export var edge_map:Dictionary = {}
## The portals this network has.
@export var portals:Array[NetworkPortal] = []

## Connections between worlds
@export var portal_edges:Array[PortalEdge] = []

signal redraw

Expand Down
3 changes: 0 additions & 3 deletions addons/network_utility/Scripts/network_portal.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
class_name NetworkPortal
extends NetworkPoint
## A special point that allows you to connect two networks.

## The point in another (or the same) network graph this point connects to.
@export var destination_point:NetworkPoint
6 changes: 6 additions & 0 deletions addons/network_utility/Scripts/portal_edge.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class_name PortalEdge
extends Resource


@export var portal_from:NetworkPortal
@export var portal_to:NetworkPortal
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,24 @@ func _load_from_networks(data:Dictionary):
var added_nodes = {}
var edges = []
var portals = []
var portal_edges = []
# add each point from each network
for world in data:
print("loading world network %s" % world)
edges.append_array(data[world].edges)
portals.append_array(data[world].portals)
portal_edges.append(data[world].portal_edges)

for point in data[world].points + data[world].portals:
added_nodes[point] = add_point(world, point.position)
# then go back and connect edges and portals, using the dictionary as a lookup
for edge in edges:
connect_nodes(added_nodes[edge.point_a], added_nodes[edge.point_b], edge.cost)
for portal in portals:
if not portal.destination_point == null:
if added_nodes.has(portal.destination_point):
connect_nodes(added_nodes[portal], added_nodes[portal.destination_point], 0)
else:
print("Unable to make portal connection from portal at world %s position %s. Ensure that connecting world is loaded." % [added_nodes[portal].world, added_nodes[portal].position])
for edge in portal_edges:
if added_nodes.has(edge.portal_from) and added_nodes.has(edge.portal_to):
connect_nodes(added_nodes[edge.portal_from], added_nodes[edge.portal_to], 0)
else:
print("Unable to make portal connection. Ensure that connecting world is loaded.")


func _load_from_disk(path:String, networks:Dictionary, regex:RegEx) -> void:
Expand Down

0 comments on commit 1d3bda6

Please sign in to comment.