Skip to content
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

Fixed bug where ScriptTrigger areas wouldn't save their name #1622

Merged
merged 1 commit into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/supertux/moving_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "editor/resize_marker.hpp"
#include "supertux/sector.hpp"
#include "util/reader_mapping.hpp"
#include "util/writer.hpp"

MovingObject::MovingObject() :
Expand All @@ -29,6 +30,16 @@ MovingObject::MovingObject(const ReaderMapping& reader) :
GameObject(reader),
m_col(COLGROUP_MOVING, *this)
{
float height, width;

if (reader.get("width", width))
m_col.m_bbox.set_width(width);

if (reader.get("height", height))
m_col.m_bbox.set_height(height);

reader.get("x", m_col.m_bbox.get_left());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this. the get_left() and get_top() methods are marked const. However, they're passed by reference to the reader.get() method which might attempt to save a value, which should fail. Can you please test this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobbi There is another place in the code that uses the exact same trick, the author called it a "temporary hack" (which I (or anyone) should fix someday). Two overloads for that function, of which one is a non-const reference.
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting. OKay, I'm gonna merge this.

reader.get("y", m_col.m_bbox.get_top());
}

MovingObject::~MovingObject()
Expand Down
25 changes: 10 additions & 15 deletions src/trigger/scripttrigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@
#include "video/drawing_context.hpp"

ScriptTrigger::ScriptTrigger(const ReaderMapping& reader) :
TriggerBase(reader),
triggerevent(),
script(),
new_size(),
must_activate(false),
oneshot(false),
runcount(0)
{
reader.get("x", m_col.m_bbox.get_left());
reader.get("y", m_col.m_bbox.get_top());
float w = 32, h = 32;
reader.get("width", w);
reader.get("height", h);
m_col.m_bbox.set_size(w, h);
new_size.x = w;
new_size.y = h;
if (m_col.m_bbox.get_width() == 0.f)
m_col.m_bbox.set_width(32.f);

if (m_col.m_bbox.get_height() == 0.f)
m_col.m_bbox.set_height(32.f);

reader.get("script", script);
reader.get("button", must_activate);
reader.get("oneshot", oneshot);
Expand All @@ -53,6 +52,7 @@ ScriptTrigger::ScriptTrigger(const ReaderMapping& reader) :
}

ScriptTrigger::ScriptTrigger(const Vector& pos, const std::string& script_) :
TriggerBase(),
triggerevent(EVENT_TOUCH),
script(script_),
new_size(),
Expand All @@ -70,13 +70,8 @@ ScriptTrigger::get_settings()
new_size.x = m_col.m_bbox.get_width();
new_size.y = m_col.m_bbox.get_height();

ObjectSettings result(_("Script Trigger"));
ObjectSettings result = TriggerBase::get_settings();

result.add_text(_("Name"), &m_name);
result.add_float(_("Width"), &new_size.x, "width");
result.add_float(_("Height"), &new_size.y, "height");
result.add_float(_("X"), &m_col.m_bbox.get_left(), "x", {}, OPTION_HIDDEN);
result.add_float(_("Y"), &m_col.m_bbox.get_top(), "y", {}, OPTION_HIDDEN);
result.add_script(_("Script"), &script, "script");
result.add_bool(_("Button"), &must_activate, "button");
result.add_bool(_("Oneshot"), &oneshot, "oneshot", false);
Expand All @@ -88,7 +83,7 @@ ScriptTrigger::get_settings()

void
ScriptTrigger::after_editor_set() {
m_col.m_bbox.set_size(new_size.x, new_size.y);
//m_col.m_bbox.set_size(new_size.x, new_size.y);
if (must_activate) {
triggerevent = EVENT_ACTIVATE;
} else {
Expand Down
1 change: 1 addition & 0 deletions src/trigger/scripttrigger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ScriptTrigger final : public TriggerBase
ScriptTrigger(const Vector& pos, const std::string& script);

virtual std::string get_class() const override { return "scripttrigger"; }
std::string get_display_name() const override { return _("Script Trigger"); }
virtual bool has_variable_size() const override { return true; }

virtual ObjectSettings get_settings() override;
Expand Down