Skip to content

Commit 654dfd1

Browse files
committed
feat: Add sun/moon rise/set times to environment data
1 parent f981ec2 commit 654dfd1

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Source/Orts.Formats.Msts/EnvironmentFile.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2009 - 2023 by the Open Rails project.
1+
// COPYRIGHT 2009 - 2023 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -151,13 +151,19 @@ public SkyLayer(STFReader stf)
151151

152152
public class SkySatellite
153153
{
154+
public int RiseTime;
155+
public int SetTime;
156+
public SkySatelliteType Type;
154157
public string TextureName;
155158
public string TextureMode;
156159

157160
public SkySatellite(STFReader stf)
158161
{
159162
stf.ParseWholeBlock(new[]
160163
{
164+
new STFReader.TokenProcessor("world_sky_satellite_rise_time", () => RiseTime = ParseTime(stf.ReadStringBlock("00:00:00"))),
165+
new STFReader.TokenProcessor("world_sky_satellite_set_time", () => SetTime = ParseTime(stf.ReadStringBlock("00:00:00"))),
166+
new STFReader.TokenProcessor("world_sky_satellite_light", () => Type = (SkySatelliteType)stf.ReadIntBlock((int)SkySatelliteType.Unknown)),
161167
new STFReader.TokenProcessor("world_anim_shader", () => stf.ParseWholeBlock(new[]
162168
{
163169
new STFReader.TokenProcessor("world_shader", () =>
@@ -185,6 +191,24 @@ public SkySatellite(STFReader stf)
185191
})),
186192
});
187193
}
194+
195+
public enum SkySatelliteType
196+
{
197+
Unknown = -1,
198+
Moon = 0,
199+
Sun = 1,
200+
}
201+
202+
int ParseTime(string time)
203+
{
204+
var timeParts = time.Split(':');
205+
if (timeParts.Length != 3 || !byte.TryParse(timeParts[0], out var hours) || !byte.TryParse(timeParts[1], out var minutes) || !byte.TryParse(timeParts[2], out var seconds))
206+
{
207+
return 0;
208+
}
209+
210+
return (hours * 3600) + (minutes * 60) + seconds;
211+
}
188212
}
189213
}
190214
}

0 commit comments

Comments
 (0)