-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix relative paths with the Particle Editor #3137
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,7 +265,12 @@ Editor::update(float dt_sec, const Controller& controller) | |
m_particle_editor_request = false; | ||
std::unique_ptr<Screen> screen(new ParticleEditor()); | ||
if (m_particle_editor_filename) | ||
static_cast<ParticleEditor*>(screen.get())->open("particles/" + *m_particle_editor_filename); | ||
{ | ||
// realpath() is necessary for particle files outside the particles/ folder | ||
std::string path = physfsutil::realpath("particles/" + *m_particle_editor_filename); | ||
|
||
static_cast<ParticleEditor*>(screen.get())->open(path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You really need to static cast here? You can store the new ParticleEditor in a variable and use that. In my opinion, that would be more readable. And then you can std::make_unique in the push_screen function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The static cast was already there. I've copied the code and changed as little as possible so as not to transform the code too much, since I'm not very familiar with the current coding standards and people's preferences. A static cast will be needed either way if |
||
} | ||
ScreenManager::current()->push_screen(std::move(screen)); | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#include "gui/dialog.hpp" | ||
#include "gui/menu_item.hpp" | ||
#include "gui/menu_manager.hpp" | ||
#include "physfs/util.hpp" | ||
#include "supertux/level.hpp" | ||
#include "supertux/gameconfig.hpp" | ||
#include "supertux/menu/menu_storage.hpp" | ||
|
@@ -55,11 +56,17 @@ ParticleEditorOpen::~ParticleEditorOpen() | |
void | ||
ParticleEditorOpen::menu_action(MenuItem& item) | ||
{ | ||
std::string path; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What? Can't you just make the variable inside the switch case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement The coding style documentation does not specify whether to declare variables outside the switch statement or to create a new scope within the case statement. Since I'm used to the former with SDL and I couldn't find any source as to how to format a scope within a case, I put the variable outside the block. I can move it inside and create a scope, if you could provide me with a preferred formatting template. |
||
|
||
switch (item.get_id()) | ||
{ | ||
case MNID_OPEN: | ||
std::replace(m_filename.begin(), m_filename.end(), '\\', '/'); | ||
ParticleEditor::current()->open("/particles/" + m_filename); | ||
|
||
// realpath() is necessary for particle files outside the particles/ folder | ||
path = physfsutil::realpath("/particles/" + m_filename); | ||
|
||
ParticleEditor::current()->open(path); | ||
MenuManager::instance().clear_menu_stack(); | ||
break; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, whatever happened to
FileSystem::join
? Orstd::filesystem::path::operator/
? Not the only place where this happens so if you're gonna fix this then do it there aswellThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly to above, I have opted not to change the code more than necessary to keep the changes minimal and avoid going against eventual preferences. The join function also does not normalize the path, so it would be an extra call rather than a replacement.