annotate mde/file/mergetag/MTTagWriter.d @ 137:9f035cd139c6

BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed. Content restrutured a lot: New IContent module, Content module includes more functionality. New ContentLoader module to manage content loading/saving/translation. Translation module moved to content dir and cut down to reflect current usage. File format unchanged except renames: FontOptions -> Font, VideoOptions -> Screen. Font render mode and LCD filter options are now enums. GUI loading needs to create content (and set type for enums), but doesn't save/load value. Some setup of mainSchedule moved to mde.mainLoop. Content callbacks are called on content change now. ContentLists are set up implicitly from content symbols. Not as fast but much easier! Bug-fix in the new MTTagReader. Renamed MT *Reader maker functions to avoid confusion in paths.d. New mde.setup.logger module to allow logger setup before any other module's static this().
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 07 Feb 2009 12:46:03 +0000
parents 4084f07f2c7a
children e785e98d3b78
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 the terms of the GNU General Public License as published by the Free Software
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 Foundation, either version 2 of the License, or (at your option) any later version.
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
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
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 PARTICULAR PURPOSE. See the GNU General Public License for more details.
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /******************************************************************************
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * This module contains a simpler, easier to use, mergetag writer.
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 *****************************************************************************/
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 module mde.file.mergetag.MTTagWriter;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 import mde.file.mergetag.internal;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 import mde.file.mergetag.exception;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import tango.io.device.File;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import tango.io.stream.Buffer;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import tango.util.log.Log : Log, Logger;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 private Logger logger;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29 static this() {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 logger = Log.getLogger ("mde.file.mergetag.MTTagWriter");
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
33 MTTagWriter getMTTagWriter (char[] path) {
136
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 if (path.length > 4 && path[$-4..$] == ".mtt")
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 return new MTTTagWriter (path);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 else if (path.length > 4 && path[$-4..$] == ".mtb")
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 return new MTBTagWriter (path);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 else {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 logger.error ("Unable to determine writing format: text or binary");
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 throw new MTFileFormatException;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 abstract class MTTagWriter
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /// Set the current section
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 void sectionTag (char[] section);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 /// Write a data tag
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 void dataTag (char[] type, char[] id, char[] data);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 /// Change the section if necessary and write a data tag
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 void writeTag (char[] section, char[] type, char[] id, char[] data) {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 if (section != sec)
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 sectionTag (section);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 dataTag (type, id, data);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 /// Close the file
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 void close ();
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 protected:
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 char[] sec; // current section
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 class MTTTagWriter : MTTagWriter
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 /** Opens the file path for writing. Call close() when done! */
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 this (char[] path) {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 buffer = new BufferOutput (new File (path, File.WriteCreate));
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 buffer.append ("{" ~ CurrentVersionString ~ "}" ~ Eol);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 void sectionTag (char[] section) {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 sec = section;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 buffer.append ("{" ~ section ~ "}" ~ Eol);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 void dataTag (char[] type, char[] id, char[] data) {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 buffer.append ("<" ~ type ~ "|" ~ id ~"=" ~ data ~ ">" ~ Eol);
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 void close () {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 buffer.flush;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 buffer.close;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 private:
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 scope BufferOutput buffer;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 class MTBTagWriter : MTTagWriter
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 this (char[] path) {
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 throw new MTNotImplementedException;
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 }
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 void sectionTag (char[] section) {}
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 void dataTag (char[] type, char[] id, char[] data) {}
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 void close () {}
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 }