source: TFP-WebServer/WebServer/src/WebAPI/APIs/ServerState/GamePrefs.cs@ 496

Last change on this file since 496 was 457, checked in by alloc, 16 months ago

Refactored APIs GamePrefs, GameStats, ServerInfo: Using arrays as result instead of objects, code sharing

File size: 1.5 KB
Line 
1using System;
2using JetBrains.Annotations;
3using Utf8Json;
4
5namespace Webserver.WebAPI.APIs.ServerState {
6 [UsedImplicitly]
7 public class GamePrefs : KeyValueListAbs {
8 public GamePrefs () : base ("GamePrefs") {
9 }
10
11 protected override void iterateList (ref JsonWriter _writer, ref bool _first) {
12 foreach (EnumGamePrefs stat in EnumUtils.Values<EnumGamePrefs> ()) {
13 string name = stat.ToStringCached ();
14
15 if (name.Contains ("Password", StringComparison.Ordinal)) {
16 continue;
17 }
18
19 global::GamePrefs.EnumType? type = global::GamePrefs.GetPrefType (stat);
20 object defaultValue = global::GamePrefs.GetDefault (stat);
21
22 switch (type) {
23 case global::GamePrefs.EnumType.Int:
24 int? defaultInt = defaultValue as int?;
25 addItem (ref _writer, ref _first, name, global::GamePrefs.GetInt (stat), defaultInt);
26 break;
27 case global::GamePrefs.EnumType.Float:
28 float? defaultFloat = defaultValue as float?;
29 addItem (ref _writer, ref _first, name, global::GamePrefs.GetFloat (stat), defaultFloat);
30 break;
31 case global::GamePrefs.EnumType.String:
32 string defaultString = defaultValue as string;
33 addItem (ref _writer, ref _first, name, global::GamePrefs.GetString (stat), defaultString);
34 break;
35 case global::GamePrefs.EnumType.Bool:
36 bool? defaultBool = defaultValue as bool?;
37 addItem (ref _writer, ref _first, name, global::GamePrefs.GetBool (stat), defaultBool);
38 break;
39 }
40 }
41 }
42
43 }
44}
Note: See TracBrowser for help on using the repository browser.