Skip to content

Commit f4a7555

Browse files
committed
Randomize the profile when adding or inserting a new row.
1 parent 8c7ab09 commit f4a7555

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerSettings.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ ControllerSettingsRow::ControllerSettingsRow(EditableTableOption& parent_table)
178178
add_option(right_grip, "Right Grip");
179179
add_option(official_color, "Official Color");
180180

181+
set_profile(ControllerSettingsTable::random_profile(controller));
182+
181183
controller.add_listener(*this);
182184
#if 1
183185
button_color.add_listener(*this);
@@ -268,6 +270,19 @@ std::vector<std::string> ControllerSettingsTable::make_header() const{
268270
}
269271

270272

273+
274+
ControllerProfile ControllerSettingsTable::random_profile(ControllerType controller){
275+
const std::vector<OfficialJoyconColors>& DATABASE = OFFICIAL_JOYCON_COLORS();
276+
277+
ControllerProfile profile;
278+
279+
uint64_t seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
280+
seed = pabb_crc32(0, &seed, sizeof(seed));
281+
seed %= DATABASE.size();
282+
283+
DATABASE[(size_t)seed].write_to_profile(profile, controller);
284+
return profile;
285+
}
271286
ControllerProfile ControllerSettingsTable::get_or_make_profile(
272287
const std::string& name,
273288
ControllerType controller
@@ -305,13 +320,7 @@ ControllerProfile ControllerSettingsTable::get_or_make_profile(
305320
return profile;
306321
}
307322

308-
const std::vector<OfficialJoyconColors>& DATABASE = OFFICIAL_JOYCON_COLORS();
309-
310-
uint64_t seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
311-
seed = pabb_crc32(0, &seed, sizeof(seed));
312-
seed %= DATABASE.size();
313-
314-
DATABASE[(size_t)seed].write_to_profile(profile, controller);
323+
profile = random_profile(controller);
315324

316325
std::unique_ptr<ControllerSettingsRow> row(new ControllerSettingsRow(*this));
317326
row->name.set(name);

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ControllerSettingsTable : public EditableTableOption_t<ControllerSettingsR
7070
ControllerSettingsTable();
7171
virtual std::vector<std::string> make_header() const override;
7272

73+
static ControllerProfile random_profile(ControllerType controller);
7374
ControllerProfile get_or_make_profile(
7475
const std::string& name,
7576
ControllerType controller

0 commit comments

Comments
 (0)