Skip to content

Commit 4d8fc15

Browse files
committed
Add games made with ALPACA to docs
Lua all callbacks are now optional, no pass nedded anymore
1 parent 502dd11 commit 4d8fc15

File tree

6 files changed

+75
-38
lines changed

6 files changed

+75
-38
lines changed

lua-docs/docs/dialogs.md

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ Examples for start dialogs:
66

77
```lua
88
-- Dialog without callback
9-
PlayDialog("armchair", pass)
9+
PlayDialog("armchair")
1010
```
1111

1212
```lua
1313
-- Dialog with callback.
14-
-- The takeBanana function is called after the dialog is played.
15-
function takeBanana()
16-
PlayAudio("pick-up-item.ogg")
17-
AddToInventory()
18-
SetSkin("inventory")
19-
SetHidden()
20-
end
21-
14+
-- The second function is called after the dialog is played.
2215
function takeBananaDialog()
23-
PlayDialog("banana", takeBanana)
16+
PlayDialog("banana", function ()
17+
PlayAudio("pick-up-item.ogg")
18+
AddToInventory()
19+
SetSkin("inventory")
20+
SetHidden()
21+
end)
2422
end
2523
```
2624

lua-docs/docs/index.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ print("bark")
122122

123123
```lua
124124
print("bark")
125-
PlayAnimation(0, "bark", false, pass)
125+
PlayAnimation(0, "bark", false)
126126
```
127127

128128
Now we will start with the **Lua scripting**, the way logic is defined in an ALPACA game. A full list of functions can be found in the [Lua API](lua.md) documentation. For the quick intro you want the player to go to the item and interact with it. To be able to go somewhere you have to define a [Point](http://esotericsoftware.com/spine-points) in Spine, so let's add the Point to our item and save it again. *I have named the Point in the example "game center" and will also use this name in this tutorial's script*.
@@ -132,16 +132,12 @@ Most Lua Function like `GoToPoint` have two versions: GoToPoint and GoToPointOn
132132
```lua
133133
print("banana_clicked")
134134

135-
function respawn()
136-
print("respawn")
137-
PlayAnimationOn("Player", 0, "idle", true, pass)
138-
end
139-
140-
function play_death()
141-
PlayAnimationOn("Player", 0, "death", false, respawn)
142-
end
143-
144-
GoToPointOn("banana", "center", play_death)
135+
GoToPointOn("banana", "center", function ()
136+
PlayAnimationOn("Player", 0, "death", false, function respawn()
137+
print("respawn")
138+
PlayAnimationOn("Player", 0, "idle", true)
139+
end)
140+
end)
145141
```
146142

147143
For a full overview about all Lua functions see the [Lua documentation](lua.md)

lua-docs/docs/made_with.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# List of ALPACA Projects
2+
3+
## Games made with ALPACA
4+
5+
### Cure for the woods
6+
7+
Windows and Browser version at [itch.io](https://brain-connected.itch.io/cure-for-the-woods)
8+
![Cure for the woods](https://img.itch.zone/aW1nLzExMjQ4OTg2LnBuZw==/original/UWYMbM.png)
9+
10+
## Kids Books made with ALPACA
11+
12+
### Drache Puck und die Wut
13+
14+
![Drache Puck und die Wut](https://is1-ssl.mzstatic.com/image/thumb/PurpleSource221/v4/ae/4d/d4/ae4dd467-5751-79f8-ff65-26b778eef429/8830b91f-afa8-49b0-9d6a-ba720882d40f_page0.png/626x0w.webp)
15+
16+
<div class="video-wrapper">
17+
<iframe width="1280" height="720" src="https://www.youtube.com/watch?v=T5yvy9YEyro" frameborder="0" allowfullscreen></iframe>
18+
</div>
19+
20+
- [Trailer](https://www.youtube.com/watch?v=T5yvy9YEyro)
21+
- [Android](https://play.google.com/store/apps/details?id=com.alpaca.game)
22+
- [iOS](https://apps.apple.com/us/app/drache-puck-und-die-wut/id6477598064)

lua-docs/docs/scene.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ Therefor ALPACA expects a Spine point near each door with next scenes name.
110110
After changing the scene, the player will be placed at the Spine point with last scenes name.
111111

112112
```lua
113-
function door()
113+
GoToPoint("scene_corridor_right", function ()
114114
LoadScene("scene_corridor_right")
115-
end
116-
GoToPoint("scene_corridor_right", door)
115+
end)
117116
```

lua-docs/mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ nav:
1212
- "Dialogs": dialogs.md
1313
- "Spine": spine.md
1414
- "Assets": asset_pipeline.md
15+
- "Made with ALPACA": made_with.md

src/lua.cpp

+35-14
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ void Game::setupLuaFunctions()
7676
/// bool loop: Should the animation be looped at the end.
7777
/// function callback: called on the end of the animation, also on looped animations.
7878
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)
8080
{
81+
if (!callback) {
82+
callback = (*lua_state)["pass"];
83+
}
8184
std::shared_ptr<SpineObject> obj = (*lua_state)["this"];
82-
obj->playAnimation(trackIndex, newAnimation, loop, callback);
85+
obj->playAnimation(trackIndex, newAnimation, loop, callback.value());
8386
std::string lua_object = getLuaPath(obj->getId());
8487
lua_state->script(lua_object + ".animation = \"" + newAnimation + "\"");
8588
if (loop)
@@ -98,10 +101,13 @@ void Game::setupLuaFunctions()
98101
/// bool loop: Should the animation be looped at the end.
99102
/// function callback: called on the end of the animation, also on looped animations.
100103
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)
102105
{
106+
if (!callback) {
107+
callback = (*lua_state)["pass"];
108+
}
103109
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());
105111
std::string lua_object = getLuaPath(obj->getId());
106112
lua_state->script(lua_object + ".animation = \"" + newAnimation + "\"");
107113
if (loop)
@@ -121,12 +127,15 @@ void Game::setupLuaFunctions()
121127
/// bool loop: Should the animation be looped at the end.
122128
/// function callback: called on the end of the animation, also on looped animations.
123129
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)
125131
{
132+
if (!callback) {
133+
callback = (*lua_state)["pass"];
134+
}
126135
std::shared_ptr<SpineObject> obj = getObjectById(object);
127136
if (obj)
128137
{
129-
obj->playAnimation(trackIndex, newAnimation, loop, callback);
138+
obj->playAnimation(trackIndex, newAnimation, loop, callback.value());
130139
std::string lua_object = getLuaPath(obj->getId());
131140
lua_state->script(lua_object + ".animation = \"" + newAnimation + "\"");
132141
if (loop)
@@ -147,12 +156,15 @@ void Game::setupLuaFunctions()
147156
/// bool loop: Should the animation be looped at the end.
148157
/// function callback: called on the end of the animation, also on looped animations.
149158
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)
151160
{
161+
if (!callback) {
162+
callback = (*lua_state)["pass"];
163+
}
152164
std::shared_ptr<SpineObject> obj = getObjectById(object);
153165
if (obj)
154166
{
155-
obj->addAnimation(trackIndex, newAnimation, loop, delay, callback);
167+
obj->addAnimation(trackIndex, newAnimation, loop, delay, callback.value());
156168
std::string lua_object = getLuaPath(obj->getId());
157169
lua_state->script(lua_object + ".animation = \"" + newAnimation + "\"");
158170
if (loop)
@@ -196,8 +208,11 @@ void Game::setupLuaFunctions()
196208
/// Plays a dialog by name
197209
/// string dialogName: Name of the skin that will be set.
198210
lua_state->set_function("PlayDialog",
199-
[this](const LuaDialog &dialogName, sol::function callback)
211+
[this](const LuaDialog &dialogName, std::optional<sol::function> callback)
200212
{
213+
if (!callback) {
214+
callback = (*lua_state)["pass"];
215+
}
201216
float x = 0;
202217
float y = 0;
203218
std::shared_ptr<SpineObject> obj = (*lua_state)["this"];
@@ -208,7 +223,7 @@ void Game::setupLuaFunctions()
208223
spPointAttachment *point = SUB_CAST(spPointAttachment, att);
209224
spPointAttachment_computeWorldPosition(point, slot->bone, &x, &y);
210225
}
211-
getDialogManager()->play(dialogName, jngl::Vec2(x, -y) + obj->getPosition(), callback);
226+
getDialogManager()->play(dialogName, jngl::Vec2(x, -y) + obj->getPosition(), callback.value());
212227
});
213228

214229
/// Adds the current item to the inventory.
@@ -386,13 +401,16 @@ void Game::setupLuaFunctions()
386401
/// string point_name: Name of the point the player should go to
387402
/// function callback: Function that will becalled when the layer reaches the position
388403
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)
390405
{
406+
if (!callback) {
407+
callback = (*lua_state)["pass"];
408+
}
391409
std::shared_ptr<SpineObject> obj = (*lua_state)["this"];
392410
auto position = obj->getPoint(point_name);
393411
if (!position)
394412
return;
395-
std::static_pointer_cast<InteractableObject>(obj)->goToPosition(*position, callback);
413+
std::static_pointer_cast<InteractableObject>(obj)->goToPosition(*position, callback.value());
396414
// TODO Write Players position to Lua
397415
});
398416

@@ -401,15 +419,18 @@ void Game::setupLuaFunctions()
401419
/// string point_name: Name of the point the player should go to
402420
/// function callback: Function that will becalled when the layer reaches the position
403421
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)
405423
{
424+
if (!callback) {
425+
callback = (*lua_state)["pass"];
426+
}
406427
std::shared_ptr<SpineObject> obj = getObjectById(object);
407428
if (obj)
408429
{
409430
auto position = obj->getPoint(point_name);
410431
if (!position)
411432
return;
412-
std::static_pointer_cast<InteractableObject>(obj)->goToPosition(*position, callback);
433+
std::static_pointer_cast<InteractableObject>(obj)->goToPosition(*position, callback.value());
413434
// TODO Write Players position to Lua
414435
}
415436
});

0 commit comments

Comments
 (0)