-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonData.cs
662 lines (542 loc) · 21.4 KB
/
JsonData.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
// <auto-generated />
//
// To parse this JSON data, add NuGet 'System.Text.Json' then do:
//
// using Splatoon3ics;
//
// var splatData = SplatData.FromJson(jsonString);
#nullable enable
#pragma warning disable CS8618
#pragma warning disable CS8601
#pragma warning disable CS8603
namespace Splatoon3ics
{
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
public partial class SplatData
{
[JsonPropertyName("data")]
public Data Data { get; set; }
}
public partial class Data
{
[JsonPropertyName("regularSchedules")]
public Schedules RegularSchedules { get; set; }
[JsonPropertyName("bankaraSchedules")]
public Schedules BankaraSchedules { get; set; }
[JsonPropertyName("xSchedules")]
public Schedules XSchedules { get; set; }
[JsonPropertyName("eventSchedules")]
public EventSchedules EventSchedules { get; set; }
[JsonPropertyName("festSchedules")]
public Schedules FestSchedules { get; set; }
[JsonPropertyName("coopGroupingSchedule")]
public CoopGroupingSchedule CoopGroupingSchedule { get; set; }
[JsonPropertyName("currentFest")]
public object CurrentFest { get; set; }
[JsonPropertyName("currentPlayer")]
public CurrentPlayer CurrentPlayer { get; set; }
[JsonPropertyName("vsStages")]
public VsStages VsStages { get; set; }
}
public partial class Schedules
{
[JsonPropertyName("nodes")]
public List<BankaraSchedulesNode> Nodes { get; set; }
}
public partial class BankaraSchedulesNode
{
[JsonPropertyName("startTime")]
public DateTimeOffset StartTime { get; set; }
[JsonPropertyName("endTime")]
public DateTimeOffset EndTime { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("bankaraMatchSettings")]
public List<MatchSetting> BankaraMatchSettings { get; set; }
[JsonPropertyName("festMatchSettings")]
public object FestMatchSettings { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("regularMatchSetting")]
public MatchSetting RegularMatchSetting { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("xMatchSetting")]
public MatchSetting XMatchSetting { get; set; }
}
public partial class MatchSetting
{
[JsonPropertyName("__isVsSetting")]
public IsVsSetting IsVsSetting { get; set; }
[JsonPropertyName("__typename")]
public IsVsSetting Typename { get; set; }
[JsonPropertyName("vsStages")]
public List<Stage> VsStages { get; set; }
[JsonPropertyName("vsRule")]
public VsRule VsRule { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("bankaraMode")]
public BankaraMode? BankaraMode { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("leagueMatchEvent")]
public LeagueMatchEvent LeagueMatchEvent { get; set; }
}
public partial class LeagueMatchEvent
{
[JsonPropertyName("leagueMatchEventId")]
public string LeagueMatchEventId { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("desc")]
public string Desc { get; set; }
[JsonPropertyName("regulationUrl")]
public Uri RegulationUrl { get; set; }
[JsonPropertyName("regulation")]
public string Regulation { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
}
public partial class VsRule
{
[JsonPropertyName("name")]
public Name Name { get; set; }
[JsonPropertyName("rule")]
public Rule Rule { get; set; }
[JsonPropertyName("id")]
public Id Id { get; set; }
}
public partial class Stage
{
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("vsStageId")]
public long? VsStageId { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("image")]
public UserIcon Image { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("thumbnailImage")]
public UserIcon ThumbnailImage { get; set; }
}
public partial class UserIcon
{
[JsonPropertyName("url")]
public Uri Url { get; set; }
}
public partial class CoopGroupingSchedule
{
[JsonPropertyName("bannerImage")]
public object BannerImage { get; set; }
[JsonPropertyName("regularSchedules")]
public RegularSchedules RegularSchedules { get; set; }
[JsonPropertyName("bigRunSchedules")]
public Schedules BigRunSchedules { get; set; }
[JsonPropertyName("teamContestSchedules")]
public Schedules TeamContestSchedules { get; set; }
}
public partial class RegularSchedules
{
[JsonPropertyName("nodes")]
public List<PurpleNode> Nodes { get; set; }
}
public partial class PurpleNode
{
[JsonPropertyName("startTime")]
public DateTimeOffset StartTime { get; set; }
[JsonPropertyName("endTime")]
public DateTimeOffset EndTime { get; set; }
[JsonPropertyName("setting")]
public Setting Setting { get; set; }
[JsonPropertyName("__splatoon3ink_king_salmonid_guess")]
public string Splatoon3InkKingSalmonidGuess { get; set; }
}
public partial class Setting
{
[JsonPropertyName("__typename")]
public string Typename { get; set; }
[JsonPropertyName("coopStage")]
public Stage CoopStage { get; set; }
[JsonPropertyName("__isCoopSetting")]
public string IsCoopSetting { get; set; }
[JsonPropertyName("weapons")]
public List<Weapon> Weapons { get; set; }
}
public partial class Weapon
{
[JsonPropertyName("__splatoon3ink_id")]
public string Splatoon3InkId { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("image")]
public UserIcon Image { get; set; }
}
public partial class CurrentPlayer
{
[JsonPropertyName("userIcon")]
public UserIcon UserIcon { get; set; }
}
public partial class EventSchedules
{
[JsonPropertyName("nodes")]
public List<EventSchedulesNode> Nodes { get; set; }
}
public partial class EventSchedulesNode
{
[JsonPropertyName("leagueMatchSetting")]
public MatchSetting LeagueMatchSetting { get; set; }
[JsonPropertyName("timePeriods")]
public List<TimePeriod> TimePeriods { get; set; }
}
public partial class TimePeriod
{
[JsonPropertyName("startTime")]
public DateTimeOffset StartTime { get; set; }
[JsonPropertyName("endTime")]
public DateTimeOffset EndTime { get; set; }
}
public partial class VsStages
{
[JsonPropertyName("nodes")]
public List<VsStagesNode> Nodes { get; set; }
}
public partial class VsStagesNode
{
[JsonPropertyName("vsStageId")]
public long VsStageId { get; set; }
[JsonPropertyName("originalImage")]
public UserIcon OriginalImage { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("stats")]
public object Stats { get; set; }
[JsonPropertyName("id")]
public string Id { get; set; }
}
public enum BankaraMode { Challenge, Open };
public enum IsVsSetting { BankaraMatchSetting, LeagueMatchSetting, RegularMatchSetting, XMatchSetting };
public enum Id { VnNSdWxlLta, VnNSdWxlLte, VnNSdWxlLti, VnNSdWxlLtm, VnNSdWxlLtq };
public enum Name { ClamBlitz, Rainmaker, SplatZones, TowerControl, TurfWar };
public enum Rule { Area, Clam, Goal, Loft, TurfWar };
public partial class SplatData
{
public static SplatData FromJson(string json) => JsonSerializer.Deserialize<SplatData>(json, Splatoon3ics.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this SplatData self) => JsonSerializer.Serialize(self, Splatoon3ics.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
{
Converters =
{
IsVsSettingConverter.Singleton,
BankaraModeConverter.Singleton,
IdConverter.Singleton,
NameConverter.Singleton,
RuleConverter.Singleton,
new DateOnlyConverter(),
new TimeOnlyConverter(),
IsoDateTimeOffsetConverter.Singleton
},
};
}
internal class IsVsSettingConverter : JsonConverter<IsVsSetting>
{
public override bool CanConvert(Type t) => t == typeof(IsVsSetting);
public override IsVsSetting Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
switch (value)
{
case "BankaraMatchSetting":
return IsVsSetting.BankaraMatchSetting;
case "LeagueMatchSetting":
return IsVsSetting.LeagueMatchSetting;
case "RegularMatchSetting":
return IsVsSetting.RegularMatchSetting;
case "XMatchSetting":
return IsVsSetting.XMatchSetting;
}
throw new Exception("Cannot unmarshal type IsVsSetting");
}
public override void Write(Utf8JsonWriter writer, IsVsSetting value, JsonSerializerOptions options)
{
switch (value)
{
case IsVsSetting.BankaraMatchSetting:
JsonSerializer.Serialize(writer, "BankaraMatchSetting", options);
return;
case IsVsSetting.LeagueMatchSetting:
JsonSerializer.Serialize(writer, "LeagueMatchSetting", options);
return;
case IsVsSetting.RegularMatchSetting:
JsonSerializer.Serialize(writer, "RegularMatchSetting", options);
return;
case IsVsSetting.XMatchSetting:
JsonSerializer.Serialize(writer, "XMatchSetting", options);
return;
}
throw new Exception("Cannot marshal type IsVsSetting");
}
public static readonly IsVsSettingConverter Singleton = new IsVsSettingConverter();
}
internal class BankaraModeConverter : JsonConverter<BankaraMode>
{
public override bool CanConvert(Type t) => t == typeof(BankaraMode);
public override BankaraMode Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
switch (value)
{
case "CHALLENGE":
return BankaraMode.Challenge;
case "OPEN":
return BankaraMode.Open;
}
throw new Exception("Cannot unmarshal type BankaraMode");
}
public override void Write(Utf8JsonWriter writer, BankaraMode value, JsonSerializerOptions options)
{
switch (value)
{
case BankaraMode.Challenge:
JsonSerializer.Serialize(writer, "CHALLENGE", options);
return;
case BankaraMode.Open:
JsonSerializer.Serialize(writer, "OPEN", options);
return;
}
throw new Exception("Cannot marshal type BankaraMode");
}
public static readonly BankaraModeConverter Singleton = new BankaraModeConverter();
}
internal class IdConverter : JsonConverter<Id>
{
public override bool CanConvert(Type t) => t == typeof(Id);
public override Id Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
switch (value)
{
case "VnNSdWxlLTA=":
return Id.VnNSdWxlLta;
case "VnNSdWxlLTE=":
return Id.VnNSdWxlLte;
case "VnNSdWxlLTI=":
return Id.VnNSdWxlLti;
case "VnNSdWxlLTM=":
return Id.VnNSdWxlLtm;
case "VnNSdWxlLTQ=":
return Id.VnNSdWxlLtq;
}
throw new Exception("Cannot unmarshal type Id");
}
public override void Write(Utf8JsonWriter writer, Id value, JsonSerializerOptions options)
{
switch (value)
{
case Id.VnNSdWxlLta:
JsonSerializer.Serialize(writer, "VnNSdWxlLTA=", options);
return;
case Id.VnNSdWxlLte:
JsonSerializer.Serialize(writer, "VnNSdWxlLTE=", options);
return;
case Id.VnNSdWxlLti:
JsonSerializer.Serialize(writer, "VnNSdWxlLTI=", options);
return;
case Id.VnNSdWxlLtm:
JsonSerializer.Serialize(writer, "VnNSdWxlLTM=", options);
return;
case Id.VnNSdWxlLtq:
JsonSerializer.Serialize(writer, "VnNSdWxlLTQ=", options);
return;
}
throw new Exception("Cannot marshal type Id");
}
public static readonly IdConverter Singleton = new IdConverter();
}
internal class NameConverter : JsonConverter<Name>
{
public override bool CanConvert(Type t) => t == typeof(Name);
public override Name Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
switch (value)
{
case "Clam Blitz":
return Name.ClamBlitz;
case "Rainmaker":
return Name.Rainmaker;
case "Splat Zones":
return Name.SplatZones;
case "Tower Control":
return Name.TowerControl;
case "Turf War":
return Name.TurfWar;
}
throw new Exception("Cannot unmarshal type Name");
}
public override void Write(Utf8JsonWriter writer, Name value, JsonSerializerOptions options)
{
switch (value)
{
case Name.ClamBlitz:
JsonSerializer.Serialize(writer, "Clam Blitz", options);
return;
case Name.Rainmaker:
JsonSerializer.Serialize(writer, "Rainmaker", options);
return;
case Name.SplatZones:
JsonSerializer.Serialize(writer, "Splat Zones", options);
return;
case Name.TowerControl:
JsonSerializer.Serialize(writer, "Tower Control", options);
return;
case Name.TurfWar:
JsonSerializer.Serialize(writer, "Turf War", options);
return;
}
throw new Exception("Cannot marshal type Name");
}
public static readonly NameConverter Singleton = new NameConverter();
}
internal class RuleConverter : JsonConverter<Rule>
{
public override bool CanConvert(Type t) => t == typeof(Rule);
public override Rule Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
switch (value)
{
case "AREA":
return Rule.Area;
case "CLAM":
return Rule.Clam;
case "GOAL":
return Rule.Goal;
case "LOFT":
return Rule.Loft;
case "TURF_WAR":
return Rule.TurfWar;
}
throw new Exception("Cannot unmarshal type Rule");
}
public override void Write(Utf8JsonWriter writer, Rule value, JsonSerializerOptions options)
{
switch (value)
{
case Rule.Area:
JsonSerializer.Serialize(writer, "AREA", options);
return;
case Rule.Clam:
JsonSerializer.Serialize(writer, "CLAM", options);
return;
case Rule.Goal:
JsonSerializer.Serialize(writer, "GOAL", options);
return;
case Rule.Loft:
JsonSerializer.Serialize(writer, "LOFT", options);
return;
case Rule.TurfWar:
JsonSerializer.Serialize(writer, "TURF_WAR", options);
return;
}
throw new Exception("Cannot marshal type Rule");
}
public static readonly RuleConverter Singleton = new RuleConverter();
}
public class DateOnlyConverter : JsonConverter<DateOnly>
{
private readonly string serializationFormat;
public DateOnlyConverter() : this(null) { }
public DateOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
}
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return DateOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
public class TimeOnlyConverter : JsonConverter<TimeOnly>
{
private readonly string serializationFormat;
public TimeOnlyConverter() : this(null) { }
public TimeOnlyConverter(string? serializationFormat)
{
this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
}
public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return TimeOnly.Parse(value!);
}
public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString(serializationFormat));
}
internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
private string? _dateTimeFormat;
private CultureInfo? _culture;
public DateTimeStyles DateTimeStyles
{
get => _dateTimeStyles;
set => _dateTimeStyles = value;
}
public string? DateTimeFormat
{
get => _dateTimeFormat ?? string.Empty;
set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
}
public CultureInfo Culture
{
get => _culture ?? CultureInfo.CurrentCulture;
set => _culture = value;
}
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
string text;
if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
{
value = value.ToUniversalTime();
}
text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
writer.WriteStringValue(text);
}
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string? dateText = reader.GetString();
if (string.IsNullOrEmpty(dateText) == false)
{
if (!string.IsNullOrEmpty(_dateTimeFormat))
{
return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
}
else
{
return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
}
}
else
{
return default(DateTimeOffset);
}
}
public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
}
}
#pragma warning restore CS8618
#pragma warning restore CS8601
#pragma warning restore CS8603