[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src stat_manager.cxx,NONE,1.1 stat_manage
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src stat_manager.cxx,NONE,1.1 stat_manager.hxx,NONE,1.1 Makefile.am,1.140,1.141 menu_button.cxx,1.5,1.6 pingus_main.cxx,1.53,1.54 pingus_main.hxx,1.7,1.8 story_screen.cxx,1.6,1.7 |
Date: |
28 Mar 2003 13:06:57 -0000 |
Update of /var/lib/cvs/Games/Pingus/src
In directory dark:/tmp/cvs-serv32086
Modified Files:
Makefile.am menu_button.cxx pingus_main.cxx pingus_main.hxx
story_screen.cxx
Added Files:
stat_manager.cxx stat_manager.hxx
Log Message:
added statmanager to keep track of simple name/value pairs
--- NEW FILE: stat_manager.cxx ---
// $Id: stat_manager.cxx,v 1.1 2003/03/28 13:06:55 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <iostream>
#include <fstream>
#include "string_converter.hxx"
#include "xml_helper.hxx"
#include "system.hxx"
#include "stat_manager.hxx"
StatManager* StatManager::instance_ = 0;
StatManager*
StatManager::instance()
{
if (instance_)
return instance_;
else
return (instance_ = new StatManager(System::get_statdir() +
"stat/stats.xml"));
}
void
StatManager::init()
{
StatManager::instance();
}
void
StatManager::deinit()
{
instance()->flush();
delete instance_;
instance_ = 0;
}
StatManager::StatManager(const std::string& arg_filename)
: statfilename(arg_filename)
{
load(statfilename);
}
StatManager::~StatManager()
{
}
void
StatManager::load(const std::string& filename)
{
xmlDocPtr doc = xmlParseFile(filename.c_str());
if (doc)
{
xmlNodePtr cur = doc->ROOT;
cur = XMLhelper::skip_blank(cur);
if (cur && XMLhelper::equal_str(cur->name, "pingus-stats"))
{
cur = XMLhelper::skip_blank(cur);
cur = cur->children;
cur = XMLhelper::skip_blank(cur);
while(cur)
{
std::string name = (const char*)(cur->name);
std::string value = XMLhelper::parse_string(doc, cur);
std::cout << "Stat: " << name << " = " << value << std::endl;
stats[name] = value;
cur = cur->next;
}
}
else
{
std::cout << "StatManager: stat file '" << filename
<< "' is corrupt or invalid, assuming an empty one." <<
std::endl;
}
xmlFreeDoc(doc);
}
}
void
StatManager::flush()
{
save(statfilename);
}
void
StatManager::save(const std::string& filename)
{
std::ofstream xml(filename.c_str());
xml << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n"
<< "<pingus-stats>\n";
for (Table::iterator i = stats.begin(); i != stats.end(); ++i)
{
xml << " <" << i->first << ">" << i->second << "/<" << i->first << ">"
<< std::endl;
}
xml << "</pingus-stats>\n";
}
bool
StatManager::get_int(const std::string& name, int& value)
{
std::string str;
if (get_string(name, str))
return from_string(str, value);
else
return false;
}
bool
StatManager::get_bool(const std::string& name, bool& value)
{
std::string str;
if (get_string(name, str))
return from_string(str, value);
else
return false;
}
bool
StatManager::get_string(const std::string& name, std::string& value)
{
Table::iterator i = stats.find(name);
if (i == stats.end())
{
return false;
}
else
{
value = i->second;
return true;
}
}
void
StatManager::set_string(const std::string& name, const std::string& value)
{
stats[name] = value;
}
void
StatManager::set_int(const std::string& name, int value)
{
stats[name] = to_string(value);
}
void
StatManager::set_bool(const std::string& name, bool value)
{
stats[name] = to_string(value);
}
/* EOF */
--- NEW FILE: stat_manager.hxx ---
// $Id: stat_manager.hxx,v 1.1 2003/03/28 13:06:55 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PINGUS_STAT_MANAGER_HXX
#define HEADER_PINGUS_STAT_MANAGER_HXX
#include <map>
#include <string>
/** */
class StatManager
{
private:
static StatManager* instance_;
/** File from which it loads/saves the stats */
std::string statfilename;
typedef std::map<std::string, std::string> Table;
Table stats;
public:
static StatManager* instance();
static void init();
static void deinit();
StatManager(const std::string& filename);
~StatManager();
bool get_int (const std::string&, int& value);
bool get_bool (const std::string&, bool& value);
bool get_string(const std::string&, std::string& vlaue);
void set_string(const std::string& name, const std::string& value);
void set_int (const std::string& name, int value);
void set_bool (const std::string& name, bool value);
/** Write the current status down */
void flush();
void load(const std::string& filename);
void save(const std::string& filename);
private:
StatManager (const StatManager&);
StatManager& operator= (const StatManager&);
};
#endif
/* EOF */
Index: Makefile.am
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/Makefile.am,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -d -r1.140 -r1.141
--- Makefile.am 26 Mar 2003 12:01:17 -0000 1.140
+++ Makefile.am 28 Mar 2003 13:06:55 -0000 1.141
@@ -262,6 +262,8 @@
sprite.hxx \
start_screen.hxx \
start_screen.cxx \
+stat_manager.hxx \
+stat_manager.cxx \
story_screen.hxx \
story_screen.cxx \
string_converter.cxx \
Index: menu_button.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/menu_button.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- menu_button.cxx 28 Mar 2003 12:06:32 -0000 1.5
+++ menu_button.cxx 28 Mar 2003 13:06:55 -0000 1.6
@@ -32,6 +32,7 @@
#include "worldmap/manager.hxx"
#include "story_screen.hxx"
#include "my_gettext.hxx"
+#include "stat_manager.hxx"
using EditorNS::Editor;
@@ -361,10 +362,18 @@
StoryButton::on_click ()
{
PingusSound::play_sound ("letsgo");
- if (1 /* story_seen */)
- ScreenManager::instance()->push_screen(new StoryScreen(), true);
+
+ bool story_seen = false;
+ StatManager::instance()->get_bool("story-seen", story_seen);
+
+ if (!story_seen)
+ {
+ ScreenManager::instance()->push_screen(new StoryScreen(), true);
+ }
else
-
ScreenManager::instance()->push_screen(WorldMapNS::WorldMapManager::instance
());
+ {
+
ScreenManager::instance()->push_screen(WorldMapNS::WorldMapManager::instance
());
+ }
}
ThemeButton::ThemeButton (PingusMenu* menu_)
Index: pingus_main.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/pingus_main.cxx,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- pingus_main.cxx 28 Mar 2003 12:06:32 -0000 1.53
+++ pingus_main.cxx 28 Mar 2003 13:06:55 -0000 1.54
@@ -74,6 +74,7 @@
#include "story_screen.hxx"
#include "start_screen.hxx"
#include "savegame_manager.hxx"
+#include "stat_manager.hxx"
#include "demo_session.hxx"
#include "debug.hxx"
#include "editor/editor.hxx"
@@ -888,7 +889,10 @@
pout.add (console);
perr.add (std::cout);
perr.add (console);
-
+
+ SavegameManager::instance();
+ StatManager::init();
+
ScreenManager::init();
PingusSound::init();
PingusResource::init();
@@ -901,8 +905,6 @@
fps_counter.init();
console.init();
- SavegameManager::instance();
-
// FIXME: See action_data.hxx, a bit ugly
init_default_actions();
}
@@ -918,6 +920,7 @@
PingusResource::deinit();
PingusSound::deinit();
ScreenManager::deinit();
+ StatManager::deinit();
}
/* EOF */
Index: pingus_main.hxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/pingus_main.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pingus_main.hxx 18 Feb 2003 15:04:47 -0000 1.7
+++ pingus_main.hxx 28 Mar 2003 13:06:55 -0000 1.8
@@ -74,6 +74,3 @@
#endif
/* EOF */
-
-
-
Index: story_screen.cxx
===================================================================
RCS file: /var/lib/cvs/Games/Pingus/src/story_screen.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- story_screen.cxx 28 Mar 2003 12:06:32 -0000 1.6
+++ story_screen.cxx 28 Mar 2003 13:06:55 -0000 1.7
@@ -30,6 +30,7 @@
#include "story_screen.hxx"
#include "res_descriptor.hxx"
#include "worldmap/manager.hxx"
+#include "stat_manager.hxx"
#include "sound/sound.hxx"
class StoryPage
@@ -206,6 +207,7 @@
else
{
std::cout << "StoryScreenComponent: Out of story pages" << std::endl;
+ StatManager::instance()->set_bool("story-seen", true);
//ScreenManager::instance()->replace_screen
(PingusMenuManager::instance (), false);
ScreenManager::instance()->replace_screen(WorldMapNS::WorldMapManager::instance
());
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src stat_manager.cxx,NONE,1.1 stat_manager.hxx,NONE,1.1 Makefile.am,1.140,1.141 menu_button.cxx,1.5,1.6 pingus_main.cxx,1.53,1.54 pingus_main.hxx,1.7,1.8 story_screen.cxx,1.6,1.7,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/gui screen_manager.cxx,1.3,1.4
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/data/levels/tutorial basher-tutorial-grumbel.xml,1.1,1.2bomber-tutorial2-grumbel.xml,1.1,1.2 miner-tutorial2-grumbel.xml,1.1,1.2 snow11-grumbel.xml,1.1,1.2 snow12-grumbel.xml,1.1,1.2 snow14-grumbel.xml,1.1,1.2 snow15-grumbel.xml,1.1,1.2 snow16-grumbel.xml,1.2,1.3 snow19-grumbel.xml,1.2,1.3 snow21-grumbel.xml,1.1,1.2 snow8-grumbel.xml,1.1,1.2
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/gui screen_manager.cxx,1.3,1.4
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/data/levels/tutorial basher-tutorial-grumbel.xml,1.1,1.2bomber-tutorial2-grumbel.xml,1.1,1.2 miner-tutorial2-grumbel.xml,1.1,1.2 snow11-grumbel.xml,1.1,1.2 snow12-grumbel.xml,1.1,1.2 snow14-grumbel.xml,1.1,1.2 snow15-grumbel.xml,1.1,1.2 snow16-grumbel.xml,1.2,1.3 snow19-grumbel.xml,1.2,1.3 snow21-grumbel.xml,1.1,1.2 snow8-grumbel.xml,1.1,1.2
- Index(es):