Author: ilor
Date: Tue Oct 14 22:10:29 2008
New Revision: 30168

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30168&view=rev
Log:
editor2 --load will now remeber the filename when loading the map

Modified:
    trunk/src/editor2/editor_controller.cpp
    trunk/src/editor2/editor_controller.hpp
    trunk/src/editor2/editor_main.cpp
    trunk/src/editor2/map_context.cpp
    trunk/src/editor2/map_context.hpp

Modified: trunk/src/editor2/editor_controller.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=30168&r1=30167&r2=30168&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Tue Oct 14 22:10:29 2008
@@ -54,7 +54,7 @@
 
 namespace editor2 {
 
-editor_controller::editor_controller(const config &game_config, CVideo& video, 
editor_map* init_map /*=NULL*/)
+editor_controller::editor_controller(const config &game_config, CVideo& video, 
map_context* init_map_context /*=NULL*/)
        : controller_base(SDL_GetTicks(), game_config, video)
        , mouse_handler_base(get_map())
        , rng_(NULL)
@@ -83,10 +83,10 @@
        , 
auto_update_transitions_(utils::string_bool(preferences::get(prefkey_auto_update_transitions),
 true))
        , default_dir_(preferences::get(prefkey_default_dir))
 {
-       if (init_map == NULL) {
+       if (init_map_context == NULL) {
                map_context_ = new map_context(editor_map(game_config, 44, 33, 
t_translation::GRASS_LAND));
        } else {
-               map_context_ = new map_context(*init_map);
+               map_context_ = init_map_context;
        }
        if (default_dir_.empty()) {
                default_dir_ = get_dir(get_dir(get_user_data_dir() + "/editor") 
+ "/maps");

Modified: trunk/src/editor2/editor_controller.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=30168&r1=30167&r2=30168&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Tue Oct 14 22:10:29 2008
@@ -66,7 +66,7 @@
        private boost::noncopyable
 {
        public:
-               editor_controller(const config &game_config, CVideo& video, 
editor_map* init_map = NULL);
+               editor_controller(const config &game_config, CVideo& video, 
map_context* init_map_context = NULL);
                ~editor_controller();
                
                EXIT_STATUS main_loop();

Modified: trunk/src/editor2/editor_main.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_main.cpp?rev=30168&r1=30167&r2=30168&view=diff
==============================================================================
--- trunk/src/editor2/editor_main.cpp (original)
+++ trunk/src/editor2/editor_main.cpp Tue Oct 14 22:10:29 2008
@@ -16,7 +16,7 @@
 #include "editor_common.hpp"
 #include "editor_controller.hpp"
 #include "editor_main.hpp"
-#include "editor_map.hpp"
+#include "map_context.hpp"
 
 #include "../construct_dialog.hpp"
 #include "../gettext.hpp"
@@ -34,13 +34,12 @@
                hotkey::deactivate_all_scopes();
                hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
                hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
-               editor_map* map = NULL;
+               std::auto_ptr<map_context> mc(NULL);
                std::string map_error;
                if (!filename.empty()) {
                        try {
-                               map = new 
editor_map(editor_map::load_from_file(game_conf, filename));
-                               LOG_ED << "Map loaded. " << map->w() << " by " 
<< map->h() << "\n";
-                               map->sanity_check();
+                               mc.reset(new map_context(game_conf, filename));
+                               LOG_ED << "Map loaded. " << mc->get_map().w() 
<< " by " << mc->get_map().h() << "\n";
                        } catch (editor_map_load_exception& e) {
                                std::stringstream ss;
                                ss << "\"" << boost::replace_all_copy(filename, 
"\\", "\\\\") << "\"";
@@ -48,11 +47,10 @@
                                ss << e.what();
                                map_error = ss.str();
                                ERR_ED << map_error << "\n";
-                               delete map;
-                               map = NULL;
+                               mc.reset();
                        }
                }
-               editor_controller editor(game_conf, video, map);
+               editor_controller editor(game_conf, video, mc.get());
                if (!map_error.empty()) {
                        gui::message_dialog(editor.gui(), _("Error loading 
map"), map_error).show();
                }

Modified: trunk/src/editor2/map_context.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.cpp?rev=30168&r1=30167&r2=30168&view=diff
==============================================================================
--- trunk/src/editor2/map_context.cpp (original)
+++ trunk/src/editor2/map_context.cpp Tue Oct 14 22:10:29 2008
@@ -45,6 +45,21 @@
 {
 }
 
+map_context::map_context(const config& game_config, const std::string& 
filename)
+       : map_(editor_map::load_from_file(game_config, filename)) //will throw 
on error
+       , filename_(filename)
+       , undo_stack_()
+       , redo_stack_()
+       , actions_since_save_(0)
+       , starting_position_label_locs_()
+       , needs_reload_(false)
+       , needs_terrain_rebuild_(false)
+       , needs_labels_reset_(false)
+       , changed_locations_()
+       , everything_changed_(false)
+{
+}
+
 map_context::~map_context()
 {
        clear_stack(undo_stack_);

Modified: trunk/src/editor2/map_context.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/map_context.hpp?rev=30168&r1=30167&r2=30168&view=diff
==============================================================================
--- trunk/src/editor2/map_context.hpp (original)
+++ trunk/src/editor2/map_context.hpp Tue Oct 14 22:10:29 2008
@@ -39,6 +39,13 @@
         */
        map_context(const editor_map& map);
        
+       /**
+        * Create map_context from a map file. If the map cannot be
+        * loaded, an exception will be thrown and the object will
+        * not be constructed.
+        */
+       map_context(const config& game_config, const std::string& filename);
+       
        ~map_context();
        
        /**


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to