File indexing completed on 2024-04-21 04:02:00
0001 /* 0002 This file is part of the KDE project "KAtomic" 0003 0004 SPDX-FileCopyrightText: 2006-2009 Dmitry Suzdalev <dimsuz@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KATOMIC_LEVELSET_H 0010 #define KATOMIC_LEVELSET_H 0011 0012 #include "commondefs.h" 0013 0014 #include <KSharedConfig> 0015 0016 #include <QString> 0017 #include <QList> 0018 0019 class Molecule; 0020 0021 /** 0022 * Class that represents a KAtomic level 0023 */ 0024 class LevelData 0025 { 0026 public: 0027 ~LevelData(); 0028 0029 struct Element 0030 { 0031 int atom; // == -1 for walls 0032 int x; 0033 int y; 0034 0035 Element() : atom(-1), x(-1), y(-1) {} 0036 }; 0037 0038 QList<Element> atomElements() const; 0039 0040 bool containsWallAt(int x, int y) const; 0041 0042 /** 0043 * A pointer to molecule object that is the target of this level 0044 */ 0045 const Molecule* molecule() const; 0046 0047 private: 0048 friend class LevelSet; 0049 0050 // @param elements contain atoms and walls. for walls 'atom' field will be -1 0051 // @param molecule - molecule to be solved. LevelData takes ownership of this object and will 0052 // delete it 0053 LevelData(const QList<Element>& elements, const Molecule* mol); 0054 LevelData(const LevelData&); 0055 0056 QList<Element> m_atoms; 0057 bool m_field[FIELD_SIZE][FIELD_SIZE]; 0058 0059 const Molecule* m_molecule; 0060 }; 0061 0062 /** 0063 * Represents a set of levels. Implements loading of level set given its name 0064 */ 0065 class LevelSet 0066 { 0067 public: 0068 LevelSet(); 0069 ~LevelSet(); 0070 0071 bool load(const QString& levelSetName); 0072 bool loadFromFile(const QString& fileName); 0073 0074 const LevelData* levelData(int levelNum) const; 0075 0076 /** 0077 * Returns name of the levelset. In general this name shouldn't be used in gui. 0078 * To get the name suitable to showing in gui @see visibleName 0079 */ 0080 QString name() const; 0081 0082 /** 0083 * @return name of the levelset which is suitable for showing in gui 0084 */ 0085 QString visibleName() const; 0086 0087 /** 0088 * @return name of the author of the levelset 0089 */ 0090 QString author() const; 0091 0092 /** 0093 * @return email of the author of the levelset 0094 */ 0095 QString authorEmail() const; 0096 0097 /** 0098 * @return description of the levelset 0099 */ 0100 QString description() const; 0101 0102 /** 0103 * @return number of levels in this levelset 0104 */ 0105 int levelCount() const; 0106 0107 /** 0108 * Checks if default level set is installed on disk 0109 */ 0110 static bool isDefaultLevelsAvailable(); 0111 0112 private: 0113 void reset(); 0114 const LevelData* readLevel(int levelNum) const; 0115 const Molecule* readLevelMolecule(int levelNum) const; 0116 0117 private: 0118 KSharedConfigPtr m_levelsFile; 0119 mutable QHash<int, LevelData*> m_levelCache; 0120 0121 QString m_name; 0122 QString m_visibleName; 0123 QString m_description; 0124 QString m_author; 0125 QString m_authorEmail; 0126 int m_levelCount; 0127 }; 0128 0129 #endif