Mercurial > projects > mde
annotate mde/lookup/Options.d @ 94:9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
This should facilitate generic option editing widgets.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 17:45:49 +0100 |
parents | 97e6dce08037 |
children | 2a364c7d82c9 |
rev | line source |
---|---|
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** This module handles stored options, currently all except input maps. |
84
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
17 * |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
18 * The purpose of having all options centrally controlled is to allow generic handling by the GUI |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
19 * and ease saving and loading of values. The Options class is only really designed around handling |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
20 * small numbers of variables for now. |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
21 * |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
22 * Note: This module uses some non-spec functionality, which "works for me", but may need to be |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
23 * changed if it throws up problems. Specifically: templated virtual functions (Options.set, get |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
24 * and list), and accessing private templates from an unrelated class (Options.TName, TYPES). |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
25 * OptionChanges used to have a templated set member function (used by Options.set), which caused |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
26 * linker problems when the module wasn't compiled from scratch. |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
27 */ |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
28 module mde.lookup.Options; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
29 |
70
7fc0a8295c83
Moved my parseTo and parseFrom modules from tango.scrapple to mde in order to reduce dependencies.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
67
diff
changeset
|
30 import mde.setup.paths; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 import mde.exception; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
32 |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
33 public import mde.gui.content.Content; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
34 |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
35 import mde.file.mergetag.Reader; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
36 import mde.file.mergetag.Writer; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
37 import mde.file.mergetag.DataSet; |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
38 import mde.file.serialize; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 import tango.core.Exception : ArrayBoundsException; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 import tango.util.log.Log : Log, Logger; |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
42 private Logger logger; |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
43 static this() { |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
44 logger = Log.getLogger ("mde.lookup.Options"); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
45 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
46 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 /** Base class for handling options. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 * This class itself handles no options and should not be instantiated, but provides a sub-classable |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 * base for generic options handling. Also, the static portion of this class tracks sub-class |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 * instances and provides loading and saving methods. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
52 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 * Each sub-class provides named variables for maximal-speed reading. Local sub-class references |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
54 * should be used for reading variables, and via the addOptionsClass() hook will be loaded from |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
55 * files during pre-init (init0 stage). Do not write changes directly to the subclasses or they will |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
56 * not be saved; instead use set(), for example, miscOpts.set!(char[])("L10n","en-GB"). Use an |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
57 * example like MiscOptions as a template for creating a new Options sub-class. |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 * |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
59 * Optionally, overload the validate() function. This is called after loading, allowing conditions |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
60 * to be enforced on variables. Use set!()() to change the variables. If an exception is thrown, |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
61 * init will abort and the executable won't start. |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
62 * |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
63 * Details: Options sub-classes hold associative arrays of pointers to all option variables, with a |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
64 * char[] id. This list is used for saving, loading and to provide generic GUI options screens. The |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
65 * built-in support in Options is only for bool, int and char[] types (a float type may get added). |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
66 * Further to this, a generic class is used to store all options which have been changed, and if any |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
67 * have been changed, is merged with options from the user conf dir and saved on exit. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
68 */ |
84
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
69 /* An idea for potentially extending Options, but which doesn't seem necessary now: |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
70 Move static code from Options to an OptionSet class, which may be sub-classed. These sub-classes |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
71 may be hooked in to the master OptionSet class to shadow all Options classes and be notified of |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
72 changes, and may or may not have values loaded from files during init. Change-sets could be |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
73 rewritten to use this. |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
74 However, only the changesets should need to be notified of each change (gui interfaces could simply |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
75 be notified that a change occured and redraw everything; users of options can just re-take their |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
76 values every time they use them). */ |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
77 class Options : IDataSection |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 { |
84
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
79 protected this() {} /// Do not instantiate directly. |
e0f1ec7fe73a
Merge plus a few tweaks.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
82
diff
changeset
|
80 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
81 // All supported types, for generic handling via templates. It should be possible to change |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
82 // the supported types simply by changing this list now (untested). |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
83 template store(A...) { alias A store; } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
84 alias store!(int, double, char[]) TYPES;//FIXME removed bool |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
85 //BEGIN Templates: internal |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
86 private { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
87 // Get name of a type. Basically just stringof, but special handling for arrays. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
88 // Use TName!(T) for a valid symbol name, and T.stringof for a type. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
89 template TName(T : T[]) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
90 const char[] TName = TName!(T) ~ "A"; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
91 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
92 template TName(T) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
93 const char[] TName = T.stringof; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
94 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
95 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
96 // Pointer lists |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
97 template PLists(A...) { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
98 static if (A.length) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
99 static if (is (T == bool)) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
100 const char[] PLists = PLists!(A[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
101 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
102 const char[] PLists = A[0].stringof~"*[ID] opts"~TName!(A[0])~";\n" ~ PLists!(A[1..$]); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
103 } else |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
104 const char[] PLists = ""; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
105 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
106 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
107 // True if type is one of A |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
108 template TIsIn(T, A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
109 static if (A.length) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
110 static if (is(T == A[0])) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
111 const bool TIsIn = true; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
112 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
113 const bool TIsIn = TIsIn!(T,A[1..$]); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
114 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
115 const bool TIsIn = false; // no more possibilities |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
116 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
117 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
118 // For addTag |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
119 template addTagMixin(T, A...) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
120 static if (is(T == bool)) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
121 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
122 auto p = id in opts; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
123 if (p) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
124 auto q = cast(BoolContent) (*p); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
125 if (q) q = parseTo!(`~T.stringof~`) (dt); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
126 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
127 }`; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
128 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
129 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
130 `~T.stringof~`** p = id in opts`~TName!(T)~`; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
131 if (p !is null) **p = parseTo!(`~T.stringof~`) (dt); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
132 }`; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
133 static if (A.length) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
134 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
135 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
136 const char[] addTagMixin = ifBlock; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
137 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
138 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
139 // For writeAll |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
140 template writeAllMixin(A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
141 static if (A.length) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
142 const char[] writeAllMixin = |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
143 `foreach (ID id, `~A[0].stringof~`* val; opts`~TName!(A[0])~`) dlg ("`~A[0].stringof~`", id, parseFrom!(`~A[0].stringof~`) (*val));` ~ writeAllMixin!(A[1..$]); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
144 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
145 const char[] writeAllMixin = ``; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
146 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
147 |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
148 // For list |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
149 template listMixin(A...) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
150 static if (A.length) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
151 const char[] listMixin = `ret ~= opts`~TName!(A[0])~`.keys;` ~ listMixin!(A[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
152 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
153 const char[] listMixin = ``; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
154 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
155 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
156 //END Templates: internal |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
157 |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
158 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
159 //BEGIN Static |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
160 static { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
161 /** Add an options sub-class to the list for loading and saving. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
162 * |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
163 * Call from static this() (before Init calls load()). */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
164 void addOptionsClass (Options c, char[] i) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
165 in { // Trap a couple of potential coding errors: |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
166 assert (c !is null); // Instance must be created before calling addOptionsClass |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
167 assert (((cast(ID) i) in subClasses) is null); // Don't allow a silent replacement |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
168 } body { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
169 c.secName = i; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
170 subClasses[cast(ID) i] = c; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
171 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
172 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
173 // Track all sections for saving/loading/other generic handling. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
174 Options[ID] subClasses; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
175 bool changed = false; // any changes at all, i.e. do we need to save? |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
176 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
177 /* Load/save options from file. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
178 * |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
179 * If the file doesn't exist, no reading is attempted (options are left at default values). |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
180 */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
181 private const fileName = "options"; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
182 void load () { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
183 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
184 IReader reader; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
185 reader = confDir.makeMTReader (fileName, PRIORITY.LOW_HIGH); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
186 reader.dataSecCreator = delegate IDataSection(ID id) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
187 /* Recognise each defined section, and return null for unrecognised sections. */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
188 Options* p = id in subClasses; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
189 if (p !is null) return *p; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
190 else return null; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
191 }; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
192 reader.read; |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
193 } catch (NoFileException e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
194 // Just return. Options file will be created on exit. |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
195 } catch (Exception e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
196 logger.warn ("Loading options failed: "~e.msg); |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
197 logger.warn ("If warning persists, delete the offending file."); // FIXME - delete the bad file somehow |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
198 } |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
199 foreach (opts; subClasses) |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
200 opts.validate; // post-load checking of variables |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
201 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
202 void save () { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
203 if (!changed) return; // no changes to save |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
204 debug logger.trace ("Saving options..."); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
205 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
206 DataSet ds = new DataSet(); |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
207 foreach (id, subOpts; subClasses) |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
208 ds.sec[id] = subOpts.optionChanges; |
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
209 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
210 // Read locally-stored options |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
211 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
212 IReader reader; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
213 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
214 reader.dataSecCreator = delegate IDataSection(ID id) { |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
215 debug logger.warn ("New section appearing in options.mtt during save (ignored & overwritten): "~id); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
216 return null; // All recognised sections are already in the dataset. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
217 }; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
218 reader.read; |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
219 } catch (NoFileException) { |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
72
diff
changeset
|
220 // No user file exists; not an error. |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
221 } catch (Exception e) { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
222 // Log a message and continue, overwriting the file: |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
223 logger.error ("Loading options aborted: " ~ e.msg); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
224 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
225 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
226 try { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
227 IWriter writer; |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
228 writer = confDir.makeMTWriter (fileName, ds); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
229 writer.write(); |
81
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
230 } catch (Exception e) { |
d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
80
diff
changeset
|
231 logger.error ("Saving options aborted: "~e.msg); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
232 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
233 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
234 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
235 //END Static |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
236 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
237 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
238 //BEGIN Non-static |
82
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
239 /+ NOTE: according to spec: "Templates cannot be used to add non-static members or virtual |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
240 functions to classes." However, this appears to work (but linking problems did occur). |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
241 Alternative: use mixins. From OptionsChanges: |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
242 // setT (used to be a template, but: |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
243 // Templates cannot be used to add non-static members or virtual functions to classes. ) |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
244 template setMixin(A...) { |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
245 static if (A.length) { |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
246 const char[] setMixin = `void set`~TName!(A[0])~` (ID id, `~A[0].stringof~` x) { |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
247 `~TName!(T)~`s[id] = x; |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
248 } |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
249 ` ~ setMixin!(A[1..$]); |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
250 } else |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
251 const char[] setMixin = ``; |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
252 }+/ |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
253 /** Set option symbol of an Options sub-class to val. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
254 * |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
255 * Due to the way options are handled generically, string IDs must be used to access the options |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
256 * via hash-maps, which is a little slower than direct access but necessary since the option |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
257 * must be changed in two separate places. */ |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
258 void set(T) (char[] symbol, T val) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
259 static assert (TIsIn!(T,TYPES) && !is(T == bool), "Options does not support type "~T.stringof); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
260 |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
261 changed = true; // something got set (don't bother checking this isn't what it already was) |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
262 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
263 try { |
82
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
264 mixin (`*(opts`~TName!(T)~`[cast(ID) symbol]) = val;`); |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
265 mixin (`optionChanges.`~TName!(T)~`s[symbol] = val;`); |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
266 } catch (ArrayBoundsException) { |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
267 // log and ignore: |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
268 logger.error ("Options.set: invalid symbol"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
269 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
270 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
271 /+ |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
272 /** Get option symbol of an Options sub-class. |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
273 * |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
274 * Using this method to read an option is not necessary, but allows for generic use. */ |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
275 T get(T) (char[] symbol) { |
79
61ea26abe4dd
Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
276 static assert (TIsIn!(T,TYPES), "Options does not support type "~T.stringof); |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
277 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
278 mixin (`alias opts`~TName!(T)~` optsVars;`); |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
279 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
280 try { |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
281 return *(optsVars[cast(ID) symbol]); |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
282 } catch (ArrayBoundsException) { |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
283 // log and ignore: |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
284 logger.error ("Options.get: invalid symbol"); |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
285 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
286 }+/ |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
287 |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
288 /** List the names of all options of a specific type. */ |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
289 char[][] list () { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
290 char[][] ret; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
291 mixin (listMixin!(TYPES)); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
292 return ret; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
293 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
294 |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
295 /// Get all Options stored with a ValueContent. |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
296 ValueContent[char[]] content() { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
297 return opts; |
72
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
298 } |
159775502bb4
The first dynamically generated widget lists, based on Options, are here!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
70
diff
changeset
|
299 |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
300 /// Variable validate function. This implementation does nothing. |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
301 void validate() {} |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
302 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
303 protected { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
304 char[] secName; // name of this option setting; set null after translation is loaded |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
305 OptionChanges optionChanges; // all changes to options (for saving) |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
306 |
79
61ea26abe4dd
Moved mde/mergetag/parse/parse(To/From) to mde/mergetag/(de)serialize. Implemented (de)serialization of structs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
307 // The "pointer lists", e.g. char[]*[ID] optscharA; |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
308 mixin (PLists!(TYPES)); //FIXME adds unused optsbool |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
309 ValueContent[char[]] opts; // generic list of option values |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
310 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
311 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
312 //BEGIN Mergetag loading/saving code |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
313 void addTag (char[] tp, ID id, char[] dt) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
314 mixin(addTagMixin!(TYPES).addTagMixin); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
315 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
316 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
317 void writeAll (ItemDelg dlg) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
318 mixin(writeAllMixin!(TYPES)); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
319 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
320 //END Mergetag loading/saving code |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
321 //END Non-static |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
322 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
323 |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
324 //BEGIN Templates: impl & optionsThis |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
325 private { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
326 // Replace, e.g., bool, with BoolContent |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
327 template contentName(A) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
328 static if (is(A == bool)) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
329 const char[] contentName = "BoolContent"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
330 } else static if (is(A == int)) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
331 const char[] contentName = "int";// no IntContent yet |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
332 } else static if (is(A == double)) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
333 const char[] contentName = "double"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
334 } else static if (is(A == char[])) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
335 const char[] contentName = "char[]"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
336 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
337 static assert (false, "unsuppurted type: "~ A); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
338 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
339 // Return index of first comma, or halts if not found. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
340 template cIndex(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
341 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
342 static assert (false, "Error in implementation"); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
343 else static if (A[0] == ',') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
344 const size_t cIndex = 0; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
345 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
346 const size_t cIndex = 1 + cIndex!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
347 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
348 // Return index of first semi-colon, or halts if not found. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
349 template scIndex(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
350 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
351 static assert (false, "Error: no trailing semi-colon"); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
352 else static if (A[0] == ';') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
353 const size_t scIndex = 0; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
354 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
355 const size_t scIndex = 1 + scIndex!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
356 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
357 /* Look for "type symbols;" in A and return symbols as a comma separated list of names |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
358 (even if type is encountered more than once). Output may contain spaces and will have a |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
359 trailing comma unless no match was found in which case an empty string is returned. |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
360 Assumes scIndex always returns less than A.$ . */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
361 template parseT(char[] type, char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
362 static if (A.length < type.length + 1) // end of input, no match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
363 const char[] parseT = ""; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
364 else static if (A[0] == ' ') // leading whitespace: skip |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
365 const char[] parseT = parseT!(type, A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
366 else static if (A[0..type.length] == type && A[type.length] == ' ') // match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
367 const char[] parseT = A[type.length+1 .. scIndex!(A)] ~ "," ~ |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
368 parseT!(type, A[scIndex!(A)+1 .. $]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
369 else // no match |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
370 const char[] parseT = parseT!(type, A[scIndex!(A)+1 .. $]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
371 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
372 // May have a trailing comma. Assumes cIndex always returns less than A.$ . |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
373 template aaVars(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
374 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
375 const char[] aaVars = ""; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
376 else static if (A[0] == ' ') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
377 const char[] aaVars = aaVars!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
378 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
379 const char[] aaVars = "\""~A[0..cIndex!(A)]~"\"[]:&"~A[0..cIndex!(A)] ~ "," ~ |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
380 aaVars!(A[cIndex!(A)+1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
381 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
382 // May have a trailing comma. Assumes cIndex always returns less than A.$ . |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
383 template aaVarsBool(char[] A) {//FIXME |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
384 static if (A.length == 0) |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
385 const char[] aaVarsBool = ""; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
386 else static if (A[0] == ' ') |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
387 const char[] aaVarsBool = aaVarsBool!(A[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
388 else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
389 const char[] aaVarsBool = "\""~A[0..cIndex!(A)]~"\"[]:"~A[0..cIndex!(A)] ~ "," ~ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
390 aaVarsBool!(A[cIndex!(A)+1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
391 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
392 // strip Trailing Comma |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
393 template sTC(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
394 static if (A.length && A[$-1] == ',') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
395 const char[] sTC = A[0..$-1]; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
396 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
397 const char[] sTC = A; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
398 } |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
399 // if string is empty (other than space) return null, otherwise enclose: [A] |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
400 template listOrNull(char[] A) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
401 static if (A.length == 0) |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
402 const char[] listOrNull = "null"; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
403 else static if (A[0] == ' ') |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
404 const char[] listOrNull = listOrNull!(A[1..$]); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
405 else |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
406 const char[] listOrNull = "["~A~"]"; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
407 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
408 // if B is empty return an empty string otherswise return what's below: |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
409 template catOrNothing(char[] A,char[] B) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
410 static if (B.length) |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
411 const char[] catOrNothing = A~` `~sTC!(B)~";\n"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
412 else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
413 const char[] catOrNothing = ``; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
414 } |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
415 // foreach decl... |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
416 template createBCs(char[] A) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
417 static if (A.length == 0) |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
418 const char[] createBCs = ""; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
419 else static if (A[0] == ' ') |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
420 const char[] createBCs = createBCs!(A[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
421 else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
422 const char[] createBCs = A[0..cIndex!(A)]~ " = new BoolContent (false);\n"~ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
423 createBCs!(A[cIndex!(A)+1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
424 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
425 // for recursing on TYPES |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
426 template optionsThisInternal(char[] A, B...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
427 static if (B.length) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
428 static if (is(B[0] == bool)) {//FIXME |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
429 const char[] optionsThisInternal = createBCs!(parseT!(B[0].stringof,A))~ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
430 `opts = `~listOrNull!(sTC!(aaVarsBool!(parseT!(B[0].stringof,A))))~";\n" ~ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
431 optionsThisInternal!(A,B[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
432 } else |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
433 const char[] optionsThisInternal = `opts`~TName!(B[0])~` = `~listOrNull!(sTC!(aaVars!(parseT!(B[0].stringof,A))))~";\n" ~ optionsThisInternal!(A,B[1..$]); |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
434 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
435 const char[] optionsThisInternal = ``; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
436 } |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
437 template declValsInternal(char[] A, B...) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
438 static if (B.length) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
439 const char[] declValsInternal = catOrNothing!(contentName!(B[0]),parseT!(B[0].stringof,A)) ~ declValsInternal!(A,B[1..$]); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
440 } else |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
441 const char[] declValsInternal = ``; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
442 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
443 } protected { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
444 /** Declares the values. |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
445 * |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
446 * Basic types are replaced with a ValueContent class to keep the option synchronized and |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
447 * generalize use. */ |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
448 template declVals(char[] A) { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
449 const char[] declVals = declValsInternal!(A, TYPES,bool); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
450 } |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
451 /** Produces the implementation code to go in the constuctor. */ |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
452 template optionsThis(char[] A) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
453 const char[] optionsThis = |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
454 "optionChanges = new OptionChanges;\n" ~ |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
455 optionsThisInternal!(A,TYPES,bool); |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
456 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
457 /+ Needs too many custom parameters to be worth it? Plus makes class less readable. |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
458 /** Produces the implementation code to go in the static constuctor. */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
459 template optClassAdd(char[] symb) { |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
460 const char[] optClassAdd = symb ~ "=new "~classinfo(this).name~";\n";//Options.addOptionsClass("~symb~", );\n"; |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
461 }+/ |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
462 /** mixin impl("type symbol[, symbol[...]];[type symbol[...];][...]") |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
463 * |
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
464 * Where type is one of bool, int, double, char[]. E.g. |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
465 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
466 * mixin (impl ("bool a, b; int i;")); |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
467 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
468 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
469 * In case this() needs to be customized, mixin(impl!(A)) is equivalent to: |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
470 * --- |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
471 * mixin (declVals!(A)~` |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
472 this () { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
473 `~optionsThis!(A)~` |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
474 }`); |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
475 * --- |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
476 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
477 * Notes: Only use space as whitespace (no new-lines or tabs). Make sure to add a trailing |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
478 * semi-colon (;) or you'll get told off! :D |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
479 * In general errors aren't reported well. Trial with pragma (msg, impl!(...)); if |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
480 * necessary. |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
481 * |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
482 * Extending: mixins could also be used for the static this() {...} or even the whole |
62
960206198cbd
Documentation changes only. (Idea for new gui.content.Items module; unused gl.texture module commented out.)
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
483 * class, but doing so would rather decrease readability of any implementation. */ |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
484 template impl(char[] A /+, char[] symb+/) { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
485 const char[] impl = declVals!(A)~"\nthis(){\n"~optionsThis!(A)~"}"; |
50
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
486 // ~"\nstatic this(){\n"~optClassAdd!(symb)~"}" |
f68ae1d667f9
Options: impl template & new OptionsFont class.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
487 } |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
488 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
489 //END Templates: impl & optionsThis |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
490 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
491 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
492 /** Special class to store all locally changed options, whatever the section. */ |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
493 class OptionChanges : IDataSection |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
494 { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
495 //BEGIN Templates |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
496 private { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
497 alias Options.TName TName; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
498 alias Options.TYPES TYPES; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
499 template Vars(A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
500 static if (A.length) { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
501 const char[] Vars = A[0].stringof~`[ID] `~TName!(A[0])~`s;` ~ Vars!(A[1..$]); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
502 } else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
503 const char[] Vars = ``; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
504 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
505 |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
506 // For addTag |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
507 template addTagMixin(T, A...) { |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
508 const char[] ifBlock = `if (tp == "`~T.stringof~`") { |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
509 if ((id in `~TName!(T)~`s) is null) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
510 `~TName!(T)~`s[id] = parseTo!(`~T.stringof~`) (dt); |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
511 }`; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
512 static if (A.length) |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
513 const char[] addTagMixin = ifBlock~` else `~addTagMixin!(A).addTagMixin; |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
514 else |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
515 const char[] addTagMixin = ifBlock; |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
516 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
517 // For writeAll |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
518 template writeAllMixin(A...) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
519 static if (A.length) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
520 const char[] writeAllMixin = |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
521 `foreach (id, val; `~TName!(A[0])~`s) |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
522 dlg ("`~A[0].stringof~`", id, serialize (val)); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
523 ` ~ writeAllMixin!(A[1..$]); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
524 } else |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
525 const char[] writeAllMixin = ``; |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
526 } |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
527 } |
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
528 //END Templates |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
529 // These store the actual values, but are never accessed directly except when initially added. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
530 // optsX store pointers to each item added along with the ID and are used for access. |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
531 mixin(Vars!(TYPES)); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
532 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
533 this () {} |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
534 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
535 //BEGIN Mergetag loading/saving code |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
536 // HIGH_LOW priority: only load symbols not currently existing |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
537 void addTag (char[] tp, ID id, char[] dt) { |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
538 mixin (addTagMixin!(TYPES).addTagMixin); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
539 } |
80
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
540 void writeAll (ItemDelg dlg) { |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
541 mixin(writeAllMixin!(TYPES)); |
ea58f277f487
Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
79
diff
changeset
|
542 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
543 //END Mergetag loading/saving code |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
544 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
545 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
546 /* NOTE: Options sub-classes are expected to use a template to ease inserting contents and |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
547 * hide some of the "backend" functionality. Use impl as below, or read the documentation for impl. |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
548 * |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
549 * Each entry should have a Translation entry with humanized names and descriptions in |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
550 * data/L10n/ClassName.mtt |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
551 * |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
62
diff
changeset
|
552 * To create a new Options sub-class, just copy, paste and adjust. |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
553 */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
554 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
555 /** A home for all miscellaneous options, at least for now. */ |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
556 MiscOptions miscOpts; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
557 class MiscOptions : Options { |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
558 const A = "bool exitImmediately; int maxThreads, logOptions; double pollInterval; char[] L10n;"; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
559 //pragma (msg, impl!(A)); |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
560 mixin (impl!(A)); |
89
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
561 |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
562 void validate() { |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
563 // Try to enforce sensible values, whilst being reasonably flexible: |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
564 if (miscOpts.maxThreads < 1 || miscOpts.maxThreads > 64) { |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
565 logger.warn ("maxThreads must be in the range 1-64. Defaulting to 4."); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
566 miscOpts.set!(int)("maxThreads", 4); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
567 } |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
568 if (pollInterval !<= 1.0 || pollInterval !>= 0.0) |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
569 set!(double) ("pollInterval", 0.01); |
97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
86
diff
changeset
|
570 } |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
571 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
572 static this() { |
94
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
573 miscOpts = new MiscOptions; |
9520cc0448e5
Boolean options are now encapsulated within a Content class (currently an experiment).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
89
diff
changeset
|
574 Options.addOptionsClass (miscOpts, "MiscOptions"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
575 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
576 } |