1 /***************************************************************************
2 * copyright : (C) 2004-2007 by Gael de Chalendar
3 * email : kleag@free.fr
4 ***************************************************************************/
5
6 /***************************************************************************
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either either version 2
11 of the License, or (at your option) any later version.of the License, or *
12 * (at your option) any later version. *
13 * *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
18 ***************************************************************************/
19
20 #include "skinSpritesData.h"
21
22 #include <QTextStream>
23
24 #include <KLocalizedString>
25 #include <KMessageBox>
26
27 namespace Ksirk{
28 namespace Sprites {
29
30
31
32 SkinSpritesData* SkinSpritesData::m_singleton = 0;
33
SkinSpritesData()34 SkinSpritesData::SkinSpritesData()
35 {
36 }
37
~SkinSpritesData()38 SkinSpritesData::~SkinSpritesData()
39 {
40 delete m_singleton;
41 m_singleton = 0;
42 }
43
single()44 const SkinSpritesData& SkinSpritesData::single()
45 {
46 if (m_singleton == 0)
47 {
48 m_singleton = new SkinSpritesData();
49 m_singleton->init();
50 }
51 return *m_singleton;
52 }
53
changeable()54 SkinSpritesData& SkinSpritesData::changeable()
55 {
56 if (m_singleton == 0)
57 {
58 m_singleton = new SkinSpritesData();
59 m_singleton->init();
60 }
61 return *m_singleton;
62 }
63
64 /** setup default values for default skin sprites */
init()65 void SkinSpritesData::init()
66 {
67 m_intDatas.clear();
68 m_strDatas.clear();
69 }
70
71
skin() const72 const QString& SkinSpritesData::skin() const
73 {
74 return m_skin;
75 }
76
skin(const QString & newSkin)77 void SkinSpritesData::skin(const QString& newSkin)
78 {
79 m_skin = newSkin;
80 }
81
intData(const QString & name) const82 int SkinSpritesData::intData(const QString& name) const
83 {
84 QMap<QString, int>::const_iterator it = m_intDatas.find(name);
85 if (it == m_intDatas.end())
86 {
87 QString msg;
88 QTextStream(&msg) << i18n("Error - Unknown skin int data: ") << name;
89 KMessageBox::error(0, msg, i18n("Fatal Error"));
90 exit(1);
91 }
92 else
93 {
94 return *it;
95 }
96 }
97
strData(const QString & name) const98 const QString& SkinSpritesData::strData(const QString& name) const
99 {
100 QMap<QString, QString>::const_iterator it = m_strDatas.find(name);
101 if (it == m_strDatas.end())
102 {
103 QString msg;
104 QTextStream(&msg) << i18n("Error - Unknown skin string data: ") << name;
105 KMessageBox::error(0, msg, i18n("Fatal Error"));
106 exit(1);
107 }
108 else
109 {
110 return *it;
111 }
112 }
113
strData(const QString & name,const QString & data)114 void SkinSpritesData::strData(const QString& name, const QString& data)
115 {
116 m_strDatas[name] = data;
117 }
118
intData(const QString & name,int data)119 void SkinSpritesData::intData(const QString& name, int data)
120 {
121 m_intDatas[name] = data;
122 }
123
124
125 } // closing namespace GameLogic
126 } // closing namespace Ksirk
127