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

Added Squirrel function to edit the action (animation) of a platform's sprite #1506

Merged
merged 1 commit into from
Aug 14, 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
6 changes: 6 additions & 0 deletions src/object/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ Platform::stop_moving()
get_walker()->stop_moving();
}

void
Platform::set_action(const std::string& action, int repeat)
{
MovingSprite::set_action(action, repeat);
}

void
Platform::move_to(const Vector& pos)
{
Expand Down
3 changes: 3 additions & 0 deletions src/object/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Platform : public MovingSprite,
/** Stop platform at next node */
void stop_moving();

/** Updates the platform to the given action */
void set_action(const std::string& action, int repeat);

/** @} */

private:
Expand Down
7 changes: 7 additions & 0 deletions src/scripting/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ Platform::stop_moving()
object.stop_moving();
}

void
Platform::set_action(const std::string& action, int repeat)
{
SCRIPT_GUARD_VOID;
object.set_action(action, repeat);
}

} // namespace scripting

/* EOF */
3 changes: 3 additions & 0 deletions src/scripting/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Platform final

/** Stop platform at next node */
void stop_moving();

/** Updates the platform to the given action */
void set_action(const std::string& action, int repeat);
};

} // namespace scripting
Expand Down
47 changes: 47 additions & 0 deletions src/scripting/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,46 @@ static SQInteger Platform_stop_moving_wrapper(HSQUIRRELVM vm)

}

static SQInteger Platform_set_action_wrapper(HSQUIRRELVM vm)
{
SQUserPointer data;
if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, nullptr)) || !data) {
sq_throwerror(vm, _SC("'set_action' called without instance"));
return SQ_ERROR;
}
auto _this = reinterpret_cast<scripting::Platform*> (data);

if (_this == nullptr) {
return SQ_ERROR;
}

const SQChar* arg0;
if(SQ_FAILED(sq_getstring(vm, 2, &arg0))) {
sq_throwerror(vm, _SC("Argument 1 not a string"));
return SQ_ERROR;
}

SQInteger arg1;
if(SQ_FAILED(sq_getinteger(vm, 3, &arg1))) {
sq_throwerror(vm, _SC("Argument 2 not a integer"));
return SQ_ERROR;
}

try {
_this->set_action(static_cast<const char*> (arg0), static_cast<int> (arg1));

return 0;

} catch(std::exception& e) {
sq_throwerror(vm, e.what());
return SQ_ERROR;
} catch(...) {
sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_action'"));
return SQ_ERROR;
}

}

static SQInteger Player_release_hook(SQUserPointer ptr, SQInteger )
{
auto _this = reinterpret_cast<scripting::Player*> (ptr);
Expand Down Expand Up @@ -8059,6 +8099,13 @@ void register_supertux_wrapper(HSQUIRRELVM v)
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'stop_moving'");
}

sq_pushstring(v, "set_action", -1);
sq_newclosure(v, &Platform_set_action_wrapper, 0);
sq_setparamscheck(v, SQ_MATCHTYPEMASKSTRING, "x|tsi");
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register function 'set_action'");
}

if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'Platform'");
Expand Down