Skip to content

Commit 6d04839

Browse files
Add files via upload
V0.1.5 Updates: Added Weather Alerts
1 parent 69891da commit 6d04839

File tree

4 files changed

+335
-7
lines changed

4 files changed

+335
-7
lines changed

AlertInfo.tscn

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://new_dynamicfont.tres" type="DynamicFont" id=1]
4+
5+
[node name="AlertInfo" type="VBoxContainer"]
6+
margin_right = 717.0
7+
margin_bottom = 393.0
8+
9+
[node name="Intro" type="HBoxContainer" parent="."]
10+
margin_right = 720.0
11+
margin_bottom = 28.0
12+
alignment = 1
13+
14+
[node name="IntroLabel" type="Label" parent="Intro"]
15+
margin_left = 321.0
16+
margin_right = 394.0
17+
margin_bottom = 28.0
18+
custom_fonts/font = ExtResource( 1 )
19+
text = "Alert #"
20+
align = 1
21+
22+
[node name="AlertNum" type="Label" parent="Intro"]
23+
margin_left = 398.0
24+
margin_right = 398.0
25+
margin_bottom = 28.0
26+
custom_fonts/font = ExtResource( 1 )
27+
28+
[node name="Headline" type="HBoxContainer" parent="."]
29+
margin_top = 32.0
30+
margin_right = 720.0
31+
margin_bottom = 91.0
32+
alignment = 1
33+
34+
[node name="HLabel" type="Label" parent="Headline"]
35+
margin_right = 720.0
36+
margin_bottom = 59.0
37+
rect_min_size = Vector2( 720, 15 )
38+
custom_fonts/font = ExtResource( 1 )
39+
text = "Flood Watch issued June 22 at 10:51AM EDT until June 22 at 11:00PM EDT by NWS Baltimore MD/Washington DC"
40+
align = 1
41+
autowrap = true
42+
43+
[node name="HSeparator3" type="HSeparator" parent="."]
44+
margin_top = 95.0
45+
margin_right = 720.0
46+
margin_bottom = 99.0
47+
48+
[node name="AlertInfo1" type="HBoxContainer" parent="."]
49+
margin_top = 103.0
50+
margin_right = 720.0
51+
margin_bottom = 131.0
52+
alignment = 1
53+
54+
[node name="Label" type="Label" parent="AlertInfo1"]
55+
margin_left = 273.0
56+
margin_right = 368.0
57+
margin_bottom = 28.0
58+
custom_fonts/font = ExtResource( 1 )
59+
text = "Severity:"
60+
align = 1
61+
62+
[node name="A1Status" type="Label" parent="AlertInfo1"]
63+
margin_left = 372.0
64+
margin_right = 446.0
65+
margin_bottom = 28.0
66+
custom_fonts/font = ExtResource( 1 )
67+
text = "Severe"
68+
align = 1
69+
70+
[node name="AlertInfo2" type="HBoxContainer" parent="."]
71+
margin_top = 135.0
72+
margin_right = 720.0
73+
margin_bottom = 163.0
74+
alignment = 1
75+
76+
[node name="Label" type="Label" parent="AlertInfo2"]
77+
margin_left = 261.0
78+
margin_right = 367.0
79+
margin_bottom = 28.0
80+
custom_fonts/font = ExtResource( 1 )
81+
text = "Certainty:"
82+
align = 1
83+
84+
[node name="A2Status" type="Label" parent="AlertInfo2"]
85+
margin_left = 371.0
86+
margin_right = 459.0
87+
margin_bottom = 28.0
88+
custom_fonts/font = ExtResource( 1 )
89+
text = "Possible"
90+
align = 1
91+
92+
[node name="AlertInfo3" type="HBoxContainer" parent="."]
93+
margin_top = 167.0
94+
margin_right = 720.0
95+
margin_bottom = 195.0
96+
alignment = 1
97+
98+
[node name="Label" type="Label" parent="AlertInfo3"]
99+
margin_left = 275.0
100+
margin_right = 368.0
101+
margin_bottom = 28.0
102+
custom_fonts/font = ExtResource( 1 )
103+
text = "Urgency:"
104+
align = 1
105+
106+
[node name="A3Status" type="Label" parent="AlertInfo3"]
107+
margin_left = 372.0
108+
margin_right = 445.0
109+
margin_bottom = 28.0
110+
custom_fonts/font = ExtResource( 1 )
111+
text = "Future"
112+
align = 1
113+
114+
[node name="AlertInfo4" type="HBoxContainer" parent="."]
115+
margin_top = 199.0
116+
margin_right = 720.0
117+
margin_bottom = 227.0
118+
alignment = 1
119+
120+
[node name="Label" type="Label" parent="AlertInfo4"]
121+
margin_left = 257.0
122+
margin_right = 325.0
123+
margin_bottom = 28.0
124+
custom_fonts/font = ExtResource( 1 )
125+
text = "Event:"
126+
align = 1
127+
128+
[node name="A4Status" type="Label" parent="AlertInfo4"]
129+
margin_left = 329.0
130+
margin_right = 462.0
131+
margin_bottom = 28.0
132+
custom_fonts/font = ExtResource( 1 )
133+
text = "Flood Watch"
134+
align = 1
135+
136+
[node name="AlertInfo5" type="HBoxContainer" parent="."]
137+
margin_top = 231.0
138+
margin_right = 720.0
139+
margin_bottom = 259.0
140+
alignment = 1
141+
142+
[node name="Label" type="Label" parent="AlertInfo5"]
143+
margin_left = 261.0
144+
margin_right = 370.0
145+
margin_bottom = 28.0
146+
custom_fonts/font = ExtResource( 1 )
147+
text = "Response:"
148+
align = 1
149+
150+
[node name="A5Status" type="Label" parent="AlertInfo5"]
151+
margin_left = 374.0
152+
margin_right = 459.0
153+
margin_bottom = 28.0
154+
custom_fonts/font = ExtResource( 1 )
155+
text = "Prepare"
156+
align = 1
157+
158+
[node name="HSeparator2" type="HSeparator" parent="."]
159+
margin_top = 263.0
160+
margin_right = 720.0
161+
margin_bottom = 267.0
162+
163+
[node name="Desc" type="Label" parent="."]
164+
margin_top = 271.0
165+
margin_right = 720.0
166+
margin_bottom = 1043.0
167+
custom_fonts/font = ExtResource( 1 )
168+
text = "* WHAT...Flash flooding caused by excessive rainfall continues to be\\npossible.\\n\\n* WHERE...Portions of DC, Maryland, Virginia and West Virginia,\\nincluding the following areas: in DC, District of Columbia. In\\nMaryland, Carroll, Central and Eastern Allegany, Central and\\nSoutheast Howard, Central and Southeast Montgomery, Frederick MD,\\nNorthern Baltimore, Northwest Howard, Northwest Montgomery, Prince\\nGeorges, Southern Baltimore and Washington. In Virginia,\\nArlington/Falls Church/Alexandria, Clarke, Culpeper, Eastern\\nLoudoun, Fairfax, Frederick VA, Greene, Madison, Northern\\nFauquier, Northern Virginia Blue Ridge, Orange, Page, Prince\\nWilliam/Manassas/Manassas Park, Rappahannock, Rockingham,\\nShenandoah, Southern Fauquier, Spotsylvania, Stafford, Warren and\\nWestern Loudoun. In West Virginia, Berkeley, Eastern Mineral,\\nHampshire, Hardy, Jefferson and Morgan.\\n\\n* WHEN...From 3 PM EDT this afternoon through this evening.\\n\\n* IMPACTS...Excessive runoff may result in flooding of rivers,\\ncreeks, streams, and other low-lying and flood-prone locations.\\n\\n* ADDITIONAL DETAILS...\\n- Widespread showers and thunderstorms are expected later this\\nafternoon into the evening. Given a very warm and moist air\\nmass, these will produce some very heavy rainfall at times.\\nRainfall amounts of 1 to 3 inches are possible within the\\nspan of a couple of hours, with locally higher amounts\\npossible.\\n- http://www.weather.gov/safety/flood"
169+
align = 1
170+
autowrap = true
171+
172+
[node name="HSeparator4" type="HSeparator" parent="."]
173+
margin_top = 1047.0
174+
margin_right = 720.0
175+
margin_bottom = 1051.0
176+
177+
[node name="Ins" type="Label" parent="."]
178+
margin_top = 1055.0
179+
margin_right = 720.0
180+
margin_bottom = 1083.0
181+
custom_fonts/font = ExtResource( 1 )
182+
text = "Instructions Go Here"
183+
align = 1
184+
autowrap = true
185+
186+
[node name="HSeparator5" type="HSeparator" parent="."]
187+
margin_top = 1087.0
188+
margin_right = 720.0
189+
margin_bottom = 1091.0

Main.gd

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ var CatForecastURL
1616
var WeeklyForecastResult
1717
var HourlyForecastResult
1818
var DetailedForecastNumebr
19-
var CityState = str(city,state)
19+
var CityState
20+
var ZoneURL
21+
var ZoneID
22+
var AlertBase = "https://api.weather.gov/alerts/active/zone/"
23+
var ActiveAlertURL
24+
var Alerts
25+
var AlertCount
2026

2127
func _ready():
2228
print("Program Starting")
@@ -36,6 +42,8 @@ func _on_Location_request_completed(result, response_code, headers, body):
3642
zipCode = json.result.zip
3743
lat = json.result.lat
3844
long = json.result.lon
45+
#lat = 33.4025 #For Testing.
46+
#long = -84.522 #For Testing
3947
fullURL = str(baseURL, lat, ",", long)
4048
CityState = str(city," ",state)
4149
$GUI/Forecasts/Window/Header/Location.text = String(CityState)
@@ -57,22 +65,29 @@ func _on_Forecast_request_completed(result, response_code, headers, body):
5765
ForecastURL = GPjson.result.properties.forecast
5866
HForecastURL = GPjson.result.properties.forecastHourly
5967
CatForecastURL = str(ForecastURL,ImpUnits)
68+
ZoneURL = GPjson.result.properties.county
6069
print("Forecast URL:")
6170
print(ForecastURL)
6271
print("Hourly URL:")
6372
print(HForecastURL)
6473
print("Full Weekly URL:")
6574
print(CatForecastURL)
75+
print("Zone URL:")
76+
print(ZoneURL)
6677
print("Getting Weekly Forecast")
6778
getHourlyForecast()
6879
getWeeklyForecast()
80+
getZoneID()
6981

7082
func getHourlyForecast():
7183
$NetworkController/HoulyForecast.request(HForecastURL)
7284

7385
func getWeeklyForecast():
7486
$NetworkController/WeeklyForecast.request(CatForecastURL)
7587

88+
func getZoneID():
89+
$NetworkController/ZoneIDRequest.request(ZoneURL)
90+
7691
func _on_HoulyForecast_request_completed(result, response_code, headers, body):
7792
var HourlyForecastJSON = JSON.parse(body.get_string_from_utf8())
7893
HourlyForecastResult = HourlyForecastJSON.result.properties.periods
@@ -83,6 +98,85 @@ func _on_WeeklyForecast_request_completed(result, response_code, headers, body):
8398
WeeklyForecastResult = WeeklyForecastJSON.result.properties.periods
8499
PrintWeeklyResults()
85100

101+
func _on_ZoneIDRequest_request_completed(result, response_code, headers, body):
102+
var ZoneIDRequestResult = JSON.parse(body.get_string_from_utf8())
103+
ZoneID = ZoneIDRequestResult.result.properties.id
104+
ActiveAlertURL = str(AlertBase,ZoneID)
105+
print("ZoneID:")
106+
print(ZoneID)
107+
print("Active Alerts URL:")
108+
print(ActiveAlertURL)
109+
getAlerts()
110+
111+
func getAlerts():
112+
$NetworkController/AlertRequest.request(ActiveAlertURL)
113+
114+
func _on_AlertRequest_request_completed(result, response_code, headers, body):
115+
var AlertJSON = JSON.parse(body.get_string_from_utf8())
116+
Alerts = AlertJSON.result.features
117+
AlertHandler()
118+
119+
func AlertHandler():
120+
print("Alerts:")
121+
if Alerts == []:
122+
print("No Alerts")
123+
$GUI/Forecasts/Window/NowCast/Alert.visible = false
124+
else:
125+
$GUI/Forecasts/Window/NowCast/Alert.visible = true
126+
print("ALERT!")
127+
AlertCount = Alerts.size()
128+
#AlertCount = 3 #Testing.
129+
print("Alert Count:")
130+
print(AlertCount)
131+
alertProcessing()
132+
133+
func alertProcessing():
134+
var i = AlertCount
135+
var Counter = 0
136+
var AlertNumber = 1
137+
var scene = ResourceLoader.load("res://AlertInfo.tscn")
138+
var path = get_tree().get_root().get_node("Main/GUI/AlertDisplay/Body/AlertScroll/Target")
139+
print(path)
140+
print(scene)
141+
print(i)
142+
143+
for number in range(i):
144+
#Make Instance
145+
print("Loop:", Counter)
146+
var NewInstance = scene.instance()
147+
NewInstance.name = "AlertInfo" + String(Counter)
148+
path.add_child(NewInstance)
149+
print("New Instance Name:")
150+
print(NewInstance.name)
151+
NewInstance.get_node("Intro/AlertNum").text = String(AlertNumber)
152+
NewInstance.get_node("Headline/HLabel").text = String(Alerts[Counter].properties.headline)
153+
NewInstance.get_node("AlertInfo1/A1Status").text = String(Alerts[Counter].properties.severity)
154+
NewInstance.get_node("AlertInfo2/A2Status").text = String(Alerts[Counter].properties.certainty)
155+
NewInstance.get_node("AlertInfo3/A3Status").text = String(Alerts[Counter].properties.urgency)
156+
NewInstance.get_node("AlertInfo4/A4Status").text = String(Alerts[Counter].properties.event)
157+
NewInstance.get_node("AlertInfo5/A5Status").text = String(Alerts[Counter].properties.response)
158+
NewInstance.get_node("Desc").text = String(Alerts[Counter].properties.description)
159+
print("Instructions:")
160+
print(Alerts[Counter].properties.instruction)
161+
162+
if Alerts[Counter].properties.instruction == null:
163+
print("NULL!!!!")
164+
NewInstance.get_node("Ins").text = "No Further Instructions at this Time"
165+
else:
166+
print("Instructions Present")
167+
NewInstance.get_node("Ins").text = String(Alerts[Counter].properties.instruction)
168+
169+
Counter = Counter + 1
170+
AlertNumber = AlertNumber + 1
171+
172+
func _on_Alert_pressed():
173+
$GUI/AlertDisplay.visible = true
174+
$GUI/Forecasts.visible = false
175+
176+
func _on_ForecastReturn_pressed():
177+
$GUI/AlertDisplay.visible = false
178+
$GUI/Forecasts.visible = true
179+
86180
func PrintHourlyResults():
87181
#NowCast
88182
$GUI/Forecasts/Window/NowCast/NowTemp/Temp.text = String(HourlyForecastResult[0].temperature)
@@ -99,6 +193,7 @@ func PrintHourlyResults():
99193

100194
func PrintWeeklyResults():
101195
$GUI/Forecasts/Window/WeeklyScroll.get_v_scrollbar().modulate = Color(0, 0, 0, 0) #Hide Scroll Bar
196+
$GUI/AlertDisplay/Body/AlertScroll.get_v_scrollbar().modulate = Color(0, 0, 0, 0) #Hide Scroll Bar
102197
$GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/Date.text = String(WeeklyForecastResult[0].name)
103198
$GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/W0Temp/Temp.text = String(WeeklyForecastResult[0].temperature)
104199
$GUI/Forecasts/Window/WeeklyScroll/WeekCast/W0/W0Temp/Unit.text = String(WeeklyForecastResult[0].temperatureUnit)

0 commit comments

Comments
 (0)