1 /*
2  * Kuklomenos
3  * Copyright (C) 2008-2009 Martin Bays <mbays@sdf.lonestar.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/.
17  */
18 
19 #include <iostream>
20 #include <fstream>
21 #include <string>
22 using namespace std;
23 
24 #include <SDL_gfxPrimitivesDirty.h>
25 
26 #include "data.h"
27 
28 char fontSmall[3328];
29 char fontBig[10240];
30 
31 #ifndef DATADIR
32 const int numDataPaths = 4;
33 const string dataPaths[numDataPaths] = { "./", "/usr/share/kuklomenos/",
34     "/usr/local/share/kuklomenos/", "/usr/share/games/kuklomenos/"};
35 #else
36 const int numDataPaths = 5;
37 const string dataPaths[numDataPaths] = { DATADIR "/kuklomenos/",
38     "./", "/usr/share/kuklomenos/", "/usr/local/share/kuklomenos/",
39     "/usr/share/games/kuklomenos/"};
40 #endif
41 
openDataFile(string relPath)42 ifstream* openDataFile(string relPath)
43 {
44     ifstream* f = new ifstream;
45     for (int i=0; i < numDataPaths; i++)
46     {
47 	f->open((dataPaths[i]+relPath).c_str(), ios::binary);
48 	if (f->is_open())
49 	    return f;
50 	else
51 	    continue;
52     }
53     return f;
54 }
55 
findDataPath(string relPath)56 const string findDataPath(string relPath)
57 {
58     ifstream f;
59     for (int i=0; i < numDataPaths; i++)
60     {
61 	const string absPath = dataPaths[i] + relPath;
62 	f.open(absPath.c_str(), ios::binary);
63 	if (f.is_open())
64 	{
65 	    f.close();
66 	    return absPath;
67 	}
68 	else
69 	    continue;
70     }
71     return "";
72 }
73 
initFont()74 bool initFont()
75 {
76     ifstream* f = openDataFile("fonts/7x13.fnt");
77     ifstream* f2 = openDataFile("fonts/10x20.fnt");
78 
79     if (!f->is_open())
80 	return false;
81 
82     f->read(fontSmall, 3328);
83     f2->read(fontBig, 10240);
84 
85     delete f;
86     delete f2;
87 
88     return true;
89 }
90