Add basic power network setup
This commit is contained in:
parent
04eb4846e8
commit
75b760086d
13 changed files with 146 additions and 56 deletions
|
@ -48,7 +48,7 @@ tracks/0/keys = {
|
|||
length = 0.2
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("../Control:modulate")
|
||||
tracks/0/path = NodePath("Control:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
|
@ -60,7 +60,7 @@ tracks/0/keys = {
|
|||
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
|
||||
}
|
||||
tracks/1/type = "bezier"
|
||||
tracks/1/path = NodePath("../Control:position:y")
|
||||
tracks/1/path = NodePath("Control:position:y")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
|
@ -73,7 +73,7 @@ tracks/1/keys = {
|
|||
[sub_resource type="Animation" id=6]
|
||||
length = 0.2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("../Control:modulate")
|
||||
tracks/0/path = NodePath("Control:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
|
@ -85,7 +85,7 @@ tracks/0/keys = {
|
|||
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
|
||||
}
|
||||
tracks/1/type = "bezier"
|
||||
tracks/1/path = NodePath("../Control:position:y")
|
||||
tracks/1/path = NodePath("Control:position:y")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
|
@ -113,6 +113,7 @@ region_enabled = true
|
|||
region_rect = Rect2( 0, 0, 32, 32 )
|
||||
|
||||
[node name="screen" type="Sprite" parent="computer"]
|
||||
modulate = Color( 0, 0, 0, 1 )
|
||||
material = SubResource( 2 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
|
@ -135,6 +136,8 @@ anims/fadein = SubResource( 5 )
|
|||
anims/fadeout = SubResource( 6 )
|
||||
|
||||
[node name="Control" type="Node2D" parent="."]
|
||||
modulate = Color( 1, 1, 1, 0 )
|
||||
position = Vector2( 0, 10 )
|
||||
z_index = 999
|
||||
|
||||
[node name="ControlComp" parent="Control" instance=ExtResource( 4 )]
|
||||
|
|
|
@ -64,7 +64,7 @@ __meta__ = {
|
|||
[node name="VelocityBox" type="VBoxContainer" parent="Container"]
|
||||
material = ExtResource( 4 )
|
||||
margin_right = 180.0
|
||||
margin_bottom = 51.0
|
||||
margin_bottom = 45.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
alignment = 1
|
||||
|
@ -73,9 +73,9 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Container/VelocityBox"]
|
||||
margin_top = 6.0
|
||||
margin_top = 3.0
|
||||
margin_right = 180.0
|
||||
margin_bottom = 24.0
|
||||
margin_bottom = 21.0
|
||||
custom_constants/separation = 10
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
|
@ -100,9 +100,9 @@ custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
|
|||
|
||||
[node name="HSlider" type="HSlider" parent="Container/VelocityBox"]
|
||||
material = ExtResource( 4 )
|
||||
margin_top = 28.0
|
||||
margin_top = 25.0
|
||||
margin_right = 180.0
|
||||
margin_bottom = 44.0
|
||||
margin_bottom = 41.0
|
||||
mouse_filter = 1
|
||||
max_value = 1000.0
|
||||
value = 1000.0
|
||||
|
@ -111,9 +111,9 @@ ticks_on_borders = true
|
|||
|
||||
[node name="DirectionBox" type="VBoxContainer" parent="Container"]
|
||||
material = ExtResource( 4 )
|
||||
margin_top = 71.0
|
||||
margin_top = 65.0
|
||||
margin_right = 180.0
|
||||
margin_bottom = 122.0
|
||||
margin_bottom = 110.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
alignment = 1
|
||||
|
@ -122,9 +122,9 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Container/DirectionBox"]
|
||||
margin_top = 6.0
|
||||
margin_top = 3.0
|
||||
margin_right = 180.0
|
||||
margin_bottom = 24.0
|
||||
margin_bottom = 21.0
|
||||
|
||||
[node name="ShipDirectionLabel" type="Label" parent="Container/DirectionBox/HBoxContainer"]
|
||||
material = ExtResource( 4 )
|
||||
|
@ -145,9 +145,9 @@ custom_colors/font_color = Color( 0.494118, 0.52549, 0.737255, 1 )
|
|||
|
||||
[node name="HSlider" type="HSlider" parent="Container/DirectionBox"]
|
||||
material = ExtResource( 4 )
|
||||
margin_top = 28.0
|
||||
margin_top = 25.0
|
||||
margin_right = 180.0
|
||||
margin_bottom = 44.0
|
||||
margin_bottom = 41.0
|
||||
mouse_filter = 1
|
||||
max_value = 360.0
|
||||
tick_count = 18
|
||||
|
|
|
@ -3,51 +3,62 @@ tool
|
|||
extends Area2D
|
||||
|
||||
enum Direction { LEFT, RIGHT, UP, DOWN }
|
||||
enum Flow { SOURCE, SINK }
|
||||
enum Flow { SOURCE, SINK, BIDIRECTIONAL }
|
||||
|
||||
export(Direction) var direction = Direction.DOWN setget set_direction
|
||||
|
||||
export(Array, NodePath) var connections = []
|
||||
export(Array, NodePath) var connectionPaths = []
|
||||
var connections = []
|
||||
|
||||
export(Color) var source_color
|
||||
export(Color) var sink_color
|
||||
export(Color) var bidirectional_color
|
||||
|
||||
export(Flow) var flow = Flow.SINK setget set_flow
|
||||
|
||||
var ready = false
|
||||
onready var socket = $socket
|
||||
|
||||
var network: PowerNetwork = null
|
||||
|
||||
func _ready():
|
||||
ready = true
|
||||
$socket.material = $socket.material.duplicate()
|
||||
socket.material = socket.material.duplicate()
|
||||
refresh_sprite()
|
||||
for connection in connectionPaths:
|
||||
add_connection(get_node(connection))
|
||||
|
||||
func add_connection(node: Node):
|
||||
var manager = node.get_node("PowerManager") as PowerManager
|
||||
manager.wired = true
|
||||
|
||||
func set_direction(dir):
|
||||
direction = dir
|
||||
if ready:
|
||||
refresh_sprite()
|
||||
refresh_sprite()
|
||||
|
||||
func set_flow(val):
|
||||
flow = val
|
||||
if ready:
|
||||
refresh_sprite()
|
||||
refresh_sprite()
|
||||
|
||||
func refresh_sprite():
|
||||
if socket == null:
|
||||
return
|
||||
var rot = 0
|
||||
match direction:
|
||||
Direction.DOWN:
|
||||
$socket.region_rect.position = Vector2(0, 0)
|
||||
socket.region_rect.position = Vector2(0, 0)
|
||||
rot = 0
|
||||
Direction.UP:
|
||||
$socket.region_rect.position = Vector2(32, 0)
|
||||
socket.region_rect.position = Vector2(32, 0)
|
||||
rot = PI
|
||||
Direction.LEFT:
|
||||
$socket.region_rect.position = Vector2(32, 32)
|
||||
socket.region_rect.position = Vector2(32, 32)
|
||||
rot = PI/2
|
||||
Direction.RIGHT:
|
||||
$socket.region_rect.position = Vector2(0, 32)
|
||||
socket.region_rect.position = Vector2(0, 32)
|
||||
rot = -PI/2
|
||||
match flow:
|
||||
Flow.SOURCE:
|
||||
$socket.material.set_shader_param("cable_color", source_color)
|
||||
socket.material.set_shader_param("cable_color", source_color)
|
||||
Flow.SINK:
|
||||
$socket.material.set_shader_param("cable_color", sink_color)
|
||||
socket.material.set_shader_param("cable_color", sink_color)
|
||||
Flow.BIDIRECTIONAL:
|
||||
socket.material.set_shader_param("cable_color", bidirectional_color)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[ext_resource path="res://Graphics/tgstation/socket.png" type="Texture" id=1]
|
||||
[ext_resource path="res://Actors/Objects/ElectricSocket/ElectricSocket.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="Shader" id=4]
|
||||
[sub_resource type="Shader" id=1]
|
||||
code = "shader_type canvas_item;
|
||||
render_mode blend_mix;
|
||||
|
||||
|
@ -12,34 +12,52 @@ uniform vec4 cable_color: hint_color;
|
|||
void fragment() {
|
||||
vec4 col = texture(TEXTURE, UV);
|
||||
if (col.r/col.g > 2.) {
|
||||
col.rgb = cable_color.rgb * length(col.rgb);
|
||||
if (length(cable_color) == 0.) {
|
||||
if (UV.y > 0.6 && UV.y < 0.85) {
|
||||
if (int(UV.x * 200.) % 12 > 4) {
|
||||
col.rgb = vec3(0.94, 0.08, 0.08) * length(col.rgb);
|
||||
} else {
|
||||
col.rgb = vec3(0.04, 0.58, 0.98) * length(col.rgb);
|
||||
}
|
||||
} else {
|
||||
if (int(UV.y * 200.) % 12 > 4) {
|
||||
col.rgb = vec3(0.94, 0.08, 0.08) * length(col.rgb);
|
||||
} else {
|
||||
col.rgb = vec3(0.04, 0.58, 0.98) * length(col.rgb);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
col.rgb = cable_color.rgb * length(col.rgb);
|
||||
}
|
||||
}
|
||||
COLOR = col;
|
||||
}"
|
||||
custom_defines = ""
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=5]
|
||||
shader = SubResource( 4 )
|
||||
shader_param/cable_color = Color( 0.0823529, 0.937255, 0.27451, 1 )
|
||||
[sub_resource type="ShaderMaterial" id=2]
|
||||
shader = SubResource( 1 )
|
||||
shader_param/cable_color = Color( 0, 0, 0, 0 )
|
||||
|
||||
[sub_resource type="CircleShape2D" id=6]
|
||||
[sub_resource type="CircleShape2D" id=3]
|
||||
radius = 12.0
|
||||
|
||||
[node name="ElectricSocket" type="Area2D"]
|
||||
collision_layer = 4
|
||||
collision_mask = 2147483652
|
||||
script = ExtResource( 2 )
|
||||
direction = 1
|
||||
direction = 2
|
||||
source_color = Color( 0.937255, 0.0823529, 0.0823529, 1 )
|
||||
sink_color = Color( 0.0901961, 0.533333, 0.960784, 1 )
|
||||
bidirectional_color = Color( 0, 0, 0, 0 )
|
||||
flow = 2
|
||||
|
||||
[node name="socket" type="Sprite" parent="."]
|
||||
material = SubResource( 5 )
|
||||
material = SubResource( 2 )
|
||||
texture = ExtResource( 1 )
|
||||
centered = false
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 32, 32, 32 )
|
||||
region_rect = Rect2( 32, 0, 32, 32 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2( 16, 16 )
|
||||
shape = SubResource( 6 )
|
||||
shape = SubResource( 3 )
|
||||
|
|
|
@ -13,7 +13,7 @@ extents = Vector2( 16, 16 )
|
|||
length = 0.2
|
||||
step = 0.05
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("../StaticBody2D/Control:modulate")
|
||||
tracks/0/path = NodePath("Control:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
|
@ -25,7 +25,7 @@ tracks/0/keys = {
|
|||
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
|
||||
}
|
||||
tracks/1/type = "bezier"
|
||||
tracks/1/path = NodePath("../StaticBody2D/Control:position:y")
|
||||
tracks/1/path = NodePath("Control:position:y")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
|
@ -38,7 +38,7 @@ tracks/1/keys = {
|
|||
[sub_resource type="Animation" id=3]
|
||||
length = 0.2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("../StaticBody2D/Control:modulate")
|
||||
tracks/0/path = NodePath("Control:modulate")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
|
@ -50,7 +50,7 @@ tracks/0/keys = {
|
|||
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
|
||||
}
|
||||
tracks/1/type = "bezier"
|
||||
tracks/1/path = NodePath("../StaticBody2D/Control:position:y")
|
||||
tracks/1/path = NodePath("Control:position:y")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/imported = false
|
||||
|
|
|
@ -2,24 +2,36 @@ extends Area2D
|
|||
|
||||
class_name ProbeElectric
|
||||
|
||||
const DEBUG = true
|
||||
|
||||
const center = Vector2.ONE * 16
|
||||
|
||||
var neighbours = []
|
||||
|
||||
var network: PowerNetwork = null
|
||||
|
||||
func _ready():
|
||||
if network == null:
|
||||
network = PowerNetwork.new()
|
||||
network.add_node(self)
|
||||
$"/root/scene/systems".add_child(network, true)
|
||||
|
||||
func _physics_process(delta):
|
||||
if DEBUG:
|
||||
if PowerNetwork.DEBUG:
|
||||
update()
|
||||
|
||||
func _draw():
|
||||
if DEBUG:
|
||||
draw_circle(center, 4, Color.cyan)
|
||||
if PowerNetwork.DEBUG:
|
||||
draw_circle(center, 4, network.debugColor)
|
||||
for neighbour in neighbours:
|
||||
var delta = (neighbour.global_position - global_position) / global_scale
|
||||
draw_line(center, delta + center, Color.cyan, 2)
|
||||
draw_line(center, delta + center, network.debugColor, 2)
|
||||
|
||||
func _got_neighbour(area: Area2D):
|
||||
if area == self:
|
||||
return
|
||||
if area.network == null:
|
||||
area.network = network
|
||||
network.add_node(area)
|
||||
elif area.network != network:
|
||||
# Merge networks
|
||||
network.join(area.network)
|
||||
neighbours.push_back(area)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
extends Node
|
26
Actors/Systems/Electricity/PowerNetwork.gd
Normal file
26
Actors/Systems/Electricity/PowerNetwork.gd
Normal file
|
@ -0,0 +1,26 @@
|
|||
extends Node
|
||||
|
||||
class_name PowerNetwork
|
||||
|
||||
const DEBUG = true
|
||||
|
||||
var nodes = []
|
||||
|
||||
var debugColor = Color.cyan
|
||||
|
||||
func _ready():
|
||||
name = "PowerNetwork"
|
||||
debugColor = Color.from_hsv(randf(), 0.8, 0.8)
|
||||
|
||||
func add_node(node):
|
||||
nodes.append(node)
|
||||
|
||||
func join(network):
|
||||
for node in network.nodes:
|
||||
nodes.append(node)
|
||||
node.network = self
|
||||
# Do other merging here
|
||||
network.queue_free()
|
||||
|
||||
func _physics_process(_delta):
|
||||
pass
|
|
@ -20,7 +20,7 @@ compress/hdr_mode=0
|
|||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
|
|
|
@ -4,8 +4,11 @@ class_name GameInstance
|
|||
|
||||
onready var ui = $CanvasLayer/ui as GameUI
|
||||
onready var world = $world as GameWorld
|
||||
onready var systems = $systems
|
||||
|
||||
func _ready():
|
||||
randomize()
|
||||
|
||||
ui.connect("command", world, "process_command")
|
||||
$world/odyssey.queue_free()
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ map_path = NodePath("runtime")
|
|||
[node name="runtime" parent="world" instance=ExtResource( 7 )]
|
||||
|
||||
[node name="odyssey" parent="world" instance=ExtResource( 1 )]
|
||||
visible = false
|
||||
|
||||
[node name="player" parent="world" instance=ExtResource( 2 )]
|
||||
position = Vector2( 206.017, 250.966 )
|
||||
|
@ -37,3 +38,5 @@ mouse_filter = 2
|
|||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="systems" type="Node" parent="."]
|
||||
|
|
|
@ -84,14 +84,17 @@ __meta__ = {
|
|||
[node name="Engine" parent="engines" instance=ExtResource( 10 )]
|
||||
position = Vector2( -320, 321 )
|
||||
direction = 0
|
||||
strength = 1.0
|
||||
|
||||
[node name="Engine2" parent="engines" instance=ExtResource( 10 )]
|
||||
position = Vector2( -320, 208 )
|
||||
direction = 0
|
||||
strength = 1.0
|
||||
|
||||
[node name="Engine3" parent="engines" instance=ExtResource( 10 )]
|
||||
position = Vector2( -320, 96 )
|
||||
direction = 0
|
||||
strength = 1.0
|
||||
|
||||
[node name="objects" type="Node2D" parent="."]
|
||||
__meta__ = {
|
||||
|
@ -100,25 +103,32 @@ __meta__ = {
|
|||
|
||||
[node name="Computer" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( -64, 128 )
|
||||
direction = 3
|
||||
computer_type = 0
|
||||
|
||||
[node name="Computer2" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( -32, 128 )
|
||||
direction = 3
|
||||
computer_type = 1
|
||||
|
||||
[node name="Computer3" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( 0, 128 )
|
||||
direction = 3
|
||||
computer_type = 2
|
||||
|
||||
[node name="Computer4" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( 32, 128 )
|
||||
direction = 3
|
||||
computer_type = 3
|
||||
|
||||
[node name="Computer5" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( -96, 128 )
|
||||
direction = 3
|
||||
computer_type = 4
|
||||
|
||||
[node name="Computer6" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( -128, 128 )
|
||||
direction = 3
|
||||
computer_type = 5
|
||||
|
||||
[node name="StaticBody2D2" parent="objects" instance=ExtResource( 12 )]
|
||||
|
@ -129,6 +139,7 @@ position = Vector2( 128, 256 )
|
|||
|
||||
[node name="Computer7" parent="objects" instance=ExtResource( 6 )]
|
||||
position = Vector2( 64, 128 )
|
||||
direction = 3
|
||||
computer_type = 6
|
||||
|
||||
[node name="Scanner" parent="objects" instance=ExtResource( 8 )]
|
||||
|
@ -136,13 +147,11 @@ position = Vector2( 288, 320 )
|
|||
|
||||
[node name="ElectricSocket" parent="objects" instance=ExtResource( 13 )]
|
||||
position = Vector2( 128, 288 )
|
||||
direction = 2
|
||||
connections = [ NodePath("../SMES1") ]
|
||||
flow = 0
|
||||
|
||||
[node name="ElectricSocket2" parent="objects" instance=ExtResource( 13 )]
|
||||
position = Vector2( 256, 320 )
|
||||
connections = [ NodePath("../Scanner") ]
|
||||
direction = 1
|
||||
flow = 1
|
||||
|
||||
[node name="lights" type="Node2D" parent="."]
|
||||
modulate = Color( 0.980392, 0.980392, 0.980392, 1 )
|
||||
|
|
|
@ -79,6 +79,11 @@ _global_script_classes=[ {
|
|||
"language": "GDScript",
|
||||
"path": "res://Actors/Components/PowerManager.gd"
|
||||
}, {
|
||||
"base": "Node",
|
||||
"class": "PowerNetwork",
|
||||
"language": "GDScript",
|
||||
"path": "res://Actors/Systems/Electricity/PowerNetwork.gd"
|
||||
}, {
|
||||
"base": "Area2D",
|
||||
"class": "ProbeElectric",
|
||||
"language": "GDScript",
|
||||
|
@ -104,6 +109,7 @@ _global_script_class_icons={
|
|||
"MapTiles": "",
|
||||
"Occluder": "",
|
||||
"PowerManager": "",
|
||||
"PowerNetwork": "",
|
||||
"ProbeElectric": "",
|
||||
"UICommand": ""
|
||||
}
|
||||
|
|
Reference in a new issue