Skip to content

Commit 7946180

Browse files
committed
add: background now dynamically fades based on lab hours
1 parent 8284bf0 commit 7946180

9 files changed

+70
-28
lines changed

frontend/labmap2/.godot/editor/editor_layout.cfg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
dock_3_selected_tab_idx=0
44
dock_4_selected_tab_idx=0
5-
dock_5_selected_tab_idx=0
5+
dock_5_selected_tab_idx=1
66
dock_floating={}
77
dock_bottom=[]
88
dock_closed=[]
@@ -18,7 +18,7 @@ dock_filesystem_display_mode=0
1818
dock_filesystem_file_sort=0
1919
dock_filesystem_file_list_display_mode=1
2020
dock_filesystem_selected_paths=PackedStringArray("res://paths/to_melange.tres")
21-
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://")
21+
dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://paths/")
2222
dock_3="Scene,Import"
2323
dock_4="FileSystem"
2424
dock_5="Inspector,Node,History"
@@ -29,13 +29,13 @@ open_scenes=PackedStringArray("res://scenes/floor_map.tscn")
2929
current_scene="res://scenes/floor_map.tscn"
3030
center_split_offset=-288
3131
selected_default_debugger_tab_idx=1
32-
selected_main_editor_idx=0
32+
selected_main_editor_idx=2
3333
selected_bottom_panel_item=0
3434

3535
[ScriptEditor]
3636

37-
open_scripts=["res://scenes/clock.gd", "res://scenes/http_get_lab_hours.gd", "res://name_dictionary.json"]
38-
selected_script="res://name_dictionary.json"
37+
open_scripts=["res://scripts/background_light.gd", "res://scenes/clock.gd", "res://scenes/http_get_lab_hours.gd", "res://name_dictionary.json"]
38+
selected_script="res://scenes/http_get_lab_hours.gd"
3939
open_help=[]
4040
script_split_offset=70
4141
list_split_offset=0

frontend/labmap2/.godot/editor/filesystem_cache8

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ea4bc82a6ad023ab7ee23ee620429895
2-
::res://::1756858800
2+
::res://::1756860483
33
export_presets.cfg::TextFile::-1::1756840323::0::1::::<><>::
44
icon.svg::CompressedTexture2D::8019015828006172325::1729218193::1756852168::1::::<><>::
5-
name_dictionary.json::JSON::-1::1756598085::0::1::::<><>::
5+
name_dictionary.json::JSON::-1::1756858929::0::1::::<><>::
66
README.md::TextFile::-1::1756599838::0::1::::<><>::
77
sample_data.json::JSON::-1::1733372300::0::1::::<><>::
88
::res://art/::1756852168
@@ -21,7 +21,7 @@ Labmap2.apple-touch-icon.png::CompressedTexture2D::8947455212634037835::17566017
2121
Labmap2.icon.png::CompressedTexture2D::6108776289350885466::1756601731::1756852168::1::::<><>::
2222
Labmap2.manifest.json::JSON::-1::1756601731::0::1::::<><>::
2323
Labmap2.png::CompressedTexture2D::2903267927140575369::1756601731::1756852168::1::::<><>::
24-
::res://paths/::1756598032
24+
::res://paths/::1756859171
2525
to_bandit.tres::Curve2D::3964835214106076797::1733372300::0::1::::<><>::
2626
to_bolt.tres::Curve2D::212375828273240441::1733372300::0::1::::<><>::
2727
to_breezy.tres::Curve2D::8603290125073973280::1733372300::0::1::::<><>::
@@ -34,11 +34,12 @@ to_gozer.tres::Curve2D::4552607048370097516::1733372300::0::1::::<><>::
3434
to_lexy.tres::Curve2D::5027847431649842825::1733372300::0::1::::<><>::
3535
to_mack.tres::Curve2D::3669894903190170233::1733372300::0::1::::<><>::
3636
to_marshmallow.tres::Curve2D::5183291648129576954::1733372300::0::1::::<><>::
37+
to_melange.tres::Curve2D::376184603246626331::1733372300::0::1::::<><>::
38+
to_misty.tres::Curve2D::1262546308938303373::1756859171::0::1::::<><>::
3739
to_patches.tres::Curve2D::9138898070918892080::1733372300::0::1::::<><>::
3840
to_peaches.tres::Curve2D::4715392189424450289::1733372300::0::1::::<><>::
3941
to_pepper.tres::Curve2D::2507108117954204135::1733372300::0::1::::<><>::
4042
to_pickles.tres::Curve2D::7202429245993580378::1733372300::0::1::::<><>::
41-
to_plague.tres::Curve2D::376184603246626331::1733372300::0::1::::<><>::
4243
to_princess.tres::Curve2D::5044101861065296420::1733372300::0::1::::<><>::
4344
to_pumpkin.tres::Curve2D::4300882724580055123::1733372300::0::1::::<><>::
4445
to_rascal.tres::Curve2D::3523611281609719317::1733372300::0::1::::<><>::
@@ -51,9 +52,9 @@ to_spud.tres::Curve2D::5178034277345821971::1733372300::0::1::::<><>::
5152
to_sunny.tres::Curve2D::1867299367943324528::1733372300::0::1::::<><>::
5253
to_tabitha.tres::Curve2D::3352327448385657489::1733372300::0::1::::<><>::
5354
to_Windows.tres::Curve2D::396053016331995211::1733372300::0::1::::<><>::
54-
::res://scenes/::1756858665
55+
::res://scenes/::1756859173
5556
clock.gd::GDScript::-1::1756857605::0::1::::<>RichTextLabel<>::
56-
floor_map.tscn::PackedScene::7631678058768377369::1756858665::0::1::::<><>::res://scripts/floor_map.gd<>uid://cqt0vr61f2bxi::::res://art/floor_sheet.png<>uid://nernh4erw8au::::res://art/table_sheet.png<>uid://c7hy84ujceanw::::res://art/wall_sheet.png<>res://scripts/devices.gd<>res://scripts/logger.gd<>uid://brs2mnfeqqby3::::res://scenes/log_display.tscn<>res://scripts/http_request_node.gd<>uid://dtlrn0pyxevuv::::res://art/background.png<>res://scripts/background_light.gd<>uid://cuaj5txrl38kg::::res://art/background2.png<>res://scenes/clock.gd<>res://scenes/http_get_lab_hours.gd
57+
floor_map.tscn::PackedScene::7631678058768377369::1756859173::0::1::::<><>::res://scripts/floor_map.gd<>uid://cqt0vr61f2bxi::::res://art/floor_sheet.png<>uid://nernh4erw8au::::res://art/table_sheet.png<>uid://c7hy84ujceanw::::res://art/wall_sheet.png<>res://scripts/devices.gd<>res://scripts/logger.gd<>uid://r8t7n7pqbnov::::res://paths/to_misty.tres<>uid://brs2mnfeqqby3::::res://scenes/log_display.tscn<>res://scripts/http_request_node.gd<>uid://dtlrn0pyxevuv::::res://art/background.png<>res://scripts/background_light.gd<>uid://cuaj5txrl38kg::::res://art/background2.png<>res://scenes/clock.gd<>res://scenes/http_get_lab_hours.gd
5758
http_get_lab_hours.gd::GDScript::-1::1756857263::0::1::::<>HTTPRequest<>::
5859
log_display.tscn::PackedScene::3618451304175608720::1733440536::0::1::::<><>::res://scripts/log_display.gd
5960
node.gd::GDScript::-1::1733372300::0::1::::<>Node<>::

frontend/labmap2/.godot/editor/floor_map.tscn-editstate-b8367499dc2d207b9c9e1350390b266a.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,4 @@ Anim={
175175
"zfar": 4000.01,
176176
"znear": 0.05
177177
}
178-
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Root/Debug_Path_Node")])
178+
selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/Root/Clock/HttpGetLabHours")])

frontend/labmap2/.godot/editor/project_metadata.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[editor_metadata]
22

33
executable_path="/usr/bin/godot"
4+
use_advanced_connections=false
45

56
[recent_files]
67

78
scenes=["res://scenes/floor_map.tscn"]
8-
scripts=["res://scenes/http_get_lab_hours.gd", "res://scenes/clock.gd", "res://scripts/devices.gd", "res://name_dictionary.json", "res://scripts/http_request_node.gd", "res://scripts/floor_map.gd"]
9+
scripts=["res://scripts/background_light.gd", "res://scenes/http_get_lab_hours.gd", "res://scenes/clock.gd", "res://scripts/devices.gd", "res://name_dictionary.json", "res://scripts/http_request_node.gd", "res://scripts/floor_map.gd"]
910

1011
[export_options]
1112

frontend/labmap2/.godot/editor/script_editor_cache.cfg

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,25 @@ state={
7373
state={
7474
"bookmarks": PackedInt32Array(),
7575
"breakpoints": PackedInt32Array(),
76-
"column": 0,
76+
"column": 37,
7777
"folded_lines": Array[int]([]),
7878
"h_scroll_position": 0,
79-
"row": 20,
80-
"scroll_position": 0.0,
79+
"row": 2,
80+
"scroll_position": 2.0,
81+
"selection": false,
82+
"syntax_highlighter": "GDScript"
83+
}
84+
85+
[res://scripts/background_light.gd]
86+
87+
state={
88+
"bookmarks": PackedInt32Array(),
89+
"breakpoints": PackedInt32Array(),
90+
"column": 93,
91+
"folded_lines": Array[int]([]),
92+
"h_scroll_position": 0,
93+
"row": 3,
94+
"scroll_position": 3.0,
8195
"selection": false,
8296
"syntax_highlighter": "GDScript"
8397
}

frontend/labmap2/.godot/uid_cache.bin

-38 Bytes
Binary file not shown.

frontend/labmap2/scenes/floor_map.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,4 @@ script = ExtResource("13_1la2h")
252252
[connection signal="timeout" from="Update_Timer" to="Devices/HTTPRequestNode" method="_on_update_timer_timeout"]
253253
[connection signal="timeout" from="Update_Timer" to="LogDisplay" method="_on_update_timer_timeout"]
254254
[connection signal="new_log" from="Logger" to="LogDisplay" method="_on_logger_new_log"]
255+
[connection signal="hours_ready" from="Clock/HttpGetLabHours" to="BackgroundLight" method="_on_http_get_lab_hours_hours_ready"]

frontend/labmap2/scenes/http_get_lab_hours.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends HTTPRequest
22

3+
signal hours_ready(hours: Dictionary)
4+
35
@onready var parser = YAMLParser.new()
46
var bbcode_snippet: String = "" # this will hold the formatted opening hours
57

@@ -15,7 +17,9 @@ func _on_request_completed(_result, response_code, _headers, body):
1517
return
1618
var yaml_text = body.get_string_from_utf8()
1719
var parsed = parser.parse(yaml_text)
18-
if typeof(parsed) != TYPE_DICTIONARY:
20+
if typeof(parsed) == TYPE_DICTIONARY:
21+
emit_signal("hours_ready", parsed)
22+
else:
1923
push_error("YAML did not parse into a dictionary")
2024
return
2125

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
'''
22
This script controls the background by turning the alpha level of the BackgroundLight
33
node to 1 between 8am and 8pm and to 0 outside of those times.
4+
It reads a signal from the HttpGetLabHours to determine if the background light is on or not.
45
'''
56

67
extends Sprite2D
78

8-
@export var day_start = 8 # 8 AM
9-
@export var night_start = 20 # 8 PM
109
@export var fade_duration = 2.0 # Duration of fade in seconds
11-
1210
var target_alpha = 1.0 # The desired alpha value for the light background
11+
var today_hours: Array = []
1312

1413
func _ready():
1514
# Set the initial alpha value based on the current time
@@ -19,14 +18,36 @@ func _ready():
1918
func _process(_delta):
2019
# Smoothly adjust alpha value to the target
2120
self.modulate.a = lerp(self.modulate.a, target_alpha, 0.1)
22-
# Periodically check the time to update target alpha values
23-
if Time.get_datetime_dict_from_system().second == 0: # Check every minute
21+
# Check once per minute
22+
if Time.get_datetime_dict_from_system().second == 0:
2423
update_target_alpha()
2524

25+
2626
func update_target_alpha():
27-
var time = Time.get_datetime_dict_from_system() # Get current local time
28-
var hour = time.hour
29-
if hour >= night_start or hour < day_start:
30-
target_alpha = 0.0 # Nighttime: fade out
31-
else:
32-
target_alpha = 1.0 # Daytime: fade in
27+
var now = Time.get_datetime_dict_from_system()
28+
var current_minutes = now.hour * 60 + now.minute
29+
30+
if today_hours.is_empty():
31+
# Fallback: treat as always closed = dark
32+
target_alpha = 0.0
33+
return
34+
35+
var open_now = false
36+
for range in today_hours:
37+
var open_split = range[0].split(":")
38+
var close_split = range[1].split(":")
39+
var open_minutes = int(open_split[0]) * 60 + int(open_split[1])
40+
var close_minutes = int(close_split[0]) * 60 + int(close_split[1])
41+
42+
if current_minutes >= open_minutes and current_minutes < close_minutes:
43+
open_now = true
44+
break
45+
46+
target_alpha = 1.0 if open_now else 0.0
47+
48+
func _on_http_get_lab_hours_hours_ready(hours: Dictionary) -> void:
49+
var days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
50+
var now = Time.get_datetime_dict_from_system()
51+
var day_name = days[now.weekday]
52+
today_hours = hours["regular"].get(day_name, [])
53+
update_target_alpha()

0 commit comments

Comments
 (0)