forked from xmnovotny/VoxelTycoon-ScheduleStopwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VehicleScheduleData.MeasurementSurrogate.cs
41 lines (38 loc) · 1.26 KB
/
VehicleScheduleData.MeasurementSurrogate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using VoxelTycoon.Serialization;
using VoxelTycoon.Tracks.Tasks;
namespace ScheduleStopwatch
{
public partial class VehicleScheduleData
{
private class MeasurementSurrogate
{
internal static void Write(StateBinaryWriter writer, Measurement measurement)
{
if (measurement is StationLoadingMeasurement)
{
writer.WriteByte(0);
} else
if (measurement is TravelMeasurement)
{
writer.WriteByte(1);
} else
{
throw new ArgumentException("Unknown class " + measurement.GetType().Name);
}
}
internal static Measurement Read(StateBinaryReader reader, VehicleScheduleData data, RootTask task)
{
byte id = reader.ReadByte();
switch (id)
{
case 0:
return new StationLoadingMeasurement(data, task);
case 1:
return new TravelMeasurement(data, task);
}
throw new ArgumentException("Unknown id " + id.ToString());
}
}
}
}