[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2782 - in branches/pingus_sdl/src: . editor
From: |
jave27 |
Subject: |
[Pingus-CVS] r2782 - in branches/pingus_sdl/src: . editor |
Date: |
Sat, 4 Aug 2007 01:49:56 +0200 |
Author: jave27
Date: 2007-08-04 01:49:47 +0200 (Sat, 04 Aug 2007)
New Revision: 2782
Added:
branches/pingus_sdl/src/editor/editor_level.cpp
branches/pingus_sdl/src/editor/editor_level.hpp
Removed:
branches/pingus_sdl/src/editor/xml_level.cpp
branches/pingus_sdl/src/editor/xml_level.hpp
Modified:
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/editor/editor_screen.cpp
branches/pingus_sdl/src/editor/editor_screen.hpp
branches/pingus_sdl/src/editor/editor_viewport.cpp
branches/pingus_sdl/src/editor/level_head.cpp
branches/pingus_sdl/src/editor/level_objs.cpp
branches/pingus_sdl/src/editor/level_objs.hpp
branches/pingus_sdl/src/editor/panel_buttons.cpp
Log:
- Rename XMLLevel to EditorLevel and get rid of references to XML
FileReader/Writer.
- Move the EditorViewport's z-position up so the level objects are actually
visible.
Now, we just need a SExprFileWriter class, and the save() functionality can be
enabled.
Plenty of GUI functionality still needs improvment, too (piece selection, etc.).
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-08-03 22:43:55 UTC (rev 2781)
+++ branches/pingus_sdl/src/SConscript 2007-08-03 23:49:47 UTC (rev 2782)
@@ -118,13 +118,13 @@
'display/scene_context.cpp',
'editor/context_menu.cpp',
+'editor/editor_level.cpp',
'editor/editor_panel.cpp',
'editor/editor_screen.cpp',
'editor/editor_viewport.cpp',
'editor/level_head.cpp',
'editor/level_objs.cpp',
'editor/panel_buttons.cpp',
-'editor/xml_level.cpp',
'command_line.cpp',
'command_line_generic.cpp',
Added: branches/pingus_sdl/src/editor/editor_level.cpp
===================================================================
--- branches/pingus_sdl/src/editor/editor_level.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/editor_level.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -0,0 +1,254 @@
+// $Id: editor_level.cxx,v 1.00 2007/08/03 23:41:12 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2007 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 <string>
+#include <fstream>
+#include "editor_level.hpp"
+#include "level_impl.hpp"
+#include "level_objs.hpp"
+#include "../pingus_level.hpp"
+
+
+namespace Editor {
+
+// Default constructor
+EditorLevel::EditorLevel() :
+ impl(new LevelImpl())
+{
+
+}
+
+// Default Destructor
+EditorLevel::~EditorLevel()
+{
+ if (impl)
+ delete impl;
+}
+
+/** Verify that level is valid:
+ Level should contain the following attributes in order to be "valid":
+ -----------
+ LevelObj's:
+ - At least 1 entrance
+ - At least 1 exit
+ - At least 1 surface-background
+ - Each object should be within valid ranges (pos Vector3f should be inside
the world)
+ -----------
+ Head section:
+ - Everything should be filled in and within valid ranges
+ */
+bool EditorLevel::is_valid()
+{
+ std::cout << "EditorLevel::is_valid() - Not yet implemented" <<
std::endl;
+ if (impl)
+ return true;
+ else
+ return false;
+}
+
+// Save the level to a file. Returns true if successful
+bool EditorLevel::save_level(const std::string& filename)
+{
+#if 0
+ // Make sure level is valid
+ if (!is_valid())
+ return false;
+
+ // Create new file (overwrite existing file)
+ std::ofstream out_file(filename.c_str());
+ FileWriter fw(out_file);
+
+ // Write header
+ fw.begin_section("pingus-level");
+ fw.write_int("version", 2);
+ fw.begin_section("head");
+ fw.write_string("levelname", impl->levelname);
+ fw.write_string("description", impl->description);
+ fw.write_string("author", impl->author);
+ fw.write_int("number-of-pingus", impl->number_of_pingus);
+ fw.write_int("number-to-save", impl->number_to_save);
+ fw.write_int("time", impl->time);
+ fw.write_int("difficulty", impl->difficulty);
+ // FIXME: Allow user to decide if level is playable or not
+ fw.write_int("playable", 1);
+ fw.write_string("comment", impl->comment);
+ fw.write_string("music", impl->music);
+
+ // Write the list of actions to the file
+ fw.begin_section("actions");
+ for (std::map<std::string, int>::const_iterator i =
impl->actions.begin();
+ i != impl->actions.end(); i++)
+ {
+ fw.write_int(i->first.c_str(), i->second);
+ }
+ fw.end_section(); // actions
+
+ fw.begin_section("levelsize");
+ fw.write_int("width", impl->size.width);
+ fw.write_int("height", impl->size.height);
+ fw.end_section(); // levelsize
+ fw.end_section(); // head
+
+ // Write the objects
+ fw.begin_section("objects");
+ for (unsigned i = 0; i < impl->objects.size(); i++)
+ impl->objects[i]->write_properties(fw);
+ fw.end_section(); // objects
+
+ fw.end_section(); // pingus-level
+
+ // Clean up
+ out_file.close();
+#endif
+ return true;
+}
+
+// Load an existing level from a file
+void EditorLevel::load_level(const std::string& filename)
+{
+ if (impl)
+ delete impl;
+ impl = new LevelImpl();
+
+ // Load the level from the file - we don't care what it's res_name is.
+ PingusLevel existing_level("", filename);
+
+ // Assign all of the level information to our LevelImpl
+ impl->levelname = existing_level.get_levelname();
+ impl->description = existing_level.get_description();
+ impl->ambient_light = existing_level.get_ambient_light();
+ impl->size = existing_level.get_size();
+ impl->number_of_pingus = existing_level.get_number_of_pingus();
+ impl->number_to_save = existing_level.get_number_to_save();
+ impl->actions = existing_level.get_actions();
+ impl->time = existing_level.get_time();
+ impl->difficulty = existing_level.get_difficulty();
+ impl->author = existing_level.get_author();
+ impl->music = existing_level.get_music();
+
+ // Temporary objects
+ unsigned attribs;
+ Vector3f p;
+ Color tmp_color;
+ ResDescriptor desc;
+ std::string tmp_str;
+ int tmp_int;
+ float tmp_float;
+ bool tmp_bool;
+
+ // Get the objects
+ std::vector<FileReader> objs = existing_level.get_objects();
+ for (std::vector<FileReader>::const_iterator i = objs.begin(); i !=
objs.end(); i++)
+ {
+ // Create new object
+ LevelObj* obj = new LevelObj(i->get_name(), impl);
+ attribs = obj->get_attribs();
+
+ // All objects have a position - get that.
+ i->read_vector("position", p);
+ obj->set_orig_pos(p);
+ obj->set_pos(p);
+
+ // Get optional attributes based on the attribs value
+ if (attribs & HAS_SURFACE)
+ {
+ i->read_desc("surface", desc);
+ obj->set_res_desc(desc);
+ }
+ if (attribs & HAS_TYPE)
+ {
+ i->read_string("type", tmp_str);
+ obj->set_type(tmp_str);
+ }
+ if (attribs & HAS_SPEED)
+ {
+ i->read_int("speed", tmp_int);
+ obj->set_speed(tmp_int);
+ }
+ if (attribs & HAS_WIDTH)
+ {
+ i->read_int("width", tmp_int);
+ obj->set_width(tmp_int);
+ }
+ if (attribs & HAS_PARALLAX)
+ {
+ i->read_float("parallax", tmp_float);
+ obj->set_parallax(tmp_float);
+ }
+ if (attribs & HAS_OWNER)
+ {
+ i->read_int("owner-id", tmp_int);
+ obj->set_owner(tmp_int);
+ }
+ if (attribs & HAS_DIRECTION)
+ {
+ i->read_string("direction", tmp_str);
+ obj->set_direction(tmp_str);
+ }
+ if (attribs & HAS_COLOR)
+ {
+ i->read_color("color", tmp_color);
+ obj->set_color(tmp_color);
+ }
+ if (attribs & HAS_SCROLL)
+ {
+ i->read_float("scroll-x", tmp_float);
+ obj->set_scroll_x(tmp_float);
+ i->read_float("scroll-y", tmp_float);
+ obj->set_scroll_y(tmp_float);
+ }
+ if (attribs & HAS_STRETCH)
+ {
+ i->read_bool("stretch-x", tmp_bool);
+ obj->set_stretch_x(tmp_bool);
+ i->read_bool("stretch-y", tmp_bool);
+ obj->set_stretch_y(tmp_bool);
+ i->read_bool("keep-aspect", tmp_bool);
+ obj->set_aspect(tmp_bool);
+ }
+ if (attribs & HAS_PARA)
+ {
+ i->read_float("para-x", tmp_float);
+ obj->set_para_x(tmp_float);
+ i->read_float("para-y", tmp_float);
+ obj->set_para_y(tmp_float);
+ }
+ if (attribs & HAS_RELEASE_RATE)
+ {
+ i->read_int("release-rate", tmp_int);
+ obj->set_release_rate(tmp_int);
+ }
+
+ impl->objects.push_back((LevelObj*)obj);
+ }
+
+ // Sort by Z coordinate
+ impl->sort_objs();
+}
+
+void
+EditorLevel::add_object(LevelObj* obj)
+{
+ impl->objects.push_back(obj);
+}
+
+} // Editor namespace
+
+/* EOF */
Added: branches/pingus_sdl/src/editor/editor_level.hpp
===================================================================
--- branches/pingus_sdl/src/editor/editor_level.hpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/editor_level.hpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -0,0 +1,72 @@
+// $Id: editor_level.hxx,v 1.00 2005/11/11 23:41:12 Jave27 Exp $
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2005 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_EDITOR_EDITORLEVEL_HXX
+#define HEADER_PINGUS_EDITOR_EDITORLEVEL_HXX
+
+#include <vector>
+#include "level_impl.hpp"
+
+
+namespace Editor {
+
+ class LevelObj;
+
+class EditorLevel
+{
+private:
+ LevelImpl* impl;
+
+public:
+
+ /** Construct new blank level */
+ EditorLevel();
+
+ /** Destructor */
+ ~EditorLevel();
+
+ /** Verify that level is valid */
+ bool is_valid();
+
+ /** Save the level to a file. Returns true if successful */
+ bool save_level(const std::string& filename);
+
+ /** Load an existing level from a file */
+ void load_level(const std::string& filename);
+
+ /** Return all objects in the level */
+ std::vector<LevelObj*> get_objects() const { return impl->objects; }
+
+ /** Add an object to the level */
+ void add_object(LevelObj* obj);
+
+ /** Return LevelImpl */
+ LevelImpl* get_level_impl() { return impl; }
+
+
+private:
+ EditorLevel (const EditorLevel&);
+ EditorLevel& operator= (const EditorLevel&);
+}; // EditorLevel class
+
+} // Editor namespace
+
+#endif
+
+/* EOF */
Modified: branches/pingus_sdl/src/editor/editor_screen.cpp
===================================================================
--- branches/pingus_sdl/src/editor/editor_screen.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/editor_screen.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -29,24 +29,24 @@
#include "../fonts.hpp"
#include "../file_dialog.hpp"
#include "../path_manager.hpp"
+#include "editor_level.hpp"
+#include "editor_panel.hpp"
#include "editor_screen.hpp"
-#include "editor_panel.hpp"
#include "editor_viewport.hpp"
-#include "xml_level.hpp"
#include "level_objs.hpp"
namespace Editor {
// Default constructor
-EditorScreen::EditorScreen(XMLLevel* level)
+EditorScreen::EditorScreen(EditorLevel* level)
: plf(level),
panel(0),
viewport(0),
filedialog(0),
close_dialog(false)
{
- if (!plf) plf = new XMLLevel();
+ if (!plf) plf = new EditorLevel();
}
// Destructor
Modified: branches/pingus_sdl/src/editor/editor_screen.hpp
===================================================================
--- branches/pingus_sdl/src/editor/editor_screen.hpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/editor_screen.hpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -30,7 +30,7 @@
namespace Editor {
-class XMLLevel;
+class EditorLevel;
class LevelObj;
class EditorPanel;
class EditorViewport;
@@ -41,7 +41,7 @@
{
private:
/** The level currently being edited */
- XMLLevel* plf;
+ EditorLevel* plf;
/** Panel which contains all of the buttons for each action */
EditorPanel* panel;
@@ -56,7 +56,7 @@
public:
/** Default constructor */
- EditorScreen(XMLLevel* level = 0);
+ EditorScreen(EditorLevel* level = 0);
/** Destructor */
~EditorScreen();
@@ -83,9 +83,9 @@
EditorViewport* get_viewport() const { return viewport; }
/** Return a pointer to the current level */
- XMLLevel* get_level() const { return plf; }
+ EditorLevel* get_level() const { return plf; }
- /** Add an object to both the XMLLevel and the EditorViewport */
+ /** Add an object to both the EditorLevel and the EditorViewport */
void add_object(LevelObj* obj);
void add_objects(std::vector<LevelObj*> objs);
Modified: branches/pingus_sdl/src/editor/editor_viewport.cpp
===================================================================
--- branches/pingus_sdl/src/editor/editor_viewport.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/editor_viewport.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -25,10 +25,10 @@
#include "../display/drawing_context.hpp"
#include "../math/vector3f.hpp"
#include "../graphic_context_state.hpp"
+#include "editor_level.hpp"
+#include "editor_screen.hpp"
#include "editor_viewport.hpp"
-#include "editor_screen.hpp"
#include "context_menu.hpp"
-#include "xml_level.hpp"
#include "level_objs.hpp"
namespace Editor {
@@ -207,7 +207,7 @@
Color(255,255,255,150));
state.pop(*scene_context);
- gc.draw(new SceneContextDrawingRequest(scene_context, Vector3f(0, 0,
-5000)));
+ gc.draw(new SceneContextDrawingRequest(scene_context, Vector3f(0, 0,
-150)));
}
// Returns true if the viewport is at the x,y coordinate
Modified: branches/pingus_sdl/src/editor/level_head.cpp
===================================================================
--- branches/pingus_sdl/src/editor/level_head.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/level_head.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -30,9 +30,9 @@
#include "level_impl.hpp"
#include "../gui/display.hpp"
#include "panel_buttons.hpp"
+#include "editor_level.hpp"
#include "editor_panel.hpp"
#include "editor_screen.hpp"
-#include "xml_level.hpp"
namespace Editor {
Modified: branches/pingus_sdl/src/editor/level_objs.cpp
===================================================================
--- branches/pingus_sdl/src/editor/level_objs.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/level_objs.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -26,7 +26,6 @@
#include "../res_descriptor.hpp"
#include "../gui/display.hpp"
#include "../display/drawing_context.hpp"
-#include "../xml_file_writer.hpp"
namespace Editor {
@@ -187,65 +186,65 @@
refresh_sprite();
}
-// Writes the XML attributes for the file
+// Writes the attributes for the file
void
-LevelObj::write_properties(XMLFileWriter &xml)
+LevelObj::write_properties(FileWriter &fw)
{
if (!removed)
{
- xml.begin_section(section_name.c_str());
+ fw.begin_section(section_name.c_str());
const unsigned attribs = get_attributes(section_name);
// Write information about the main sprite
if (attribs & HAS_SURFACE)
{
- xml.begin_section("surface");
- xml.write_string("image", desc.res_name);
- xml.write_string("modifier",
ResourceModifierNS::rs_to_string(desc.modifier));
- xml.end_section(); // surface
+ fw.begin_section("surface");
+ fw.write_string("image", desc.res_name);
+ fw.write_string("modifier",
ResourceModifierNS::rs_to_string(desc.modifier));
+ fw.end_section(); // surface
}
// Write the optional information
if (attribs & HAS_TYPE)
- xml.write_string("type", object_type);
+ fw.write_string("type", object_type);
if (attribs & HAS_SPEED)
- xml.write_int("speed", speed);
+ fw.write_int("speed", speed);
if (attribs & HAS_PARALLAX)
- xml.write_float("parallax", parallax);
+ fw.write_float("parallax", parallax);
if (attribs & HAS_WIDTH)
- xml.write_int("width", width);
+ fw.write_int("width", width);
if (attribs & HAS_OWNER)
- xml.write_int("owner-id", owner_id);
+ fw.write_int("owner-id", owner_id);
if (attribs & HAS_DIRECTION)
- xml.write_string("direction", direction);
+ fw.write_string("direction", direction);
if (attribs & HAS_RELEASE_RATE)
- xml.write_int("release-rate", release_rate);
+ fw.write_int("release-rate", release_rate);
if (attribs & HAS_COLOR)
- ////xml.write_color("color", color);
+ ////fw.write_color("color", color);
if (attribs & HAS_STRETCH)
{
- xml.write_bool("stretch-x", stretch_x);
- xml.write_bool("stretch-y", stretch_y);
- xml.write_bool("keep-aspect", keep_aspect);
+ fw.write_bool("stretch-x", stretch_x);
+ fw.write_bool("stretch-y", stretch_y);
+ fw.write_bool("keep-aspect", keep_aspect);
}
if (attribs & HAS_SCROLL)
{
- xml.write_float("scroll-x", scroll_x);
- xml.write_float("scroll-y", scroll_y);
+ fw.write_float("scroll-x", scroll_x);
+ fw.write_float("scroll-y", scroll_y);
}
if (attribs & HAS_PARA)
{
- xml.write_float("para-x", para_x);
- xml.write_float("para-y", para_y);
+ fw.write_float("para-x", para_x);
+ fw.write_float("para-y", para_y);
}
// Writes any extra properties that may be necessary (virtual
function)
- write_extra_properties(xml);
+ write_extra_properties(fw);
// Write the Vector3f position - all objects have this
- ////xml.write_vector("position", pos);
+ ////fw.write_vector("position", pos);
- xml.end_section(); // object's section_name
+ fw.end_section(); // object's section_name
}
}
Modified: branches/pingus_sdl/src/editor/level_objs.hpp
===================================================================
--- branches/pingus_sdl/src/editor/level_objs.hpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/level_objs.hpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -25,10 +25,10 @@
#include "../math/origin.hpp"
#include "../math/vector3f.hpp"
#include "../res_descriptor.hpp"
+#include "../file_writer.hpp"
#include <string>
- class XMLFileWriter;
class DrawingContext;
namespace Editor {
@@ -160,8 +160,8 @@
/** Loads any generic images necessary for objects with
HAS_FAKE_SURFACE */
void load_generic_surface();
- /** Write any additional properties to the XML file for this type */
- virtual void write_extra_properties(XMLFileWriter& xml) { }
+ /** Write any additional properties to the file for this type */
+ virtual void write_extra_properties(FileWriter& fw) { }
/** Sets a position vector of where the sprite is located based
on the "translation origin" specified in the sprite file. */
@@ -306,8 +306,8 @@
void select() { selected = true; }
void unselect() { selected = false; }
- /** Write basic properties to the XML file for this type */
- virtual void write_properties(XMLFileWriter &xml);
+ /** Write basic properties to the file for this type */
+ virtual void write_properties(FileWriter &fw);
/** Call when the sprite needs to be reloaded */
void refresh_sprite();
Modified: branches/pingus_sdl/src/editor/panel_buttons.cpp
===================================================================
--- branches/pingus_sdl/src/editor/panel_buttons.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/panel_buttons.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -25,11 +25,11 @@
#include "../fonts.hpp"
#include "../resource.hpp"
#include "panel_buttons.hpp"
+#include "editor_level.hpp"
+#include "editor_panel.hpp"
#include "editor_screen.hpp"
-#include "editor_panel.hpp"
#include "level_objs.hpp"
#include "level_head.hpp"
-#include "xml_level.hpp"
class Resource;
Deleted: branches/pingus_sdl/src/editor/xml_level.cpp
===================================================================
--- branches/pingus_sdl/src/editor/xml_level.cpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/xml_level.cpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -1,255 +0,0 @@
-// $Id: xml_level.cxx,v 1.00 2005/11/11 23:41:12 Jave27 Exp $
-//
-// Pingus - A free Lemmings clone
-// Copyright (C) 2005 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 <string>
-#include <fstream>
-#include "xml_level.hpp"
-#include "level_impl.hpp"
-#include "level_objs.hpp"
-#include "../xml_pingus_level.hpp"
-#include "../xml_file_writer.hpp"
-#include "../xml_file_reader.hpp"
-#include "../res_descriptor.hpp"
-
-
-namespace Editor {
-
-// Default constructor
-XMLLevel::XMLLevel() :
- impl(new LevelImpl())
-{
-
-}
-
-// Default Destructor
-XMLLevel::~XMLLevel()
-{
- if (impl)
- delete impl;
-}
-
-/** Verify that level is valid:
- Level should contain the following attributes in order to be "valid":
- -----------
- LevelObj's:
- - At least 1 entrance
- - At least 1 exit
- - At least 1 surface-background
- - Each object should be within valid ranges (pos Vector3f should be inside
the world)
- -----------
- Head section:
- - Everything should be filled in and within valid ranges
- */
-bool XMLLevel::is_valid()
-{
- std::cout << "XMLLevel::is_valid() - Not yet implemented" << std::endl;
- if (impl)
- return true;
- else
- return false;
-}
-
-// Save the level to a file. Returns true if successful
-bool XMLLevel::save_level(const std::string& filename)
-{
-#if 0
- // Make sure level is valid
- if (!is_valid())
- return false;
-
- // Create new XML file (overwrite existing file)
- std::ofstream out_file(filename.c_str());
- XMLFileWriter xml(out_file);
-
- // Write header
- xml.begin_section("pingus-level");
- xml.write_int("version", 2);
- xml.begin_section("head");
- xml.write_string("levelname", impl->levelname);
- xml.write_string("description", impl->description);
- xml.write_string("author", impl->author);
- xml.write_int("number-of-pingus", impl->number_of_pingus);
- xml.write_int("number-to-save", impl->number_to_save);
- xml.write_int("time", impl->time);
- xml.write_int("difficulty", impl->difficulty);
- // FIXME: Allow user to decide if level is playable or not
- xml.write_int("playable", 1);
- xml.write_string("comment", impl->comment);
- xml.write_string("music", impl->music);
-
- // Write the list of actions to the file
- xml.begin_section("actions");
- for (std::map<std::string, int>::const_iterator i =
impl->actions.begin();
- i != impl->actions.end(); i++)
- {
- xml.write_int(i->first.c_str(), i->second);
- }
- xml.end_section(); // actions
-
- xml.begin_section("levelsize");
- xml.write_int("width", impl->size.width);
- xml.write_int("height", impl->size.height);
- xml.end_section(); // levelsize
- xml.end_section(); // head
-
- // Write the objects
- xml.begin_section("objects");
- for (unsigned i = 0; i < impl->objects.size(); i++)
- impl->objects[i]->write_properties(xml);
- xml.end_section(); // objects
-
- xml.end_section(); // pingus-level
-
- // Clean up
- out_file.close();
-#endif
- return true;
-}
-
-// Load an existing level from a file
-void XMLLevel::load_level(const std::string& filename)
-{
- if (impl)
- delete impl;
- impl = new LevelImpl();
-
- // Load the level from the file - we don't care what it's res_name is.
- PingusLevel existing_level("", filename);
-
- // Assign all of the level information to our LevelImpl
- impl->levelname = existing_level.get_levelname();
- impl->description = existing_level.get_description();
- impl->ambient_light = existing_level.get_ambient_light();
- impl->size = existing_level.get_size();
- impl->number_of_pingus = existing_level.get_number_of_pingus();
- impl->number_to_save = existing_level.get_number_to_save();
- impl->actions = existing_level.get_actions();
- impl->time = existing_level.get_time();
- impl->difficulty = existing_level.get_difficulty();
- impl->author = existing_level.get_author();
- impl->music = existing_level.get_music();
-
- // Temporary objects
- unsigned attribs;
- Vector3f p;
- Color tmp_color;
- ResDescriptor desc;
- std::string tmp_str;
- int tmp_int;
- float tmp_float;
- bool tmp_bool;
-
- // Get the objects
- std::vector<FileReader> objs = existing_level.get_objects();
- for (std::vector<FileReader>::const_iterator i = objs.begin(); i !=
objs.end(); i++)
- {
- // Create new object
- LevelObj* obj = new LevelObj(i->get_name(), impl);
- attribs = obj->get_attribs();
-
- // All objects have a position - get that.
- i->read_vector("position", p);
- obj->set_orig_pos(p);
- obj->set_pos(p);
-
- // Get optional attributes based on the attribs value
- if (attribs & HAS_SURFACE)
- {
- i->read_desc("surface", desc);
- obj->set_res_desc(desc);
- }
- if (attribs & HAS_TYPE)
- {
- i->read_string("type", tmp_str);
- obj->set_type(tmp_str);
- }
- if (attribs & HAS_SPEED)
- {
- i->read_int("speed", tmp_int);
- obj->set_speed(tmp_int);
- }
- if (attribs & HAS_WIDTH)
- {
- i->read_int("width", tmp_int);
- obj->set_width(tmp_int);
- }
- if (attribs & HAS_PARALLAX)
- {
- i->read_float("parallax", tmp_float);
- obj->set_parallax(tmp_float);
- }
- if (attribs & HAS_OWNER)
- {
- i->read_int("owner-id", tmp_int);
- obj->set_owner(tmp_int);
- }
- if (attribs & HAS_DIRECTION)
- {
- i->read_string("direction", tmp_str);
- obj->set_direction(tmp_str);
- }
- if (attribs & HAS_COLOR)
- {
- i->read_color("color", tmp_color);
- obj->set_color(tmp_color);
- }
- if (attribs & HAS_SCROLL)
- {
- i->read_float("scroll-x", tmp_float);
- obj->set_scroll_x(tmp_float);
- i->read_float("scroll-y", tmp_float);
- obj->set_scroll_y(tmp_float);
- }
- if (attribs & HAS_STRETCH)
- {
- i->read_bool("stretch-x", tmp_bool);
- obj->set_stretch_x(tmp_bool);
- i->read_bool("stretch-y", tmp_bool);
- obj->set_stretch_y(tmp_bool);
- i->read_bool("keep-aspect", tmp_bool);
- obj->set_aspect(tmp_bool);
- }
- if (attribs & HAS_PARA)
- {
- i->read_float("para-x", tmp_float);
- obj->set_para_x(tmp_float);
- i->read_float("para-y", tmp_float);
- obj->set_para_y(tmp_float);
- }
- if (attribs & HAS_RELEASE_RATE)
- {
- i->read_int("release-rate", tmp_int);
- obj->set_release_rate(tmp_int);
- }
-
- impl->objects.push_back((LevelObj*)obj);
- }
-
- // Sort by Z coordinate
- impl->sort_objs();
-}
-
-void
-XMLLevel::add_object(LevelObj* obj)
-{
- impl->objects.push_back(obj);
-}
-
-} // Editor namespace
Deleted: branches/pingus_sdl/src/editor/xml_level.hpp
===================================================================
--- branches/pingus_sdl/src/editor/xml_level.hpp 2007-08-03 22:43:55 UTC
(rev 2781)
+++ branches/pingus_sdl/src/editor/xml_level.hpp 2007-08-03 23:49:47 UTC
(rev 2782)
@@ -1,72 +0,0 @@
-// $Id: xml_level.hxx,v 1.00 2005/11/11 23:41:12 Jave27 Exp $
-//
-// Pingus - A free Lemmings clone
-// Copyright (C) 2005 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_EDITOR_XMLLEVEL_HXX
-#define HEADER_PINGUS_EDITOR_XMLLEVEL_HXX
-
-#include <vector>
-#include "level_impl.hpp"
-
-
-namespace Editor {
-
- class LevelObj;
-
-class XMLLevel
-{
-private:
- LevelImpl* impl;
-
-public:
-
- /** Construct new blank level */
- XMLLevel();
-
- /** Destructor */
- ~XMLLevel();
-
- /** Verify that level is valid */
- bool is_valid();
-
- /** Save the level to a file. Returns true if successful */
- bool save_level(const std::string& filename);
-
- /** Load an existing level from a file */
- void load_level(const std::string& filename);
-
- /** Return all objects in the level */
- std::vector<LevelObj*> get_objects() const { return impl->objects; }
-
- /** Add an object to the level */
- void add_object(LevelObj* obj);
-
- /** Return LevelImpl */
- LevelImpl* get_level_impl() { return impl; }
-
-
-private:
- XMLLevel (const XMLLevel&);
- XMLLevel& operator= (const XMLLevel&);
-}; // XMLLevel class
-
-} // Editor namespace
-
-#endif
-
-/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2782 - in branches/pingus_sdl/src: . editor,
jave27 <=