cosmetix
[xreader.git] / xreadercfg.d
blob44c5b52dc1c3cfb75336e5fc93f05c0fc65c8bb0
1 /* Written by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module xreadercfg;
19 import core.atomic;
20 import core.time;
22 import std.concurrency;
23 import std.stdio;
25 import iv.strex;
27 import arsd.simpledisplay;
28 import arsd.color;
29 import arsd.png;
30 import arsd.jpeg;
32 import iv.nanovg;
34 import iv.vfs;
36 import xmodel;
37 import xiniz;
39 import booktext;
42 // ////////////////////////////////////////////////////////////////////////// //
43 __gshared string RcDir = "~/.xreader";
44 __gshared string stateFileName;
46 __gshared float shipAngle = 0;
47 __gshared bool showShip = false;
49 __gshared EliteModel shipModel;
52 // ////////////////////////////////////////////////////////////////////////// //
53 __gshared string textFontName = "~/ttf/ms/arial.ttf:noaa";
54 __gshared string textiFontName = "~/ttf/ms/ariali.ttf:noaa";
55 __gshared string textbFontName = "~/ttf/ms/arialbd.ttf:noaa";
56 __gshared string textzFontName = "~/ttf/ms/arialbi.ttf:noaa";
57 __gshared string monoFontName = "~/ttf/ms/cour.ttf:noaa";
58 __gshared string monoiFontName = "~/ttf/ms/couri.ttf:noaa";
59 __gshared string monobFontName = "~/ttf/ms/courbd.ttf:noaa";
60 __gshared string monozFontName = "~/ttf/ms/courbi.ttf:noaa";
61 __gshared string uiFontName = "~/ttf/ms/verdana.ttf:noaa";
62 __gshared string galmapFontName = "~/ttf/ms/verdana.ttf:noaa";
63 __gshared int GWidth = 900;
64 __gshared int GHeight = 1024;
65 __gshared int fsizeText = 24;
66 __gshared int fsizeUI = 16;
67 __gshared int fGalMapSize = 16;
68 __gshared bool sbLeft = false;
69 __gshared bool interAllowed = false;
71 __gshared bool flagNanoAA = false;
72 __gshared bool flagNanoSS = false;
74 __gshared uint colorDim = 0;
75 __gshared uint colorBack = 0x2a2a2a;
76 __gshared uint colorText = 0xff7f00;
77 __gshared uint colorTextHi = 0xffff00;
79 __gshared int uiFont, galmapFont;
80 __gshared int textFont, textiFont, textbFont, textzFont;
81 __gshared int monoFont, monoiFont, monobFont, monozFont;
83 __gshared bool optJustify = false;
86 // ////////////////////////////////////////////////////////////////////////// //
87 BookInfo[] loadDetailedHistory () {
88 BookInfo[] res;
89 try {
90 import std.path;
91 foreach (string line; File(buildPath(RcDir, ".lastfile")).byLineCopy) {
92 line = xstrip(line);
93 if (line.length == 0 || line[0] == '#' || line[0] == ';') continue;
94 try {
95 res ~= loadBookInfo(line);
96 res[$-1].diskfile = line.idup;
97 } catch (Exception e) {}
99 } catch (Exception) {}
100 return res;
104 // ////////////////////////////////////////////////////////////////////////// //
105 __gshared string[] eliteShipFiles;
108 void loadEliteShips () {
109 import std.path;
110 import std.path : extension;
111 vfsAddPak(buildPath(RcDir, "eliteships.zip"), "oxm:");
112 //scope(exit) vfsRemovePack(buildPath(RcDir, "eliteships.zip"), "oxm:");
113 foreach (immutable idx, ref de; vfsFileList) {
114 //writeln("<", de.name, ">");
115 if (de.name.length > 4 && de.name[0..4] == "oxm:" && strEquCI(de.name.extension, ".oxm")) {
117 import core.memory : GC;
118 try {
119 auto mdl = new EliteModel(de.name);
120 mdl.freeData();
121 mdl.destroy;
122 //eliteShips ~= mdl;
123 eliteShipFiles ~= de.name;
124 } catch (Exception e) {}
125 GC.collect();
127 eliteShipFiles ~= de.name;
133 // ////////////////////////////////////////////////////////////////////////// //
134 auto u2ca (uint v) {
135 return nvgRGBA(
136 (v>>16)&0xff,
137 (v>>8)&0xff,
138 v&0xff,
139 (v>>24)&0xff,
144 auto u2c (uint v) {
145 return nvgRGB(
146 (v>>16)&0xff,
147 (v>>8)&0xff,
148 v&0xff,
153 // ////////////////////////////////////////////////////////////////////////// //
154 VFile fwritef(A...) (VFile fl, string fmt, /*lazy*/ A args) {
155 import std.string : format;
156 auto s = format(fmt, args);
157 if (s.length) fl.rawWriteExact(s[]);
158 return fl;
162 // ////////////////////////////////////////////////////////////////////////// //
163 void readConfig () {
164 import std.path;
165 VFile fl;
166 try {
167 fl = VFile(buildPath(RcDir, ".config.ui"));
168 } catch (Exception) {
169 try {
170 try { import std.file; mkdirRecurse(RcDir); } catch (Exception) {}
171 fl = VFile(buildPath(RcDir, ".config.ui"), "w");
172 fl.fwritef("width=%s\n", GWidth);
173 fl.fwritef("height=%s\n", GHeight);
174 fl.fwritef("font-text=%s\n", textFontName);
175 fl.fwritef("font-text-italic=%s\n", textiFontName);
176 fl.fwritef("font-text-bold=%s\n", textbFontName);
177 fl.fwritef("font-text-bold-italic=%s\n", textzFontName);
178 fl.fwritef("font-mono=%s\n", monoFontName);
179 fl.fwritef("font-mono-italic=%s\n", monoiFontName);
180 fl.fwritef("font-mono-bold=%s\n", monobFontName);
181 fl.fwritef("font-mono-bold-italic=%s\n", monozFontName);
182 fl.fwritef("font-ui=%s\n", uiFontName);
183 fl.fwritef("font-galmap=%s\n", galmapFontName);
184 fl.fwritef("text-size=%s\n", fsizeText);
185 fl.fwritef("ui-text-size=%s\n", fsizeUI);
186 fl.fwritef("galmap-text-size=%s\n", fGalMapSize);
187 fl.fwritef("scrollbar-on-left=%s\n", sbLeft);
188 fl.fwritef("interference=%s\n", interAllowed);
189 fl.fwritef("color-dim=0x%08x\n", colorDim);
190 fl.fwritef("color-back=0x%08x\n", colorBack);
191 fl.fwritef("color-text=0x%08x\n", colorText);
192 fl.fwritef("color-text-hi=0x%08x\n", colorTextHi);
193 fl.fwritef("nano-aa=%s\n", flagNanoAA);
194 fl.fwritef("nano-ss=%s\n", flagNanoSS);
195 fl.fwritef("justify-text=%s\n", optJustify);
196 } catch (Exception) {}
197 return;
199 xiniParse(fl,
200 "font-text", &textFontName,
201 "font-text-italic", &textiFontName,
202 "font-text-bold", &textbFontName,
203 "font-text-bold-italic", &textzFontName,
204 "font-text-italic-bold", &textzFontName,
205 "font-mono", &monoFontName,
206 "font-mono-italic", &monoiFontName,
207 "font-mono-bold", &monobFontName,
208 "font-mono-bold-italic", &monozFontName,
209 "font-mono-italic-bold", &monozFontName,
210 "font-ui", &uiFontName,
211 "font-galmap", &galmapFontName,
212 "width", &GWidth,
213 "height", &GHeight,
214 "text-size", &fsizeText,
215 "ui-text-size", &fsizeUI,
216 "galmap-text-size", &fGalMapSize,
217 "scrollbar-on-left", &sbLeft,
218 "interference", &interAllowed,
219 "color-dim", &colorDim,
220 "color-back", &colorBack,
221 "color-text", &colorText,
222 "color-text-hi", &colorTextHi,
223 "nano-aa", &flagNanoAA,
224 "nano-ss", &flagNanoSS,
225 "justify-text", &optJustify,
230 // ////////////////////////////////////////////////////////////////////////// //
231 bool isComment (const(char)[] s) {
232 while (s.length && s.ptr[0] <= ' ') s = s[1..$];
233 return (s.length > 0 && s.ptr[0] == '#');