-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lua: Add basic APIs for walking to a towner
This may not be how we'll eventually expose towners but it's good enough for now.
- Loading branch information
Showing
9 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "lua/modules/player.hpp" | ||
|
||
#include <sol/sol.hpp> | ||
|
||
#include "engine/point.hpp" | ||
#include "lua/metadoc.hpp" | ||
#include "player.h" | ||
|
||
namespace devilution { | ||
|
||
sol::table LuaPlayerModule(sol::state_view &lua) | ||
{ | ||
sol::table table = lua.create_table(); | ||
SetDocumented(table, "walk_to", "(x: integer, y: integer)", | ||
"Walk to the given coordinates", | ||
[](int x, int y) { | ||
NetSendCmdLoc(MyPlayerId, true, CMD_WALKXY, Point { x, y }); | ||
}); | ||
return table; | ||
} | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <sol/sol.hpp> | ||
|
||
namespace devilution { | ||
|
||
sol::table LuaPlayerModule(sol::state_view &lua); | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "lua/modules/towners.hpp" | ||
|
||
#include <optional> | ||
#include <utility> | ||
|
||
#include <sol/sol.hpp> | ||
|
||
#include "engine/point.hpp" | ||
#include "lua/metadoc.hpp" | ||
#include "player.h" | ||
#include "towners.h" | ||
|
||
namespace devilution { | ||
namespace { | ||
|
||
const char *const TownerTableNames[NUM_TOWNER_TYPES] { | ||
"griswold", | ||
"pepin", | ||
"deadguy", | ||
"ogden", | ||
"cain", | ||
"farnham", | ||
"adria", | ||
"gillian", | ||
"wirt", | ||
"cow", | ||
"lester", | ||
"celia", | ||
"nut", | ||
}; | ||
|
||
void PopulateTownerTable(_talker_id townerId, sol::table &out) | ||
{ | ||
SetDocumented(out, "position", "()", | ||
"Returns towner coordinates", | ||
[townerId]() -> std::optional<std::pair<int, int>> { | ||
const Towner *towner = GetTowner(townerId); | ||
if (towner == nullptr) return std::nullopt; | ||
return std::make_pair(towner->position.x, towner->position.y); | ||
}); | ||
} | ||
} // namespace | ||
|
||
sol::table LuaTownersModule(sol::state_view &lua) | ||
{ | ||
sol::table table = lua.create_table(); | ||
for (uint8_t townerId = TOWN_SMITH; townerId < NUM_TOWNER_TYPES; ++townerId) { | ||
sol::table townerTable = lua.create_table(); | ||
PopulateTownerTable(static_cast<_talker_id>(townerId), townerTable); | ||
SetDocumented(table, TownerTableNames[townerId], /*signature=*/"", TownerLongNames[townerId], std::move(townerTable)); | ||
} | ||
return table; | ||
} | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <sol/sol.hpp> | ||
|
||
namespace devilution { | ||
|
||
sol::table LuaTownersModule(sol::state_view &lua); | ||
|
||
} // namespace devilution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters