[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] [pingus] push by address@hidden - Implemented loading of gr
From: |
pingus |
Subject: |
[Pingus-CVS] [pingus] push by address@hidden - Implemented loading of groups on 2011-09-10 22:46 GMT |
Date: |
Sat, 10 Sep 2011 23:03:06 +0000 |
Revision: b3457889a0cf
Author: Ingo Ruhnke <address@hidden>
Date: Sat Sep 10 15:45:50 2011
Log: Implemented loading of groups
http://code.google.com/p/pingus/source/detail?r=b3457889a0cf
Added:
/src/editor/level_obj_factory.cpp
/src/editor/level_obj_factory.hpp
Modified:
/src/editor/editor_level.cpp
=======================================
--- /dev/null
+++ /src/editor/level_obj_factory.cpp Sat Sep 10 15:45:50 2011
@@ -0,0 +1,178 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "editor/level_obj_factory.hpp"
+
+#include "editor/generic_level_obj.hpp"
+#include "editor/group_level_obj.hpp"
+#include "util/file_reader.hpp"
+
+namespace Editor {
+
+LevelObj*
+LevelObjFactory::create(const FileReader& reader, LevelImpl* level)
+{
+ if (reader.get_name() == "group")
+ {
+ GroupLevelObj* group = new GroupLevelObj;
+ const std::vector<FileReader>& sections = reader.get_sections();
+ for(auto it = sections.begin(); it != sections.end(); ++it)
+ {
+ LevelObj* obj = create(*it, level);
+ if (obj)
+ {
+ group->add_child(obj);
+ }
+ }
+ return group;
+ }
+ else
+ {
+ // Temporary objects
+ unsigned attribs;
+ Vector3f p;
+ Color tmp_color;
+ ResDescriptor desc;
+ std::string tmp_str;
+ int tmp_int;
+ float tmp_float;
+ bool tmp_bool;
+
+ // Create new object
+ LevelObj* obj = new GenericLevelObj(reader.get_name(), level);
+ attribs = obj->get_attribs();
+
+ // All objects have a position - get that.
+ if (!reader.read_vector("position", p))
+ { // Workaround for lack of position for background
+ if (reader.get_name() == "surface-background")
+ p = Vector3f(0.f, 0.f, -150.f);
+ }
+
+ obj->set_orig_pos(p);
+ obj->set_pos(p);
+
+ // Get optional attributes based on the attribs value
+ if (attribs & HAS_SPRITE)
+ {
+ reader.read_desc("surface", desc);
+ obj->set_res_desc(desc);
+ }
+ if (attribs & HAS_TYPE)
+ {
+ reader.read_string("type", tmp_str);
+ obj->set_type(tmp_str);
+ }
+ if (attribs & HAS_GPTYPE)
+ {
+ reader.read_string("type", tmp_str);
+ obj->set_ground_type(tmp_str);
+ }
+ if (attribs & HAS_SPEED)
+ {
+ reader.read_int("speed", tmp_int);
+ obj->set_speed(tmp_int);
+ }
+ if (attribs & HAS_REPEAT)
+ {
+ if (!reader.read_int("repeat", tmp_int))
+ reader.read_int("width", tmp_int);
+ obj->set_repeat(tmp_int);
+ }
+ if (attribs & HAS_PARALLAX)
+ {
+ reader.read_float("parallax", tmp_float);
+ obj->set_parallax(tmp_float);
+ }
+ if (attribs & HAS_OWNER)
+ {
+ reader.read_int("owner-id", tmp_int);
+ obj->set_owner(tmp_int);
+ }
+ if (attribs & HAS_DIRECTION)
+ {
+ reader.read_string("direction", tmp_str);
+ obj->set_direction(tmp_str);
+ }
+ if (attribs & HAS_COLOR)
+ {
+ if (!reader.read_colori("colori", tmp_color))
+ reader.read_colorf("color", tmp_color);
+ obj->set_color(tmp_color);
+ }
+ if (attribs & HAS_SCROLL)
+ {
+ reader.read_float("scroll-x", tmp_float);
+ obj->set_scroll_x(tmp_float);
+ reader.read_float("scroll-y", tmp_float);
+ obj->set_scroll_y(tmp_float);
+ }
+ if (attribs & HAS_STRETCH)
+ {
+ reader.read_bool("stretch-x", tmp_bool);
+ obj->set_stretch_x(tmp_bool);
+ reader.read_bool("stretch-y", tmp_bool);
+ obj->set_stretch_y(tmp_bool);
+ reader.read_bool("keep-aspect", tmp_bool);
+ obj->set_keep_aspect(tmp_bool);
+ }
+ if (attribs & HAS_PARA)
+ {
+ reader.read_float("para-x", tmp_float);
+ obj->set_para_x(tmp_float);
+ reader.read_float("para-y", tmp_float);
+ obj->set_para_y(tmp_float);
+ }
+ if (attribs & HAS_RELEASE_RATE)
+ {
+ reader.read_int("release-rate", tmp_int);
+ obj->set_release_rate(tmp_int);
+ }
+ if (attribs & HAS_ID)
+ {
+ reader.read_string("id", tmp_str);
+ obj->set_id(tmp_str);
+ }
+ if (attribs & HAS_TARGET_ID)
+ {
+ reader.read_string("target-id", tmp_str);
+ obj->set_target_id(tmp_str);
+ }
+
+ if (attribs & HAS_STARFIELD)
+ {
+ reader.read_int("small-stars", tmp_int);
+ obj->set_small_stars(tmp_int);
+
+ reader.read_int("middle-stars", tmp_int);
+ obj->set_middle_stars(tmp_int);
+
+ reader.read_int("large-stars", tmp_int);
+ obj->set_large_stars(tmp_int);
+ }
+ if (attribs & HAS_HEIGHT)
+ {
+ reader.read_int("height", tmp_int);
+ obj->set_repeat(tmp_int);
+ }
+
+ return obj;
+ }
+}
+
+} // namespace Editor
+
+/* EOF */
=======================================
--- /dev/null
+++ /src/editor/level_obj_factory.hpp Sat Sep 10 15:45:50 2011
@@ -0,0 +1,42 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_PINGUS_EDITOR_LEVEL_OBJ_FACTORY_HPP
+#define HEADER_PINGUS_EDITOR_LEVEL_OBJ_FACTORY_HPP
+
+class FileReader;
+
+namespace Editor {
+
+class LevelObj;
+class LevelImpl;
+
+class LevelObjFactory
+{
+private:
+public:
+ static LevelObj* create(const FileReader& reader, LevelImpl* level);
+
+private:
+ LevelObjFactory(const LevelObjFactory&);
+ LevelObjFactory& operator=(const LevelObjFactory&);
+};
+
+} // namespace Editor
+
+#endif
+
+/* EOF */
=======================================
--- /src/editor/editor_level.cpp Sat Sep 10 15:30:34 2011
+++ /src/editor/editor_level.cpp Sat Sep 10 15:45:50 2011
@@ -20,6 +20,7 @@
#include <algorithm>
#include "editor/level_objs.hpp"
+#include "editor/level_obj_factory.hpp"
#include "editor/generic_level_obj.hpp"
#include "editor/level_impl.hpp"
#include "pingus/pingus_level.hpp"
@@ -178,139 +179,15 @@
if (impl->music == "none")
impl->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 = level.get_objects();
for (std::vector<FileReader>::const_iterator i = objs.begin(); i !=
objs.end(); i++)
{
- // Create new object
- LevelObj* obj = new GenericLevelObj(i->get_name(), impl.get());
- attribs = obj->get_attribs();
-
- // All objects have a position - get that.
- if (!i->read_vector("position", p))
- { // Workaround for lack of position for background
- if (i->get_name() == "surface-background")
- p = Vector3f(0.f, 0.f, -150.f);
- }
-
- obj->set_orig_pos(p);
- obj->set_pos(p);
-
- // Get optional attributes based on the attribs value
- if (attribs & HAS_SPRITE)
- {
- 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_GPTYPE)
- {
- i->read_string("type", tmp_str);
- obj->set_ground_type(tmp_str);
- }
- if (attribs & HAS_SPEED)
- {
- i->read_int("speed", tmp_int);
- obj->set_speed(tmp_int);
- }
- if (attribs & HAS_REPEAT)
- {
- if (!i->read_int("repeat", tmp_int))
- i->read_int("width", tmp_int);
- obj->set_repeat(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)
- {
- if (!i->read_colori("colori", tmp_color))
- i->read_colorf("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_keep_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);
- }
- if (attribs & HAS_ID)
- {
- i->read_string("id", tmp_str);
- obj->set_id(tmp_str);
- }
- if (attribs & HAS_TARGET_ID)
- {
- i->read_string("target-id", tmp_str);
- obj->set_target_id(tmp_str);
- }
-
- if (attribs & HAS_STARFIELD)
- {
- i->read_int("small-stars", tmp_int);
- obj->set_small_stars(tmp_int);
-
- i->read_int("middle-stars", tmp_int);
- obj->set_middle_stars(tmp_int);
-
- i->read_int("large-stars", tmp_int);
- obj->set_large_stars(tmp_int);
- }
- if (attribs & HAS_HEIGHT)
- {
- i->read_int("height", tmp_int);
- obj->set_repeat(tmp_int);
- }
-
- add_object(obj);
+ LevelObj* obj = LevelObjFactory::create(*i, impl.get());
+ if (obj)
+ {
+ add_object(obj);
+ }
}
sort();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] [pingus] push by address@hidden - Implemented loading of groups on 2011-09-10 22:46 GMT,
pingus <=