3 // TODO: use QSettings?
5 LevelPack::LevelPack(const QString &fileName):file(fileName)
7 file.open(QIODevice::ReadOnly|QIODevice::Text);
8 lookSection("[General]");
10 props["title"]=f.baseName();
11 while(loadPackProperty()){};
12 while(file.canReadLine()){loadLevel();};
14 LevelPack::~LevelPack()
16 while(!levels.isEmpty())
17 delete levels.takeFirst();
19 QString LevelPack::getLine()
24 QString lineR(file.readLine());
29 empty &=lineR.at(i++).isSpace();
30 empty |= lineR.startsWith(';');
32 printf("Error %d\n",file.error());
34 } while(empty && (file.error()==0) && !file.atEnd());
37 bool LevelPack::lookSection(const char *section)
39 QString line(getLine());
42 QPair<QString,QString> *LevelPack::loadProperty()
44 QString propLine=getLine();
45 if(propLine.startsWith("[") || !propLine.contains('='))
49 return new QPair<QString,QString>(propLine.section('=',0,0),propLine.section('=',1,1).trimmed());
51 bool LevelPack::loadPackProperty()
53 QPair<QString,QString> *pair=loadProperty();
56 props[pair->first]=pair->second;
62 void LevelPack::loadLevel()
64 QMap<QString,QString> levelInfo;
65 while(QPair<QString,QString> *prop=loadProperty())
67 levelInfo[prop->first]=prop->second;
70 QString title(levelInfo["title"]);
71 QString board(levelInfo["board"]);
72 QString sol(levelInfo["solution"]);
73 PlayField *level=new PlayField(title,board,sol);