From c467ffc6b7b81f36359fe91d2a15a2dfeb392211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Tue, 19 Apr 2016 20:55:51 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9placement=20de=20la=20m=C3=A9thode=20get?= =?UTF-8?q?LevelName()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/menu.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index aeb5d87..8140ab8 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -5,6 +5,27 @@ #include "game.hpp" #include +/** + * Définition des variables et fonctions globales internes + * (accessibles uniquement dans ce fichier) + */ +namespace { + /** + * Récupère le nom du niveau dont le fichier est donné + */ + sf::String getLevelName(Manager& manager, std::string path) { + // pour ce faire, on crée une instance temporaire de + // Game que l'on charge avec le chemin donné puis on + // extrait son nom + Game temporary_game(manager); + + temporary_game.setPath(path); + temporary_game.load(); + + return temporary_game.getName(); + } +} + Menu::Menu(Manager& manager) : State(manager) { background.setTexture(getResourceManager().getTexture("bg_menu.tga")); loadMainMenu(); @@ -178,7 +199,7 @@ void Menu::loadLevelMenu() { std::vector name_list; for (auto it = path_list.begin(); it != path_list.end(); it++) { - choices.push_back(Level::getLevelName(*it)); + choices.push_back(getLevelName(getManager(), *it)); actions.push_back(std::bind(&Menu::launchGame, this, *it)); } @@ -198,7 +219,7 @@ void Menu::loadEditorMenu() { actions.push_back(std::bind(&Menu::launchEditor, this, "")); for (auto it = path_list.begin(); it != path_list.end(); it++) { - choices.push_back(Level::getLevelName(*it)); + choices.push_back(getLevelName(getManager(), *it)); actions.push_back(std::bind(&Menu::launchEditor, this, *it)); } @@ -208,7 +229,8 @@ void Menu::loadEditorMenu() { void Menu::launchGame(std::string path) { auto game = std::unique_ptr(new Game(getManager())); - game->load(path); + game->setPath(path); + game->load(); getManager().pushState(std::move(game)); } @@ -221,7 +243,8 @@ void Menu::launchEditor(std::string path) { auto editor = std::unique_ptr(new Editor(getManager())); if (!path.empty()) { - editor->load(path); + editor->setPath(path); + editor->load(); } getManager().pushState(std::move(editor));