Crossfire JXClient, Trunk  R20561
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-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.main;
23 
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 
48  private boolean fullScreen = true;
49 
54  @Nullable
55  private String server;
56 
60  private boolean debugGui;
61 
66  @Nullable
67  private String debugProtocolFilename;
68 
73  @Nullable
74  private String debugKeyboardFilename;
75 
80  @Nullable
81  private String debugMouseFilename;
82 
87  @Nullable
88  private String debugScreenFilename;
89 
93  @Nullable
94  private String debugSoundFilename;
95 
99  @Nullable
101 
105  @Nullable
106  private String skin;
107 
112 
116  @NotNull
117  public static final String DEFAULT_SKIN = "ragnorok";
118 
123  private boolean avoidCopyArea;
124 
129  public void parse(@NotNull final String[] args) {
130  resolution = null;
131  skin = "default";
132 
133  // fix changed default skin name
134  if (skin.equals("com.realtime.crossfire.jxclient.JXCSkinPrelude")) {
135  skin = "default";
136  }
137 
138  int i = 0;
139  while (i < args.length) {
140  if ((args[i].equals("-r") || args[i].equals("--resolution")) && i+1 < args.length) {
141  resolution = Resolution.parse(args[++i]);
142  if (resolution == null) {
143  System.err.println("Invalid resolution: "+args[i]);
144  System.exit(1);
145  }
146  } else if ((args[i].equals("-S") || args[i].equals("-s") || args[i].equals("--skin")) && i+1 < args.length) {
147  skin = args[++i];
148  if (skin.indexOf('@') != -1) {
149  System.err.println("Invalid skin name: "+skin);
150  System.exit(1);
151  }
152  } else if (args[i].equals("-N") || args[i].equals("-n") || args[i].equals("--no-full-screen")) {
153  fullScreen = false;
154  } else if (args[i].equals("--opengl")) {
155  System.setProperty("sun.java2d.opengl", "True");
156  } else if (args[i].equals("--server") && i+1 < args.length) {
157  server = args[++i];
158  } else if (args[i].equals("--debug-gui")) {
159  debugGui = true;
160  } else if (args[i].equals("--debug-protocol") && i+1 < args.length) {
161  debugProtocolFilename = args[++i];
162  } else if (args[i].equals("--debug-keyboard") && i+1 < args.length) {
163  debugKeyboardFilename = args[++i];
164  } else if (args[i].equals("--debug-mouse") && i+1 < args.length) {
165  debugMouseFilename = args[++i];
166  } else if (args[i].equals("--debug-screen") && i+1 < args.length) {
167  debugScreenFilename = args[++i];
168  } else if (args[i].equals("--debug-sound") && i+1 < args.length) {
169  debugSoundFilename = args[++i];
170  } else if (args[i].equals("--tile-size") && i+1 < args.length) {
171  final String tmp = args[++i];
172  try {
173  tileSize = Integer.parseInt(tmp);
174  } catch (final NumberFormatException ignored) {
175  System.err.println("Invalid tile size: "+tmp);
176  System.exit(1);
177  }
178  if (tileSize < 1) {
179  System.err.println("Invalid tile size: "+tileSize);
180  System.exit(1);
181  }
182  } else if (args[i].equals("--avoid-copy-area")) {
183  avoidCopyArea = true;
184  } else {
185  System.out.println("");
186  System.out.println("Available options:");
187  System.out.println(" --no-full-screen");
188  //System.out.println(" -N"); // not advertised as it is considered deprecated
189  System.out.println(" -n : Disable full-screen mode.");
190  System.out.println(" --resolution <width>x<height>");
191  System.out.println(" -r <width>x<height>");
192  System.out.println(" : Resolution to use. [default is maximum not exceeding screen]");
193  System.out.println(" --skin <skin>");
194  //System.out.println(" -S <skin>"); // not advertised as it is considered deprecated
195  System.out.println(" -s <skin> : Skin name to use.");
196  System.out.println(" --tile-size <n>: The size of map view tiles in pixels.");
197  System.out.println(" --avoid-copy-area: Do not copy pixel areas when scrolling the map view.");
198  System.out.println(" Instead always repaint all map squares.");
199  System.out.println(" --opengl : Enable the OpenGL rendering pipeline.");
200  System.out.println(" --server <host>: Select a server to connect to; skips main and metaserver");
201  System.out.println(" windows.");
202  System.out.println(" --debug-gui : Enable debugging of GUI elements.");
203  System.out.println(" --debug-keyboard <log-file>");
204  System.out.println(" : Log keyboard input.");
205  System.out.println(" --debug-mouse <log-file>");
206  System.out.println(" : Log mouse input.");
207  System.out.println(" --debug-protocol <log-file>");
208  System.out.println(" : Log messages exchanged with the server.");
209  System.out.println(" --debug-screen <log-file>");
210  System.out.println(" : Log messages related to screen resolution.");
211  System.out.println(" --debug-sound <log-file>");
212  System.out.println(" : Log messages related to sound.");
213  System.out.println("");
214  System.out.println("Available skins: default, ragnorok.");
215  System.exit(1);
216  }
217  i++;
218  }
219 
220  // Map "default to actual skin name; must be after skin name has
221  // been written to preferences.
222  if (skin.equals("default")) {
223  skin = DEFAULT_SKIN;
224  }
225  }
226 
232  @Nullable
233  public String getDebugProtocolFilename() {
234  return debugProtocolFilename;
235  }
236 
241  @Nullable
242  public String getDebugKeyboardFilename() {
243  return debugKeyboardFilename;
244  }
245 
250  @Nullable
251  public String getDebugMouseFilename() {
252  return debugMouseFilename;
253  }
254 
259  @Nullable
260  public String getDebugScreenFilename() {
261  return debugScreenFilename;
262  }
263 
268  @Nullable
269  public String getDebugSoundFilename() {
270  return debugSoundFilename;
271  }
272 
277  public boolean isDebugGui() {
278  return debugGui;
279  }
280 
285  @Nullable
287  return resolution;
288  }
289 
294  @Nullable
295  public String getSkin() {
296  return skin;
297  }
298 
303  public int getTileSize() {
304  return tileSize;
305  }
306 
311  public boolean isFullScreen() {
312  return fullScreen;
313  }
314 
319  @Nullable
320  public String getServer() {
321  return server;
322  }
323 
329  public boolean isAvoidCopyArea() {
330  return avoidCopyArea;
331  }
332 
333 }
Resolution resolution
The resolution to use or.
Definition: Options.java:100
String debugKeyboardFilename
The filename for keyboard debug logs or.
Definition: Options.java:74
String getDebugMouseFilename()
Returns the filename for mouse debug logs.
Definition: Options.java:251
static final int DEFAULT_TILE_SIZE
The default size of tiles in the map view in pixels.
Definition: Options.java:39
String getDebugScreenFilename()
Returns the filename for screen debug logs.
Definition: Options.java:260
Resolution getResolution()
Returns the resolution.
Definition: Options.java:286
String debugSoundFilename
The filename for sound debug logs or.
Definition: Options.java:94
static Resolution parse(@NotNull final String str)
Creates a new instance from string representation.
Definition: Resolution.java:66
String getDebugProtocolFilename()
Returns the filename for Crossfire protocol debug logs.
Definition: Options.java:233
int tileSize
The size of tiles in the map view in pixels.
Definition: Options.java:111
boolean avoidCopyArea
Whether map scrolling is done by copying pixel areas.
Definition: Options.java:123
String getDebugSoundFilename()
Returns the filename for sound debug logs.
Definition: Options.java:269
boolean debugGui
Enable debugging of GUI elements.
Definition: Options.java:60
boolean isAvoidCopyArea()
Returns whether map scrolling is done by copying pixel areas.
Definition: Options.java:329
int getTileSize()
Returns the size of a tile in the map view.
Definition: Options.java:303
Maintains a set of key/value pairs.
Definition: Settings.java:43
boolean isFullScreen()
Returns whether full-screen mode should be enabled.
Definition: Options.java:311
String skin
The skin name to load or.
Definition: Options.java:106
String debugProtocolFilename
The filename for Crossfire protocol message logs or.
Definition: Options.java:67
String getDebugKeyboardFilename()
Returns the filename for keyboard debug logs.
Definition: Options.java:242
String getSkin()
Returns the skin name.
Definition: Options.java:295
String debugScreenFilename
The filename for screen debug logs or.
Definition: Options.java:88
String getServer()
Returns the Crossfire server to connect to.
Definition: Options.java:320
boolean isDebugGui()
Returns whether debugging of GUI elements is enabled.
Definition: Options.java:277
Information about JXClient&#39;s screen/window resolution.
Definition: Resolution.java:35
String server
The Crossfire server to connect to or.
Definition: Options.java:55
Command line argument parser.
Definition: Options.java:34
void parse(@NotNull final String[] args)
Parse command line arguments.
Definition: Options.java:129
String debugMouseFilename
The filename for mouse debug logs or.
Definition: Options.java:81
boolean fullScreen
The Settings for saving/restoring defaults.
Definition: Options.java:48
static final String DEFAULT_SKIN
The default skin name.
Definition: Options.java:117