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

A maintenance-type task prototype #192

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion src/assets/autoload/uimanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var menus: Dictionary = {
"chatbox": {"scene": preload("res://assets/ui/lobbyui/chatbox/chatbox.tscn")},

#task UI
"clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")}
"clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")},
"gasvalve": {"scene": preload("res://assets/ui/tasks/gasvalve/gasvalve.tscn")}
}

var openMenus: Array = []
Expand Down
12 changes: 12 additions & 0 deletions src/assets/maps/test/gasvalvetexttemp.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Label

func _ready():
# warning-ignore:return_value_discarded
MapManager.connect("interacted_with", self, "interacted_with")

func interacted_with(interactNode, from, interact_data):
if interactNode != self:
return
if PlayerManager.assignedtasks[0] == 0:
UIManager.open_menu("gasvalve", {"linkedNode": self})
#test if client has correct assigned task
19 changes: 18 additions & 1 deletion src/assets/maps/test/test.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 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,6 +7,7 @@
[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://assets/maps/test/gasvalvetexttemp.gd" type="Script" id=8]

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

Expand All @@ -29,6 +30,22 @@ scale = Vector2( 2.96302, 2.84043 )
z_index = -1
texture = ExtResource( 1 )

[node name="standbutton3" parent="." instance=ExtResource( 3 )]
position = Vector2( 400, -80 )
node_path = NodePath("gasvalvetext")
interact_on_exit = false

[node name="gasvalvetext" type="Label" parent="standbutton3"]
margin_left = -11.0
margin_top = -34.0
margin_right = 94.0
margin_bottom = -12.0
text = "Gas valve task"
script = ExtResource( 8 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="testdoor" parent="." instance=ExtResource( 2 )]
position = Vector2( 0, -200 )
scale = Vector2( 1.5, 3 )
Expand Down
109 changes: 109 additions & 0 deletions src/assets/ui/tasks/gasvalve/gasvalve.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
extends WindowDialog

var menuData: Dictionary = {}

#variables for the pressure
var inputPressure: float #the pressure coming from the main pipe
var inputPressTarget: float #the input pressure slowly drifts towards this value
var inputDrift: float #the drift velocity of the input pressure
var dial: float #the setting of the pressure valve on the regulator
var outputPressure: float #the regulated pressure provided by the valve

#signals for handling the extreme pressures
signal gasPressureWarning #an alarm should go off
signal gasPressureLow #tasks dependent on gas fail
signal gasPressureHigh #tasks dependent on gas fail OR lose condition?

signal updateInputGauge
signal updateOutputGauge
signal updateDial

#The minimum and maximum input pressure with min and max drift velocities
export var inputMinPressure = 0
export var inputMaxPressure = 10
export var inputMaxDrift = 1
export var inputMinDrift = 0.0
export var driftDrift = 0.01
#Possible settings of the dial
export var dialMinValue = 0
export var dialMaxValue = 10.0
export var dialUnit = 0.2
export var outputDrift = 0.2
#Output ranges
export var idealOutput = 10.0
export var acceptedRange = 2.0
export var warningRange = 3.0


func _ready():
var initialOutput: float

inputPressure = rand_range(inputMinPressure, inputMaxPressure)
inputPressTarget = rand_range(inputMinPressure, inputMaxPressure)
inputDrift = inputMinDrift
initialOutput = rand_range(idealOutput-warningRange, idealOutput-acceptedRange)
print("Initial Output: ", initialOutput)
dial = round((initialOutput - inputPressure) / dialUnit) * dialUnit
outputPressure = inputPressure + dial
emit_signal("updateDial", dial / (dialMaxValue - dialMinValue))
print("D=", dial, "; IP=", inputPressure, "; IPT=", inputPressTarget, "; OP=", outputPressure)


func _process(delta):
#this one updates the gas pressures every frame.
var outPressTarget

#input pressure drifts towards the target pressure in a nonlinear way:
inputDrift = inputDrift + ((inputMaxDrift-inputDrift) / (inputMaxDrift-inputMinDrift) * driftDrift * delta)
inputPressure = inputPressure + (inputPressTarget - inputPressure) * inputDrift * delta
emit_signal("updateInputGauge", (inputPressure - inputMinPressure) / (inputMaxPressure - inputMinPressure))

#the current input pressure and dial settings set a target towards which the output pressure drifts:
outPressTarget = inputPressure + dial
outputPressure = outputPressure + (outPressTarget - outputPressure) * outputDrift * delta
emit_signal("updateOutputGauge", (outputPressure - idealOutput) / (warningRange * 2 + 2) + 0.5)

#check whether the current pressure is in the approved range and send the proper signals
if outputPressure < idealOutput - warningRange:
#the gas pressure is too low, the tasks dependent on gas supply should fail
emit_signal("gasPressureLow")
elif outputPressure > idealOutput + warningRange:
#the gas pressure is too high, it could be a fail condution
emit_signal("gasPressureHigh")
elif outputPressure < idealOutput - acceptedRange or outputPressure > idealOutput + acceptedRange:
#the gas pressure reached the warning levels, should send out an alarm
emit_signal("gasPressureWarning")

#if the input pressure is relatively close to the target, we select a new target
if abs(inputPressure - inputPressTarget) < (inputMaxPressure - inputMinPressure) * 0.005:
inputPressTarget = rand_range(inputMinPressure, inputMaxPressure)
inputDrift = inputMinDrift
print("reached target pressure, moving on")
print("D=", dial, "; IP=", inputPressure, "; IPT=", inputPressTarget, "; OP=", outputPressure)

func open():
popup()
UIManager.menu_opened("gasvalve")

func close():
hide()
UIManager.menu_closed("gasvalve")

func _on_gasvalve_about_to_show():
pass

func _on_gasvalve_popup_hide():
UIManager.menu_closed("gasvalve")

func _on_decrease_pressed():
dial -= dialUnit
dial = max(dialMinValue, dial)
emit_signal("updateDial", dial / (dialMaxValue - dialMinValue))
print("D=", dial, "; IP=", inputPressure, "; IPT=", inputPressTarget, "; OP=", outputPressure)

func _on_increase_pressed():
dial += dialUnit
dial = min(dialMaxValue, dial)
emit_signal("updateDial", dial / (dialMaxValue - dialMinValue))
print("D=", dial, "; IP=", inputPressure, "; IPT=", inputPressTarget, "; OP=", outputPressure)

114 changes: 114 additions & 0 deletions src/assets/ui/tasks/gasvalve/gasvalve.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://assets/ui/tasks/gasvalve/gasvalve.gd" type="Script" id=1]
[ext_resource path="res://assets/ui/tasks/gasvalve/pressuregauge.gd" type="Script" id=2]

[node name="gasvalve" type="WindowDialog"]
anchor_left = 0.3
anchor_top = 0.2
anchor_right = 0.7
anchor_bottom = 0.7
focus_mode = 2
window_title = "Adjust the gas pressure!"
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="inputrange" type="ColorRect" parent="."]
margin_left = 30.0
margin_top = 30.0
margin_right = 70.0
margin_bottom = 250.0
color = Color( 0.662745, 0.662745, 0.662745, 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="inputpressure" type="Polygon2D" parent="inputrange"]
color = Color( 0.0352941, 0.0352941, 0.0352941, 1 )
polygon = PoolVector2Array( 1.35919, 0.494644, 1.35919, 21.3058, 39.4138, 10.6029 )
script = ExtResource( 2 )

[node name="valveset" type="ColorRect" parent="."]
margin_left = 180.0
margin_top = 30.0
margin_right = 220.0
margin_bottom = 250.0
color = Color( 0.662745, 0.662745, 0.662745, 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="valvepos" type="Polygon2D" parent="valveset"]
color = Color( 0.0352941, 0.0352941, 0.0352941, 1 )
polygon = PoolVector2Array( 1.35919, 0.494644, 1.35919, 21.3058, 39.4138, 10.6029 )
script = ExtResource( 2 )

[node name="outputrange" type="ColorRect" parent="."]
margin_left = 330.0
margin_top = 30.0
margin_right = 370.0
margin_bottom = 250.0
color = Color( 0.662745, 0.662745, 0.662745, 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="outputpressure" type="Polygon2D" parent="outputrange"]
color = Color( 0.0352941, 0.0352941, 0.0352941, 1 )
polygon = PoolVector2Array( 1.35919, 0.494644, 1.35919, 21.3058, 39.4138, 10.6029 )
script = ExtResource( 2 )

[node name="Label" type="Label" parent="."]
margin_left = 27.7496
margin_top = 4.2045
margin_right = 67.7496
margin_bottom = 26.2045
text = "Input"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label2" type="Label" parent="."]
margin_left = 327.432
margin_top = 4.204
margin_right = 375.432
margin_bottom = 26.204
text = "Output"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="Label3" type="Label" parent="."]
margin_left = 167.442
margin_top = 4.204
margin_right = 233.442
margin_bottom = 26.204
text = "Valve set"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="decrease" type="Button" parent="."]
margin_left = 150.52
margin_top = 118.566
margin_right = 168.52
margin_bottom = 146.566
text = "-"

[node name="increase" type="Button" parent="."]
margin_left = 232.928
margin_top = 119.407
margin_right = 253.928
margin_bottom = 147.407
text = "+"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="popup_hide" from="." to="." method="_on_gasvalve_popup_hide"]
[connection signal="updateDial" from="." to="valveset/valvepos" method="_on_gasvalve_updateGauge"]
[connection signal="updateInputGauge" from="." to="inputrange/inputpressure" method="_on_gasvalve_updateGauge"]
[connection signal="updateOutputGauge" from="." to="outputrange/outputpressure" method="_on_gasvalve_updateGauge"]
[connection signal="pressed" from="decrease" to="." method="_on_decrease_pressed"]
[connection signal="pressed" from="increase" to="." method="_on_increase_pressed"]
4 changes: 4 additions & 0 deletions src/assets/ui/tasks/gasvalve/pressuregauge.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Polygon2D

func _on_gasvalve_updateGauge(value):
self.position.y = clamp(200 - int(value*200), 0, 200)