@@ -76,10 +76,13 @@ void Game::setupLuaFunctions()
76
76
// / bool loop: Should the animation be looped at the end.
77
77
// / function callback: called on the end of the animation, also on looped animations.
78
78
lua_state->set_function (" PlayAnimation" ,
79
- [this ](int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, sol::function callback)
79
+ [this ](int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, std::optional< sol::function> callback)
80
80
{
81
+ if (!callback) {
82
+ callback = (*lua_state)[" pass" ];
83
+ }
81
84
std::shared_ptr<SpineObject> obj = (*lua_state)[" this" ];
82
- obj->playAnimation (trackIndex, newAnimation, loop, callback);
85
+ obj->playAnimation (trackIndex, newAnimation, loop, callback. value () );
83
86
std::string lua_object = getLuaPath (obj->getId ());
84
87
lua_state->script (lua_object + " .animation = \" " + newAnimation + " \" " );
85
88
if (loop)
@@ -98,10 +101,13 @@ void Game::setupLuaFunctions()
98
101
// / bool loop: Should the animation be looped at the end.
99
102
// / function callback: called on the end of the animation, also on looped animations.
100
103
lua_state->set_function (" AddAnimation" ,
101
- [this ](int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, float delay, sol::function callback)
104
+ [this ](int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, float delay, std::optional< sol::function> callback)
102
105
{
106
+ if (!callback) {
107
+ callback = (*lua_state)[" pass" ];
108
+ }
103
109
std::shared_ptr<SpineObject> obj = (*lua_state)[" this" ];
104
- obj->addAnimation (trackIndex, newAnimation, loop, delay, callback);
110
+ obj->addAnimation (trackIndex, newAnimation, loop, delay, callback. value () );
105
111
std::string lua_object = getLuaPath (obj->getId ());
106
112
lua_state->script (lua_object + " .animation = \" " + newAnimation + " \" " );
107
113
if (loop)
@@ -121,12 +127,15 @@ void Game::setupLuaFunctions()
121
127
// / bool loop: Should the animation be looped at the end.
122
128
// / function callback: called on the end of the animation, also on looped animations.
123
129
lua_state->set_function (" PlayAnimationOn" ,
124
- [this ](const LuaSpineObject &object, int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, sol::function callback)
130
+ [this ](const LuaSpineObject &object, int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, std::optional< sol::function> callback)
125
131
{
132
+ if (!callback) {
133
+ callback = (*lua_state)[" pass" ];
134
+ }
126
135
std::shared_ptr<SpineObject> obj = getObjectById (object);
127
136
if (obj)
128
137
{
129
- obj->playAnimation (trackIndex, newAnimation, loop, callback);
138
+ obj->playAnimation (trackIndex, newAnimation, loop, callback. value () );
130
139
std::string lua_object = getLuaPath (obj->getId ());
131
140
lua_state->script (lua_object + " .animation = \" " + newAnimation + " \" " );
132
141
if (loop)
@@ -147,12 +156,15 @@ void Game::setupLuaFunctions()
147
156
// / bool loop: Should the animation be looped at the end.
148
157
// / function callback: called on the end of the animation, also on looped animations.
149
158
lua_state->set_function (" AddAnimationOn" ,
150
- [this ](const LuaSpineObject &object, int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, float delay, sol::function callback)
159
+ [this ](const LuaSpineObject &object, int trackIndex, const LuaSpineAnimation &newAnimation, bool loop, float delay, std::optional< sol::function> callback)
151
160
{
161
+ if (!callback) {
162
+ callback = (*lua_state)[" pass" ];
163
+ }
152
164
std::shared_ptr<SpineObject> obj = getObjectById (object);
153
165
if (obj)
154
166
{
155
- obj->addAnimation (trackIndex, newAnimation, loop, delay, callback);
167
+ obj->addAnimation (trackIndex, newAnimation, loop, delay, callback. value () );
156
168
std::string lua_object = getLuaPath (obj->getId ());
157
169
lua_state->script (lua_object + " .animation = \" " + newAnimation + " \" " );
158
170
if (loop)
@@ -196,8 +208,11 @@ void Game::setupLuaFunctions()
196
208
// / Plays a dialog by name
197
209
// / string dialogName: Name of the skin that will be set.
198
210
lua_state->set_function (" PlayDialog" ,
199
- [this ](const LuaDialog &dialogName, sol::function callback)
211
+ [this ](const LuaDialog &dialogName, std::optional< sol::function> callback)
200
212
{
213
+ if (!callback) {
214
+ callback = (*lua_state)[" pass" ];
215
+ }
201
216
float x = 0 ;
202
217
float y = 0 ;
203
218
std::shared_ptr<SpineObject> obj = (*lua_state)[" this" ];
@@ -208,7 +223,7 @@ void Game::setupLuaFunctions()
208
223
spPointAttachment *point = SUB_CAST (spPointAttachment, att);
209
224
spPointAttachment_computeWorldPosition (point, slot->bone , &x, &y);
210
225
}
211
- getDialogManager ()->play (dialogName, jngl::Vec2 (x, -y) + obj->getPosition (), callback);
226
+ getDialogManager ()->play (dialogName, jngl::Vec2 (x, -y) + obj->getPosition (), callback. value () );
212
227
});
213
228
214
229
// / Adds the current item to the inventory.
@@ -386,13 +401,16 @@ void Game::setupLuaFunctions()
386
401
// / string point_name: Name of the point the player should go to
387
402
// / function callback: Function that will becalled when the layer reaches the position
388
403
lua_state->set_function (" GoToPoint" ,
389
- [this ](const LuaSpinePoint &point_name, sol::function callback)
404
+ [this ](const LuaSpinePoint &point_name, std::optional< sol::function> callback)
390
405
{
406
+ if (!callback) {
407
+ callback = (*lua_state)[" pass" ];
408
+ }
391
409
std::shared_ptr<SpineObject> obj = (*lua_state)[" this" ];
392
410
auto position = obj->getPoint (point_name);
393
411
if (!position)
394
412
return ;
395
- std::static_pointer_cast<InteractableObject>(obj)->goToPosition (*position, callback);
413
+ std::static_pointer_cast<InteractableObject>(obj)->goToPosition (*position, callback. value () );
396
414
// TODO Write Players position to Lua
397
415
});
398
416
@@ -401,15 +419,18 @@ void Game::setupLuaFunctions()
401
419
// / string point_name: Name of the point the player should go to
402
420
// / function callback: Function that will becalled when the layer reaches the position
403
421
lua_state->set_function (" GoToPointOn" ,
404
- [this ](const LuaSpineObject &object, const LuaSpinePoint &point_name, sol::function callback)
422
+ [this ](const LuaSpineObject &object, const LuaSpinePoint &point_name, std::optional< sol::function> callback)
405
423
{
424
+ if (!callback) {
425
+ callback = (*lua_state)[" pass" ];
426
+ }
406
427
std::shared_ptr<SpineObject> obj = getObjectById (object);
407
428
if (obj)
408
429
{
409
430
auto position = obj->getPoint (point_name);
410
431
if (!position)
411
432
return ;
412
- std::static_pointer_cast<InteractableObject>(obj)->goToPosition (*position, callback);
433
+ std::static_pointer_cast<InteractableObject>(obj)->goToPosition (*position, callback. value () );
413
434
// TODO Write Players position to Lua
414
435
}
415
436
});
0 commit comments