diff options
-rw-r--r-- | doc/lua/player.md | 36 | ||||
-rwxr-xr-x | source/game/scripting/StarPlayerLuaBindings.cpp | 26 |
2 files changed, 62 insertions, 0 deletions
diff --git a/doc/lua/player.md b/doc/lua/player.md index fd8ebd4..f5908ee 100644 --- a/doc/lua/player.md +++ b/doc/lua/player.md @@ -527,3 +527,39 @@ Returns uuid, type, and orbits for all system objects in the specified system; #### `List<String>` player.collectables(`String` collectionName) Returns a list of names of the collectables the player has unlocked in the specified collection. + +--- + +#### `bool` player.isCodexKnown(`String` codexId) + +Returns `true` if the player knows the specified codexId, and `false` otherwise. + +--- + +#### `bool` player.isCodexRead(`String` codexId) + +Returns `true` if the player has read the specified codexId, and `false` otherwise. + +--- + +#### `bool` player.markCodexRead(`String` codexId) + +Marks the specified codexId as read by the player. Returns `true` if the codex is known by the player and was marked as unread and `false` otherwise. + +--- + +#### `bool` player.markCodexUnread(`String` codexId) + +Marks the specified codexId as not read by the player. Returns `true` if the codex is known by the player and was marked as read and `false` otherwise. + +--- + +#### `void` player.learnCodex(`String` codexId, [`bool` markRead]) + +Make the player learn the specified codexId. If markRead is `true`, then the codex will be marked as read by default. + +--- + +#### `Json` player.getCodexes() + +Returns a JSON object where the keys are the codex ID, and the values are if the codex is marked as read.
\ No newline at end of file diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index ea2bae5..ff0b877 100755 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -13,6 +13,7 @@ #include "StarJsonExtra.hpp" #include "StarUniverseClient.hpp" #include "StarTeamClient.hpp" +#include "StarPlayerCodexes.hpp" namespace Star { @@ -743,6 +744,31 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { player->log()->removeScannedObject(objectName); }); + // codex bindings + callbacks.registerCallback("isCodexKnown", [player](String const& codexId) -> bool { + return player->codexes()->codexKnown(codexId); + }); + + callbacks.registerCallback("isCodexRead", [player](String const& codexId) -> bool { + return player->codexes()->codexRead(codexId); + }); + + callbacks.registerCallback("markCodexRead", [player](String const& codexId) -> bool { + return player->codexes()->markCodexRead(codexId); + }); + + callbacks.registerCallback("markCodexUnread", [player](String const& codexId) -> bool { + return player->codexes()->markCodexUnread(codexId); + }); + + callbacks.registerCallback("learnCodex", [player](String const& codexId, Maybe<bool> markRead) { + player->codexes()->learnCodex(codexId, markRead.value(false)); + }); + + callbacks.registerCallback("getCodexes", [player]() -> Json { + return player->codexes()->toJson(); + }); + return callbacks; } |