17 from __future__
import print_function
18 from os
import listdir, stat, walk
19 from os.path
import isfile, join, splitext
23 def __init__(self,directory,subdir,fileName,mode):
27 filePath = join(directory,subdir,fileName)
33 if isinstance(byte,int):
36 return format(ord(byte),
'02x')
40 print(
"static const unsigned char %s_data[] = " % self.
bareName,file=outputFile)
41 print(
"{",file=outputFile)
42 lines = [data[x:x+bytes_per_line]
for x
in range(0,len(data),bytes_per_line)]
43 linesAsString =
',\n '.join([
', '.join([
'0x'+self.
formatByte(byte)
for byte
in line])
for line
in lines])
44 print(
' %s' % linesAsString,file=outputFile)
45 print(
"};",file=outputFile)
46 print(
"const int %s_len = %d;\n" % (self.
bareName,len(data)),file=outputFile)
49 lines = [x
for x
in self.inputFile.readlines()
if not x.startswith(
'#')]
50 w,h = (
int(x)
for x
in lines[0].
split())
51 data =
"".join(map(chr,[
int(w>>8),
int(w&0xFF),
int(h>>8),
int(h&0xFF)]+
52 [
int(x)
for line
in lines[1:]
for x
in line.split()]))
57 ext = splitext(fname)[1]
58 if ext==
'.lum':
return LumFile(directory,subdir,fname)
59 if ext==
'.luma':
return LumaFile(directory,subdir,fname)
60 if ext==
'.css':
return CSSFile(directory,subdir,fname)
65 File.__init__(self,directory,subdir,fileName,
"rb")
67 self.
writeBytes(self.inputFile.read(),outputFile)
73 File.__init__(self,directory,subdir,fileName,
"r") 75 self.
writeBytes(self.inputFile.read(),outputFile)
81 File.__init__(self,directory,subdir,fileName,
"r") 89 File.__init__(self,directory,subdir,fileName,
"r") 97 sys.exit(
'Usage: %s directory output_file.cpp' % sys.argv[0])
98 directory = sys.argv[1]
100 for dirName, subdirList, fileList
in walk(directory):
101 for fname
in sorted(fileList):
102 subdir = dirName[len(directory)+1:]
if dirName.startswith(directory)
else dirName
104 files.append(File.factory(directory,subdir,fname))
105 outputFile =
open(sys.argv[2],
"w")
106 print(
"#include \"resourcemgr.h\"\n",file=outputFile)
108 f.writeContents(outputFile)
109 print(
"static Resource resourceDir[] =",file=outputFile)
110 print(
"{",file=outputFile)
112 f.writeDirEntry(outputFile)
113 print(
"};",file=outputFile)
114 print(
"static int resourceDir_len = %s;" % len(files), file=outputFile)
115 print(
"void initResources() { ResourceMgr::instance().registerResources(resourceDir,resourceDir_len); }",file=outputFile)
117 if __name__ ==
'__main__':
def writeContents(self, outputFile)
def formatByte(self, byte)
def __init__(self, directory, subdir, fileName)
def __init__(self, directory, subdir, fileName)
def writeDirEntry(self, outputFile)
def writeBytes(self, data, outputFile)
int open(const char *, int)
Opens a file descriptor.
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
def writeDirEntry(self, outputFile)
def convertToBytes(self, outputFile)
def factory(directory, subdir, fname)
def __init__(self, directory, subdir, fileName, mode)
def walk(top, topdown=True)
def writeContents(self, outputFile)
def writeContents(self, outputFile)
void split(std::string const &s, char c, OutIter dest)
def __init__(self, directory, subdir, fileName)
def writeDirEntry(self, outputFile)
def writeContents(self, outputFile)
def writeDirEntry(self, outputFile)
def __init__(self, directory, subdir, fileName)