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

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