Crossfire JXClient, Trunk
Options.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.main;
24 
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
34 public class Options {
35 
39  private static final int DEFAULT_TILE_SIZE = 64;
40 
44  private boolean fullScreen;
45 
50  @Nullable
51  private String server;
52 
56  private boolean debugGui;
57 
62  @Nullable
63  private String debugProtocolFilename;
64 
69  @Nullable
70  private String debugKeyboardFilename;
71 
76  @Nullable
77  private String debugMouseFilename;
78 
83  @Nullable
84  private String debugScreenFilename;
85 
89  @Nullable
90  private String debugSoundFilename;
91 
95  @Nullable
97 
101  @NotNull
102  private String skin = DEFAULT_SKIN;
103 
108 
112  private float fontScaleFactor = 1.0F;
113 
117  @NotNull
118  public static final String DEFAULT_SKIN = "ragnorok";
119 
124  private boolean avoidCopyArea;
125 
130  public void parse(@NotNull final String @NotNull [] args) {
131  resolution = null;
132  skin = DEFAULT_SKIN;
133 
134  int i = 0;
135  while (i < args.length) {
136  if ((args[i].equals("-r") || args[i].equals("--resolution")) && i+1 < args.length) {
137  resolution = Resolution.parse(args[++i]);
138  if (resolution == null) {
139  System.err.println("Invalid resolution: "+args[i]);
140  System.exit(1);
141  }
142  } else if ((args[i].equals("-S") || args[i].equals("-s") || args[i].equals("--skin")) && i+1 < args.length) {
143  skin = args[++i];
144  if (skin.indexOf('@') != -1) {
145  System.err.println("Invalid skin name: "+skin);
146  System.exit(1);
147  }
148  } else if (args[i].equals("-N") || args[i].equals("-n") || args[i].equals("--no-full-screen")) {
149  fullScreen = false;
150  } else if (args[i].equals("--full-screen")) {
151  fullScreen = true;
152  } else if (args[i].equals("--opengl")) {
153  System.setProperty("sun.java2d.opengl", "True");
154  } else if (args[i].equals("--server") && i+1 < args.length) {
155  server = args[++i];
156  } else if (args[i].equals("--debug-gui")) {
157  debugGui = true;
158  } else if (args[i].equals("--debug-protocol") && i+1 < args.length) {
159  debugProtocolFilename = args[++i];
160  } else if (args[i].equals("--debug-keyboard") && i+1 < args.length) {
161  debugKeyboardFilename = args[++i];
162  } else if (args[i].equals("--debug-mouse") && i+1 < args.length) {
163  debugMouseFilename = args[++i];
164  } else if (args[i].equals("--debug-screen") && i+1 < args.length) {
165  debugScreenFilename = args[++i];
166  } else if (args[i].equals("--debug-sound") && i+1 < args.length) {
167  debugSoundFilename = args[++i];
168  } else if (args[i].equals("--tile-size") && i+1 < args.length) {
169  final String tmp = args[++i];
170  try {
171  tileSize = Integer.parseInt(tmp);
172  } catch (final NumberFormatException ignored) {
173  System.err.println("Invalid tile size: "+tmp);
174  System.exit(1);
175  }
176  if (tileSize < 1) {
177  System.err.println("Invalid tile size: "+tileSize);
178  System.exit(1);
179  }
180  } else if (args[i].equals("--font-scale-factor") && i+1 < args.length) {
181  final String tmp = args[++i];
182  try {
183  fontScaleFactor = Float.parseFloat(tmp);
184  } catch (final NumberFormatException ignored) {
185  System.err.println("Invalid font scale factor: "+tmp);
186  System.exit(1);
187  }
188  if (fontScaleFactor < 0.01 || fontScaleFactor > 100.0) {
189  System.err.println("Invalid font scale factor: "+fontScaleFactor);
190  System.exit(1);
191  }
192  } else if (args[i].equals("--avoid-copy-area")) {
193  avoidCopyArea = true;
194  } else {
195  System.out.println();
196  System.out.println("Available options:");
197  System.out.println(" --full-screen : Enable full-screen mode.");
198  //System.out.println(" --no-full-screen"); // not advertised; it is recognized only for compatibility
199  //System.out.println(" -N"); // not advertised as it is considered deprecated
200  //System.out.println(" -n : Disable full-screen mode."); // not advertised; it is recognized only for compatibility
201  System.out.println(" --resolution <width>x<height>");
202  System.out.println(" -r <width>x<height>");
203  System.out.println(" : Resolution to use. [default is maximum not exceeding screen]");
204  System.out.println(" --skin <skin>");
205  //System.out.println(" -S <skin>"); // not advertised as it is considered deprecated
206  System.out.println(" -s <skin> : Built-in skin name or skin directory to use.");
207  System.out.println(" --tile-size <n>: The size of map view tiles in pixels.");
208  System.out.println(" --font-scale-factor <factor>: The factor for scaling font sizes. Default to 1.0.");
209  System.out.println(" --avoid-copy-area: Do not copy pixel areas when scrolling the map view.");
210  System.out.println(" Instead always repaint all map squares.");
211  System.out.println(" --opengl : Enable the OpenGL rendering pipeline.");
212  System.out.println(" --server <host>: Select a server to connect to; skips main and metaserver");
213  System.out.println(" windows.");
214  System.out.println(" --debug-gui : Enable debugging of GUI elements.");
215  System.out.println(" --debug-keyboard <log-file>");
216  System.out.println(" : Log keyboard input.");
217  System.out.println(" --debug-mouse <log-file>");
218  System.out.println(" : Log mouse input.");
219  System.out.println(" --debug-protocol <log-file>");
220  System.out.println(" : Log messages exchanged with the server.");
221  System.out.println(" --debug-screen <log-file>");
222  System.out.println(" : Log messages related to screen resolution.");
223  System.out.println(" --debug-sound <log-file>");
224  System.out.println(" : Log messages related to sound.");
225  System.out.println();
226  System.out.println("Built-in skin names: ragnorok ragnorok-48px ragnorok-64px.");
227  System.exit(1);
228  }
229  i++;
230  }
231  }
232 
238  @Nullable
239  public String getDebugProtocolFilename() {
240  return debugProtocolFilename;
241  }
242 
247  @Nullable
248  public String getDebugKeyboardFilename() {
249  return debugKeyboardFilename;
250  }
251 
256  @Nullable
257  public String getDebugMouseFilename() {
258  return debugMouseFilename;
259  }
260 
265  @Nullable
266  public String getDebugScreenFilename() {
267  return debugScreenFilename;
268  }
269 
274  @Nullable
275  public String getDebugSoundFilename() {
276  return debugSoundFilename;
277  }
278 
283  public boolean isDebugGui() {
284  return debugGui;
285  }
286 
291  @Nullable
293  return resolution;
294  }
295 
300  @NotNull
301  public String getSkin() {
302  return skin;
303  }
304 
309  public int getTileSize() {
310  return tileSize;
311  }
312 
317  public float getFontScaleFactor() {
318  return fontScaleFactor;
319  }
320 
325  public boolean isFullScreen() {
326  return fullScreen;
327  }
328 
333  @Nullable
334  public String getServer() {
335  return server;
336  }
337 
343  public boolean isAvoidCopyArea() {
344  return avoidCopyArea;
345  }
346 
347 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.main.Options.getDebugMouseFilename
String getDebugMouseFilename()
Definition: Options.java:257
com.realtime.crossfire.jxclient.main.Options
Definition: Options.java:34
com.realtime.crossfire.jxclient.main.Options.getResolution
Resolution getResolution()
Definition: Options.java:292
com.realtime.crossfire.jxclient.main.Options.getDebugKeyboardFilename
String getDebugKeyboardFilename()
Definition: Options.java:248
com.realtime.crossfire.jxclient.main.Options.getServer
String getServer()
Definition: Options.java:334
com.realtime.crossfire.jxclient.main.Options.server
String server
Definition: Options.java:51
com.realtime.crossfire.jxclient.main.Options.debugScreenFilename
String debugScreenFilename
Definition: Options.java:84
com.realtime.crossfire.jxclient.main.Options.debugSoundFilename
String debugSoundFilename
Definition: Options.java:90
com.realtime.crossfire.jxclient.main.Options.fontScaleFactor
float fontScaleFactor
Definition: Options.java:112
com.realtime.crossfire.jxclient.main.Options.DEFAULT_SKIN
static final String DEFAULT_SKIN
Definition: Options.java:118
com.realtime.crossfire.jxclient.main.Options.getDebugProtocolFilename
String getDebugProtocolFilename()
Definition: Options.java:239
com.realtime.crossfire.jxclient.main.Options.avoidCopyArea
boolean avoidCopyArea
Definition: Options.java:124
com.realtime.crossfire.jxclient.main.Options.debugGui
boolean debugGui
Definition: Options.java:56
com.realtime.crossfire.jxclient.main.Options.fullScreen
boolean fullScreen
Definition: Options.java:44
com.realtime.crossfire.jxclient.main.Options.getSkin
String getSkin()
Definition: Options.java:301
com.realtime.crossfire.jxclient.main.Options.resolution
Resolution resolution
Definition: Options.java:96
com.realtime.crossfire.jxclient.main.Options.parse
void parse(@NotNull final String @NotNull[] args)
Definition: Options.java:130
com.realtime.crossfire.jxclient.main.Options.isDebugGui
boolean isDebugGui()
Definition: Options.java:283
com.realtime.crossfire.jxclient.main.Options.DEFAULT_TILE_SIZE
static final int DEFAULT_TILE_SIZE
Definition: Options.java:39
com.realtime.crossfire.jxclient.util
Definition: Codec.java:23
com.realtime.crossfire.jxclient.main.Options.tileSize
int tileSize
Definition: Options.java:107
com.realtime.crossfire.jxclient.main.Options.getTileSize
int getTileSize()
Definition: Options.java:309
com.realtime.crossfire.jxclient.main.Options.isFullScreen
boolean isFullScreen()
Definition: Options.java:325
com.realtime.crossfire.jxclient.main.Options.getFontScaleFactor
float getFontScaleFactor()
Definition: Options.java:317
com.realtime.crossfire
com.realtime.crossfire.jxclient.main.Options.debugMouseFilename
String debugMouseFilename
Definition: Options.java:77
com.realtime.crossfire.jxclient.util.Resolution.parse
static Resolution parse(@NotNull final String str)
Definition: Resolution.java:67
com.realtime
com.realtime.crossfire.jxclient.util.Resolution
Definition: Resolution.java:36
com
com.realtime.crossfire.jxclient.main.Options.isAvoidCopyArea
boolean isAvoidCopyArea()
Definition: Options.java:343
com.realtime.crossfire.jxclient.main.Options.debugKeyboardFilename
String debugKeyboardFilename
Definition: Options.java:70
com.realtime.crossfire.jxclient.main.Options.skin
String skin
Definition: Options.java:102
com.realtime.crossfire.jxclient.main.Options.getDebugSoundFilename
String getDebugSoundFilename()
Definition: Options.java:275
com.realtime.crossfire.jxclient.main.Options.debugProtocolFilename
String debugProtocolFilename
Definition: Options.java:63
com.realtime.crossfire.jxclient.main.Options.getDebugScreenFilename
String getDebugScreenFilename()
Definition: Options.java:266