From fde429d1a7a6e6c583418690b286e062de72ad2d Mon Sep 17 00:00:00 2001 From: emmaker Date: Mon, 2 Jun 2025 16:21:32 -0400 Subject: Add codex bindings to player table --- source/game/scripting/StarPlayerLuaBindings.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index ea2bae5..833d718 100755 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -743,6 +743,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, bool markRead) { + player->codexes()->learnCodex(codexId, markRead); + }); + + callbacks.registerCallback("getCodexes", [player]() -> Json { + return player->codexes()->toJson(); + }); + return callbacks; } -- cgit v1.2.3 From 9287cf833594d7bccfe3dce2b1f7230496908bcc Mon Sep 17 00:00:00 2001 From: emmaker Date: Mon, 2 Jun 2025 17:47:11 -0400 Subject: Syntax fix (oops) --- source/game/scripting/StarPlayerLuaBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 833d718..ca7c3c2 100755 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -745,7 +745,7 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { // codex bindings callbacks.registerCallback("isCodexKnown", [player](String const& codexId) -> bool { - return player.codexes()->codexKnown(codexId); + return player->codexes()->codexKnown(codexId); }); callbacks.registerCallback("isCodexRead", [player](String const& codexId) -> bool { -- cgit v1.2.3 From 00d70f62235437bd7f473d43c506a1c652236362 Mon Sep 17 00:00:00 2001 From: emmaker Date: Mon, 2 Jun 2025 18:04:46 -0400 Subject: Include missing header --- source/game/scripting/StarPlayerLuaBindings.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index ca7c3c2..0f8bdfc 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 { -- cgit v1.2.3 From 855d34a80a9c1efdc4d04bd540efef5125e54974 Mon Sep 17 00:00:00 2001 From: emmaker Date: Mon, 2 Jun 2025 18:45:40 -0400 Subject: Change type of markRead to Maybe --- source/game/scripting/StarPlayerLuaBindings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/game/scripting/StarPlayerLuaBindings.cpp b/source/game/scripting/StarPlayerLuaBindings.cpp index 0f8bdfc..ff0b877 100755 --- a/source/game/scripting/StarPlayerLuaBindings.cpp +++ b/source/game/scripting/StarPlayerLuaBindings.cpp @@ -761,8 +761,8 @@ LuaCallbacks LuaBindings::makePlayerCallbacks(Player* player) { return player->codexes()->markCodexUnread(codexId); }); - callbacks.registerCallback("learnCodex", [player](String const& codexId, bool markRead) { - player->codexes()->learnCodex(codexId, markRead); + callbacks.registerCallback("learnCodex", [player](String const& codexId, Maybe markRead) { + player->codexes()->learnCodex(codexId, markRead.value(false)); }); callbacks.registerCallback("getCodexes", [player]() -> Json { -- cgit v1.2.3 From adf61fd0df78cc7a2f1d40cacfe6cfd745d37b40 Mon Sep 17 00:00:00 2001 From: emmaker Date: Mon, 2 Jun 2025 18:45:57 -0400 Subject: Document codex binds --- doc/lua/player.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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` 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 -- cgit v1.2.3