Déplacement de la méthode getLevelName()

This commit is contained in:
Mattéo Delabre 2016-04-19 20:55:51 +02:00
parent a549694c11
commit c467ffc6b7
1 changed files with 27 additions and 4 deletions

View File

@ -5,6 +5,27 @@
#include "game.hpp" #include "game.hpp"
#include <cmath> #include <cmath>
/**
* 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) { Menu::Menu(Manager& manager) : State(manager) {
background.setTexture(getResourceManager().getTexture("bg_menu.tga")); background.setTexture(getResourceManager().getTexture("bg_menu.tga"));
loadMainMenu(); loadMainMenu();
@ -178,7 +199,7 @@ void Menu::loadLevelMenu() {
std::vector<std::string> name_list; std::vector<std::string> name_list;
for (auto it = path_list.begin(); it != path_list.end(); it++) { 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)); actions.push_back(std::bind(&Menu::launchGame, this, *it));
} }
@ -198,7 +219,7 @@ void Menu::loadEditorMenu() {
actions.push_back(std::bind(&Menu::launchEditor, this, "")); actions.push_back(std::bind(&Menu::launchEditor, this, ""));
for (auto it = path_list.begin(); it != path_list.end(); it++) { 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)); actions.push_back(std::bind(&Menu::launchEditor, this, *it));
} }
@ -208,7 +229,8 @@ void Menu::loadEditorMenu() {
void Menu::launchGame(std::string path) { void Menu::launchGame(std::string path) {
auto game = std::unique_ptr<Game>(new Game(getManager())); auto game = std::unique_ptr<Game>(new Game(getManager()));
game->load(path); game->setPath(path);
game->load();
getManager().pushState(std::move(game)); getManager().pushState(std::move(game));
} }
@ -221,7 +243,8 @@ void Menu::launchEditor(std::string path) {
auto editor = std::unique_ptr<Editor>(new Editor(getManager())); auto editor = std::unique_ptr<Editor>(new Editor(getManager()));
if (!path.empty()) { if (!path.empty()) {
editor->load(path); editor->setPath(path);
editor->load();
} }
getManager().pushState(std::move(editor)); getManager().pushState(std::move(editor));