Mercurial > projects > mde
annotate mde/options.d @ 25:2c28ee04a4ed
Some minor and some futile efforts.
Played around with init functions, had problems, gave up and put them back.
Removed idea for multiple init stages; it's not good for performance or simplicity.
Adjusted exception messages.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 17:26:52 +0100 |
parents | 32eff0e01c05 |
children | 611f7b9063c6 |
rev | line source |
---|---|
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
1 /* LICENSE BLOCK |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
4 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify it under the terms of |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
6 the GNU General Public License, version 2, as published by the Free Software Foundation. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
7 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
10 See the GNU General Public License for more details. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
11 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
12 You should have received a copy of the GNU General Public License along |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
13 with this program; if not, write to the Free Software Foundation, Inc., |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
15 |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** This module handles stored options, currently all except input maps. |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
19 * and ease saving and loading of values. The Options class is only really designed around handling |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
20 * small numbers of variables for now. |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 */ |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 module mde.options; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 import mde.exception; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
26 import mde.mergetag.Reader; |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
27 import mde.mergetag.Writer; |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
28 import mde.mergetag.DataSet; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 import mde.mergetag.exception; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
30 import mde.resource.paths; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 import tango.scrapple.text.convert.parseTo : parseTo; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 import tango.scrapple.text.convert.parseFrom : parseFrom; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
35 import tango.core.Exception : ArrayBoundsException; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 import tango.util.log.Log : Log, Logger; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
37 |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
38 /** Base class for handling options. |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
39 * |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
40 * This class itself handles no options and should not be instantiated, but provides a sub-classable |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
41 * base for generic options handling. Also, the static portion of this class tracks sub-class |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
42 * instances and provides loading and saving methods. |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 * |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
44 * Each sub-class provides named variables for maximal-speed reading. Local sub-class references |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
45 * should be used for reading variables, and via the addOptionsClass() hook will be loaded from |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
46 * files during pre-init (init0 stage). Do not write changes directly to the subclasses or they will |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
47 * not be saved; use, for example, Options.setBool(...). |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
48 * |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
49 * Details: Options sub-classes hold associative arrays of pointers to all option variables, with a |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
50 * char[] id. This list is used for saving, loading and to provide generic GUI options screens. The |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
51 * built-in support in Options is only for bool, int and char[] types (a float type may get added). |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
52 * Further to this, a generic class is used to store all options which have been changed, and if any |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
53 * have been changed, is merged with options from the user conf dir and saved on exit. |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 */ |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
55 class Options : IDataSection |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
56 { |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
57 // No actual options are stored by this class. However, much of the infrastructure is |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
58 // present since it need not be redefined in sub-classes. |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
59 |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
60 // The "pointer lists": |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
61 protected bool* [ID] optsBool; |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
62 protected char[]*[ID] optsCharA; |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
63 protected int* [ID] optsInt; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
22
diff
changeset
|
65 //BEGIN Mergetag loading/saving code |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 void addTag (char[] tp, ID id, char[] dt) { |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
67 if (tp == "bool") { |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
68 bool** p = id in optsBool; |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
69 if (p !is null) **p = parseTo!(bool) (dt); |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
70 } else if (tp == "char[]") { |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
71 char[]** p = id in optsCharA; |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
72 if (p !is null) **p = parseTo!(char[]) (dt); |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
73 } else if (tp == "int") { |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
74 int** p = id in optsInt; |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
75 if (p !is null) **p = parseTo!(int) (dt); |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
76 } |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
77 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 void writeAll (ItemDelg dlg) { |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
79 foreach (ID id, bool* val; optsBool) dlg ("bool" , id, parseFrom!(bool ) (*val)); |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
80 foreach (ID id, char[]* val; optsCharA) dlg ("char[]", id, parseFrom!(char[]) (*val)); |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
81 foreach (ID id, int* val; optsInt) dlg ("int" , id, parseFrom!(int ) (*val)); |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
82 } |
23
47478557428d
Implemented drawing a very basic gl box, and only drawing when necessary.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
22
diff
changeset
|
83 //END Mergetag loading/saving code |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
84 |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
85 //BEGIN Static |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
86 /** Add an options sub-class to the list for loading and saving. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
87 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
88 * Call from static this() (before Init calls load()). */ |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
89 static void addOptionsClass (Options c, char[] i) |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
90 in { // Trap a couple of potential coding errors: |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
91 assert (c !is null); // Instance must be created before calling addOptionsClass |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
92 assert (((cast(ID) i) in subClasses) is null); // Don't allow a silent replacement |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
93 } body { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
94 subClasses[cast(ID) i] = c; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
95 subClassChanges[cast(ID) i] = new OptionsGeneric; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
96 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
97 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
98 /** Set option symbol of Options class subClass to val. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
99 * |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
100 * Due to the way options are handled generically, string IDs must be used to access the options |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
101 * via hash-maps, which is a little slower than direct access but necessary since the option |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
102 * must be changed in two separate places. */ |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
103 private static const ERR_MSG = "Options.setXXX called with incorrect parameters!"; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
104 static void setBool (char[] subClass, char[] symbol, bool val) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
105 changed = true; // something got set (don't bother checking this isn't what it already was) |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
106 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
107 try { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
108 *(subClasses[cast(ID) subClass].optsBool[cast(ID) symbol]) = val; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
109 subClassChanges[cast(ID) subClass].setBool (cast(ID) symbol, val); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
110 } catch (ArrayBoundsException) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
111 // log and ignore: |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
112 logger.error (ERR_MSG); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
113 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
114 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
115 static void setInt (char[] subClass, char[] symbol, int val) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
116 changed = true; // something got set (don't bother checking this isn't what it already was) |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
117 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
118 try { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
119 *(subClasses[cast(ID) subClass].optsInt[cast(ID) symbol]) = val; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
120 subClassChanges[cast(ID) subClass].setInt (cast(ID) symbol, val); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
121 } catch (ArrayBoundsException) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
122 // log and ignore: |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
123 logger.error (ERR_MSG); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
124 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
125 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
126 static void setCharA (char[] subClass, char[] symbol, char[] val) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
127 changed = true; // something got set (don't bother checking this isn't what it already was) |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
128 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
129 try { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
130 *(subClasses[cast(ID) subClass].optsCharA[cast(ID) symbol]) = val; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
131 subClassChanges[cast(ID) subClass].setCharA (cast(ID) symbol, val); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
132 } catch (ArrayBoundsException) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
133 // log and ignore: |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
134 logger.error (ERR_MSG); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
135 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
136 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
137 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
138 // Track all sections for saving/loading/other generic handling. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
139 static Options[ID] subClasses; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
140 static OptionsGeneric[ID] subClassChanges; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
141 static bool changed = false; // any changes at all, i.e. do we need to save? |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
142 |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
143 /* Load/save options from file. |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
144 * |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
145 * If the file doesn't exist, no reading is attempted (options are left at default values). |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
146 */ |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
147 private static const fileName = "options"; |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
148 private static const MT_LOAD_EXC = "Loading options aborted:"; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
149 static void load () { |
14
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
150 // Check it exists (if not it should still be created on exit). |
0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
12
diff
changeset
|
151 // Don't bother checking it's not a folder, because it could still be a block or something. |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
152 if (!confDir.exists (fileName)) return; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
153 |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
154 try { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
155 IReader reader; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
156 reader = confDir.makeMTReader (fileName, PRIORITY.LOW_HIGH); |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
157 reader.dataSecCreator = delegate IDataSection(ID id) { |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
158 /* Recognise each defined section, and return null for unrecognised sections. */ |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
159 Options* p = id in subClasses; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
160 if (p !is null) return *p; |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
161 else return null; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
162 }; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
163 reader.read; |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
164 } catch (MTException e) { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
165 logger.fatal (MT_LOAD_EXC); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
166 logger.fatal (e.msg); |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
167 throw new optionsLoadException ("Mergetag exception (see above message)"); |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
168 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
169 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
170 static void save () { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
171 if (!changed) return; // no changes to save |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
172 |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
173 DataSet ds = new DataSet(); |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
174 foreach (id, sec; subClassChanges) ds.sec[id] = sec; |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
175 |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
176 // Read locally-stored options |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
177 try { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
178 IReader reader; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
179 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
180 reader.dataSecCreator = delegate IDataSection(ID id) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
181 return null; // All recognised sections are already in the dataset. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
182 }; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
183 reader.read; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
184 } catch (MTFileIOException) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
185 // File either didn't exist or couldn't be opened. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
186 // Presuming the former, this is not a problem. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
187 } catch (MTException e) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
188 // Log a message and continue, overwriting the file: |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
189 logger.error (MT_LOAD_EXC); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
190 logger.error (e.msg); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
191 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
192 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
193 try { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
194 IWriter writer; |
15
4608be19ebe2
Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
14
diff
changeset
|
195 writer = confDir.makeMTWriter (fileName, ds); |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
196 writer.write(); |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
197 } catch (MTException e) { |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
198 logger.error ("Saving options aborted! Reason:"); |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
199 logger.error (e.msg); |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
200 } |
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
201 } |
12
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
202 |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
203 private static Logger logger; |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
204 static this() { |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
205 logger = Log.getLogger ("mde.options"); |
bff0d802cb7d
Implemented some internationalization support.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
11
diff
changeset
|
206 } |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
207 //END Static |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
208 |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
209 //BEGIN Templates |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
210 template store(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
211 alias A a; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
212 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
213 template decRecurse(char[] A, B...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
214 static if (B.length) const char[] decRecurse = A ~ ", " ~ decRecurse!(B); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
215 else const char[] decRecurse = A; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
216 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
217 template decBool(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
218 const char[] decBool = "bool " ~ decRecurse!(A) ~ ";\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
219 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
220 template decCharA(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
221 const char[] decCharA = "char[] " ~ decRecurse!(A) ~ ";\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
222 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
223 template decInt(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
224 const char[] decInt = "int " ~ decRecurse!(A) ~ ";\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
225 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
226 template aaRecurse(char[] A, B...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
227 static if (B.length) const char[] aaRecurse = "\""~A~"\"[]:&"~A ~ ", " ~ aaRecurse!(B); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
228 else const char[] aaRecurse = "\""~A~"\"[]:&"~A; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
229 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
230 template aaBool(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
231 const char[] aaBool = "optsBool = [" ~ aaRecurse!(A) ~ "];\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
232 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
233 template aaInt(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
234 const char[] aaInt = "optsInt = [" ~ aaRecurse!(A) ~ "];\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
235 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
236 template aaCharA(A...) { |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
237 const char[] aaCharA = "optsCharA = [" ~ aaRecurse!(A) ~ "];\n"; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
238 } |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
239 //END Templates |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
240 } |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
241 |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
242 /* Special class to store all locally changed options, whatever the section. */ |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
243 class OptionsGeneric : Options { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
244 // These store the actual values, but are never accessed directly except when initially added. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
245 // optsX store pointers to each item added along with the ID and are used for access. |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
246 bool[] bools; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
247 int[] ints; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
248 char[][] strings; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
249 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
250 this () {} |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
251 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
252 void setBool (ID id, bool x) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
253 bool** p = id in optsBool; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
254 if (p !is null) **p = x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
255 else { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
256 bools ~= x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
257 optsBool[id] = &bools[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
258 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
259 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
260 void setInt (ID id, int x) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
261 int** p = id in optsInt; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
262 if (p !is null) **p = x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
263 else { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
264 ints ~= x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
265 optsInt[id] = &ints[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
266 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
267 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
268 void setCharA (ID id, char[] x) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
269 char[]** p = id in optsCharA; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
270 if (p !is null) **p = x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
271 else { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
272 strings ~= x; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
273 optsCharA[id] = &strings[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
274 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
275 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
276 |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
277 //BEGIN Mergetag loading/saving code |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
278 // Reverse priority: only load symbols not currently existing |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
279 void addTag (char[] tp, ID id, char[] dt) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
280 if (tp == "bool") { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
281 if ((id in optsBool) is null) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
282 bools ~= parseTo!(bool) (dt); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
283 optsBool[id] = &bools[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
284 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
285 } else if (tp == "char[]") { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
286 if ((id in optsCharA) is null) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
287 strings ~= parseTo!(char[]) (dt); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
288 optsCharA[id] = &strings[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
289 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
290 char[]** p = id in optsCharA; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
291 if (p !is null) **p = parseTo!(char[]) (dt); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
292 } else if (tp == "int") { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
293 if ((id in optsInt) is null) { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
294 ints ~= parseTo!(int) (dt); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
295 optsInt[id] = &ints[$-1]; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
296 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
297 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
298 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
299 //END Mergetag loading/saving code |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
300 } |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
301 |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
302 /* NOTE: These Options classes use templates to ease inserting contents. |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
303 * |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
304 * Each entry has an I18nTranslation entry; see data/L10n/ClassName.mtt for descriptions. |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
305 * |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
306 * To create a new class, just copy and paste anywhere and adjust. |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
307 */ |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
308 |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
309 /** A home for all miscellaneous options, at least for now. */ |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
310 OptionsMisc miscOpts; |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
311 class OptionsMisc : Options { |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
312 alias store!("useThreads") BOOL; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
313 alias store!("logLevel") INT; |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
314 alias store!("L10n") CHARA; |
18
56a42ec95024
Changes to Init and logging.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
17
diff
changeset
|
315 |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
316 mixin (decBool!(BOOL.a)); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
317 mixin (decInt!(INT.a)); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
318 mixin (decCharA!(CHARA.a)); |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
319 |
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
320 this () { |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
321 mixin (aaBool!(BOOL.a)); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
322 mixin (aaInt!(INT.a)); |
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
323 mixin (aaCharA!(CHARA.a)); |
16
9cb7b9310168
Improvements to Options and Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
15
diff
changeset
|
324 } |
22
249eb6620685
Changes to Options, particularly regarding window sizes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
325 |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
326 static this() { |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
327 miscOpts = new OptionsMisc; |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
23
diff
changeset
|
328 Options.addOptionsClass (miscOpts, "misc"); |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
329 } |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
18
diff
changeset
|
330 } |