Skip to content

Commit

Permalink
fix get_seed and set_seed in the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Nov 12, 2023
1 parent 509734c commit 861622b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 46 deletions.
4 changes: 2 additions & 2 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions docs/parse_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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&lt;int&gt; | [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.<br/>
| [set_seed](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_seed) | Params: optional<int> seed, optional<int> length<br/>Set the seed entered in the seed dialog. Call without arguments to clear entered seed. Optionally enter a length to set partial seed.<br/>
optional&lt;int&gt; | [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<int> seed, optional<int> 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

Expand Down
32 changes: 32 additions & 0 deletions src/game_api/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,35 @@ void show_journal(JOURNALUI_PAGE_SHOWN chapter, uint32_t page)
gm->journal_ui->flipping_to_page = page;
}
}

std::optional<uint32_t> 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<uint32_t> seed, std::optional<uint8_t> 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;
}
}
5 changes: 5 additions & 0 deletions src/game_api/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> seed, std::optional<uint8_t> 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<uint32_t> get_seed();

virtual void unknown() = 0; // set seed? sets the game variables in state, for ScreenEnterOnlineCode it just sets the unknown10
};

Expand Down
40 changes: 2 additions & 38 deletions src/game_api/script/usertypes/screen_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>
{
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<uint32_t> seed, std::optional<uint8_t> 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<int> seed, optional<int> 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>("ScreenCharacterSelect", sol::base_classes, sol::bases<Screen>());
screencharacterselect_type["main_background_zoom_target"] = &ScreenCharacterSelect::main_background_zoom_target;
Expand Down

0 comments on commit 861622b

Please sign in to comment.