From 861622bef9b17bfc32ac6083bc22fbe3751bc52a Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 12 Nov 2023 12:57:16 +0100 Subject: [PATCH] fix `get_seed` and `set_seed` in the doc --- docs/game_data/spel2.lua | 4 +- docs/parse_source.py | 4 -- docs/src/includes/_types.md | 4 +- src/game_api/screen.cpp | 32 ++++++++++++++++ src/game_api/screen.hpp | 5 +++ src/game_api/script/usertypes/screen_lua.cpp | 40 +------------------- 6 files changed, 43 insertions(+), 46 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 350097f34..2d85a4527 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -5688,8 +5688,8 @@ function Quad:is_point_inside(x, y, epsilon) end ---@field start_sidepanel TextureRenderingInfo ---@field start_sidepanel_slidein_timer number ---@field seed_length integer @Current input length (0-8). You probably shouldn't write to this, except to set it to 0. - ---@field get_seed integer? - ---@field set_seed any @[](ScreenCodeInput&s + ---@field get_seed fun(self): integer? @Get the seed currently entered in the seed dialog or nil if nothing is entered. Will also return incomplete seeds, check seed_length to verify it's ready. + ---@field set_seed fun(self, seed: integer?, length: integer?): nil @Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed. ---@class ScreenCharacterSelect : Screen ---@field main_background_zoom_target number diff --git a/docs/parse_source.py b/docs/parse_source.py index 929518496..1e08a1b3d 100644 --- a/docs/parse_source.py +++ b/docs/parse_source.py @@ -685,10 +685,6 @@ def run_parse(): var_name = var[0] cpp = var[1] - # if "screenonlinelobby_type" in container: - # print_console(var_name) - # print_console(cpp) - # print_console(underlying_cpp_type['name']) if var[1].startswith("sol::property"): param_match = re.match( diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 380dd29df..827ee5e12 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -2308,8 +2308,8 @@ float | [topleft_woodpanel_esc_slidein_timer](https://github.com/spelunky-fyi/ov [TextureRenderingInfo](#TextureRenderingInfo) | [start_sidepanel](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=start_sidepanel) | float | [start_sidepanel_slidein_timer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=start_sidepanel_slidein_timer) | int | [seed_length](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=seed_length) | Current input length (0-8). You probably shouldn't write to this, except to set it to 0. -optional<int> | [get_seed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_seed) | Get the seed currently entered in the seed dialog or nil if nothing is entered. Will also return incomplete seeds, check seed_length to verify it's ready.
- | [set_seed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_seed) | Params: optional seed, optional length
Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed.
+optional<int> | [get_seed()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_seed) | Get the seed currently entered in the seed dialog or nil if nothing is entered. Will also return incomplete seeds, check seed_length to verify it's ready. +nil | [set_seed(optional seed, optional length)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_seed) | Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed. ### ScreenConstellation diff --git a/src/game_api/screen.cpp b/src/game_api/screen.cpp index 3335cba70..1050d7a66 100644 --- a/src/game_api/screen.cpp +++ b/src/game_api/screen.cpp @@ -369,3 +369,35 @@ void show_journal(JOURNALUI_PAGE_SHOWN chapter, uint32_t page) gm->journal_ui->flipping_to_page = page; } } + +std::optional ScreenCodeInput::get_seed() +{ + if (code_length == 0) + return std::nullopt; + std::wstringstream ss; + std::wstring seed_str; + for (uint8_t i = 0; i < code_length; ++i) + seed_str.push_back((wchar_t)(code_chars[i])); + ss << std::hex << seed_str; + uint32_t seed{0}; + ss >> seed; + return seed; +} + +void ScreenCodeInput::set_seed(std::optional seed, std::optional length) +{ + uint8_t len = length.value_or(8); + if (len > 8) + len = 8; + if (seed.has_value()) + { + std::wstringstream ss; + ss << std::uppercase << std::hex << std::setw(len) << std::setfill(L'0') << seed.value(); + memcpy(code_chars, ss.str().c_str(), len * 2); + code_length = len; + } + else + { + code_length = 0; + } +} diff --git a/src/game_api/screen.hpp b/src/game_api/screen.hpp index 5408cad38..66d2b1f6e 100644 --- a/src/game_api/screen.hpp +++ b/src/game_api/screen.hpp @@ -390,6 +390,11 @@ class ScreenCodeInput : public Screen // ID: 8 TextureRenderingInfo start_sidepanel; float start_sidepanel_slidein; + /// Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed. + void set_seed(std::optional seed, std::optional length); + /// Get the seed currently entered in the seed dialog or nil if nothing is entered. Will also return incomplete seeds, check seed_length to verify it's ready. + std::optional get_seed(); + virtual void unknown() = 0; // set seed? sets the game variables in state, for ScreenEnterOnlineCode it just sets the unknown10 }; diff --git a/src/game_api/script/usertypes/screen_lua.cpp b/src/game_api/script/usertypes/screen_lua.cpp index 71736a0a6..8d26368dc 100644 --- a/src/game_api/script/usertypes/screen_lua.cpp +++ b/src/game_api/script/usertypes/screen_lua.cpp @@ -274,44 +274,8 @@ void register_usertypes(sol::state& lua) screenseedinput_type["start_sidepanel"] = &ScreenCodeInput::start_sidepanel; screenseedinput_type["start_sidepanel_slidein_timer"] = &ScreenCodeInput::start_sidepanel_slidein; screenseedinput_type["seed_length"] = &ScreenCodeInput::code_length; - screenseedinput_type["get_seed"] = [](ScreenCodeInput& s) -> std::optional - { - if (s.code_length == 0) - return std::nullopt; - std::wstringstream ss; - std::wstring seed_str; - for (uint8_t i = 0; i < s.code_length; ++i) - seed_str.push_back((wchar_t)(s.code_chars[i])); - ss << std::hex << seed_str; - uint32_t seed{0}; - ss >> seed; - return seed; - }; - screenseedinput_type["set_seed"] = [](ScreenCodeInput& s, std::optional seed, std::optional length) - { - uint8_t len = length.value_or(8); - if (len > 8) - len = 8; - if (seed.has_value()) - { - std::wstringstream ss; - ss << std::uppercase << std::hex << std::setw(len) << std::setfill(L'0') << seed.value(); - memcpy(s.code_chars, ss.str().c_str(), len * 2); - s.code_length = len; - } - else - { - s.code_length = 0; - } - }; - - /* ScreenCodeInput - // get_seed - // Get the seed currently entered in the seed dialog or nil if nothing is entered. Will also return incomplete seeds, check seed_length to verify it's ready. - // set_seed - // Params: optional seed, optional length - // Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed. - */ + screenseedinput_type["get_seed"] = &ScreenCodeInput::get_seed; + screenseedinput_type["set_seed"] = &ScreenCodeInput::set_seed; auto screencharacterselect_type = lua.new_usertype("ScreenCharacterSelect", sol::base_classes, sol::bases()); screencharacterselect_type["main_background_zoom_target"] = &ScreenCharacterSelect::main_background_zoom_target;