hostmodetraits.h
1 //------------------------------------------------------------------------------
2 // hostmodetraits.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2024 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef DOOMSEEKER_GUI_CREATESERVER_HOSTMODETRAITS_H
24 #define DOOMSEEKER_GUI_CREATESERVER_HOSTMODETRAITS_H
25 
26 #include "serverapi/gamecreateparams.h"
27 
32 {
33 public:
34  GameCreateParams::HostMode mode;
35 
36  HostModeTraits(GameCreateParams::HostMode mode = GameCreateParams::Host)
37  : mode(mode)
38  {}
39 
43  static HostModeTraits fromCfgName(const QString &name)
44  {
45  if (name == "offline")
46  return GameCreateParams::Offline;
47  // Default to Host if there's any other value.
48  return GameCreateParams::Host;
49  }
50 
54  QString cfgName() const
55  {
56  switch (mode)
57  {
58  default:
59  case GameCreateParams::Host: return "host";
60  case GameCreateParams::Offline: return "offline";
61  }
62  }
63 
64  HostModeTraits &operator=(GameCreateParams::HostMode mode)
65  {
66  this->mode = mode;
67  return *this;
68  }
69 
70  operator GameCreateParams::HostMode () const
71  {
72  return mode;
73  }
74 
75  bool canChangeAnyGameRules() const
76  {
77  return mode != GameCreateParams::Demo;
78  }
79 
83  bool canChangeGame() const
84  {
85  return mode == GameCreateParams::Host
86  || mode == GameCreateParams::Offline;
87  }
88 
92  bool canChangeMode() const
93  {
94  return mode == GameCreateParams::Host
95  || mode == GameCreateParams::Offline;
96  }
97 
101  bool canRecordDemo() const
102  {
103  return mode == GameCreateParams::Offline;
104  }
105 
109  bool canShowCommandLine() const
110  {
111  return mode != GameCreateParams::Remote;
112  }
113 
117  bool isCreatingServer() const
118  {
119  return mode == GameCreateParams::Host;
120  }
121 
126  {
127  return mode == GameCreateParams::Host
128  || mode == GameCreateParams::Remote;
129  }
130 };
131 
132 #endif