mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 20:07:35 +00:00
Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
This commit is contained in:
parent
e5f09ea170
commit
3f3f45580a
762 changed files with 8315 additions and 8316 deletions
|
@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
srand(time(nullptr));
|
||||
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-2048"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-2048"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
|
||||
|
@ -48,18 +48,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
size_t board_size = Config::read_i32("2048", "", "board_size", 4);
|
||||
u32 target_tile = Config::read_i32("2048", "", "target_tile", 2048);
|
||||
bool evil_ai = Config::read_bool("2048", "", "evil_ai", false);
|
||||
size_t board_size = Config::read_i32("2048"sv, ""sv, "board_size"sv, 4);
|
||||
u32 target_tile = Config::read_i32("2048"sv, ""sv, "target_tile"sv, 2048);
|
||||
bool evil_ai = Config::read_bool("2048"sv, ""sv, "evil_ai"sv, false);
|
||||
|
||||
if ((target_tile & (target_tile - 1)) != 0) {
|
||||
// If the target tile is not a power of 2, reset to its default value.
|
||||
target_tile = 2048;
|
||||
}
|
||||
|
||||
Config::write_i32("2048", "", "board_size", board_size);
|
||||
Config::write_i32("2048", "", "target_tile", target_tile);
|
||||
Config::write_bool("2048", "", "evil_ai", evil_ai);
|
||||
Config::write_i32("2048"sv, ""sv, "board_size"sv, board_size);
|
||||
Config::write_i32("2048"sv, ""sv, "target_tile"sv, target_tile);
|
||||
Config::write_bool("2048"sv, ""sv, "evil_ai"sv, evil_ai);
|
||||
|
||||
window->set_double_buffering_enabled(false);
|
||||
window->set_title("2048");
|
||||
|
@ -108,15 +108,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
if (!size_dialog->temporary()) {
|
||||
|
||||
Config::write_i32("2048", "", "board_size", board_size);
|
||||
Config::write_i32("2048", "", "target_tile", target_tile);
|
||||
Config::write_bool("2048", "", "evil_ai", evil_ai);
|
||||
Config::write_i32("2048"sv, ""sv, "board_size"sv, board_size);
|
||||
Config::write_i32("2048"sv, ""sv, "target_tile"sv, target_tile);
|
||||
Config::write_bool("2048"sv, ""sv, "evil_ai"sv, evil_ai);
|
||||
|
||||
GUI::MessageBox::show(window, "New settings have been saved and will be applied on a new game", "Settings Changed Successfully", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window, "New settings have been saved and will be applied on a new game"sv, "Settings Changed Successfully"sv, GUI::MessageBox::Type::Information);
|
||||
return;
|
||||
}
|
||||
|
||||
GUI::MessageBox::show(window, "New settings have been set and will be applied on the next game", "Settings Changed Successfully", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window, "New settings have been set and will be applied on the next game"sv, "Settings Changed Successfully"sv, GUI::MessageBox::Type::Information);
|
||||
};
|
||||
auto start_a_new_game = [&] {
|
||||
// Do not leak game states between games.
|
||||
|
@ -149,7 +149,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
update();
|
||||
auto want_to_continue = GUI::MessageBox::show(window,
|
||||
String::formatted("You won the game in {} turns with a score of {}. Would you like to continue?", game.turns(), game.score()),
|
||||
"Congratulations!",
|
||||
"Congratulations!"sv,
|
||||
GUI::MessageBox::Type::Question,
|
||||
GUI::MessageBox::InputType::YesNo);
|
||||
if (want_to_continue == GUI::MessageBox::ExecResult::Yes)
|
||||
|
@ -162,7 +162,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
update();
|
||||
GUI::MessageBox::show(window,
|
||||
String::formatted("You reached {} in {} turns with a score of {}", game.largest_tile(), game.turns(), game.score()),
|
||||
"You lost!",
|
||||
"You lost!"sv,
|
||||
GUI::MessageBox::Type::Information);
|
||||
start_a_new_game();
|
||||
break;
|
||||
|
@ -171,7 +171,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
start_a_new_game();
|
||||
})));
|
||||
|
||||
|
@ -192,7 +192,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
})));
|
||||
|
||||
TRY(game_menu->try_add_separator());
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Settings", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Settings", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv)), [&](auto&) {
|
||||
change_settings();
|
||||
})));
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
ChessWidget::ChessWidget()
|
||||
{
|
||||
set_piece_set("stelar7");
|
||||
set_piece_set("stelar7"sv);
|
||||
}
|
||||
|
||||
void ChessWidget::paint_event(GUI::PaintEvent& event)
|
||||
|
@ -248,46 +248,46 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
|
||||
if (board().game_result() != Chess::Board::Result::NotFinished) {
|
||||
bool over = true;
|
||||
String msg;
|
||||
StringView msg;
|
||||
switch (board().game_result()) {
|
||||
case Chess::Board::Result::CheckMate:
|
||||
if (board().turn() == Chess::Color::White) {
|
||||
msg = "Black wins by Checkmate.";
|
||||
msg = "Black wins by Checkmate."sv;
|
||||
} else {
|
||||
msg = "White wins by Checkmate.";
|
||||
msg = "White wins by Checkmate."sv;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::StaleMate:
|
||||
msg = "Draw by Stalemate.";
|
||||
msg = "Draw by Stalemate."sv;
|
||||
break;
|
||||
case Chess::Board::Result::FiftyMoveRule:
|
||||
update();
|
||||
if (GUI::MessageBox::show(window(), "50 moves have elapsed without a capture. Claim Draw?", "Claim Draw?",
|
||||
if (GUI::MessageBox::show(window(), "50 moves have elapsed without a capture. Claim Draw?"sv, "Claim Draw?"sv,
|
||||
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
|
||||
== GUI::Dialog::ExecResult::Yes) {
|
||||
msg = "Draw by 50 move rule.";
|
||||
msg = "Draw by 50 move rule."sv;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::SeventyFiveMoveRule:
|
||||
msg = "Draw by 75 move rule.";
|
||||
msg = "Draw by 75 move rule."sv;
|
||||
break;
|
||||
case Chess::Board::Result::ThreeFoldRepetition:
|
||||
update();
|
||||
if (GUI::MessageBox::show(window(), "The same board state has repeated three times. Claim Draw?", "Claim Draw?",
|
||||
if (GUI::MessageBox::show(window(), "The same board state has repeated three times. Claim Draw?"sv, "Claim Draw?"sv,
|
||||
GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::YesNo)
|
||||
== GUI::Dialog::ExecResult::Yes) {
|
||||
msg = "Draw by threefold repetition.";
|
||||
msg = "Draw by threefold repetition."sv;
|
||||
} else {
|
||||
over = false;
|
||||
}
|
||||
break;
|
||||
case Chess::Board::Result::FiveFoldRepetition:
|
||||
msg = "Draw by fivefold repetition.";
|
||||
msg = "Draw by fivefold repetition."sv;
|
||||
break;
|
||||
case Chess::Board::Result::InsufficientMaterial:
|
||||
msg = "Draw by insufficient material.";
|
||||
msg = "Draw by insufficient material."sv;
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -296,7 +296,7 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
set_override_cursor(Gfx::StandardCursor::None);
|
||||
set_drag_enabled(false);
|
||||
update();
|
||||
GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), msg, "Game Over"sv, GUI::MessageBox::Type::Information);
|
||||
}
|
||||
} else {
|
||||
input_engine_move();
|
||||
|
@ -377,18 +377,18 @@ static RefPtr<Gfx::Bitmap> get_piece(StringView set, StringView image)
|
|||
void ChessWidget::set_piece_set(StringView set)
|
||||
{
|
||||
m_piece_set = set;
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Pawn }, get_piece(set, "white-pawn.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Pawn }, get_piece(set, "black-pawn.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Knight }, get_piece(set, "white-knight.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Knight }, get_piece(set, "black-knight.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Bishop }, get_piece(set, "white-bishop.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Bishop }, get_piece(set, "black-bishop.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Rook }, get_piece(set, "white-rook.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Rook }, get_piece(set, "black-rook.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Queen }, get_piece(set, "white-queen.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Queen }, get_piece(set, "black-queen.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::King }, get_piece(set, "white-king.png"));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::King }, get_piece(set, "black-king.png"));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Pawn }, get_piece(set, "white-pawn.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Pawn }, get_piece(set, "black-pawn.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Knight }, get_piece(set, "white-knight.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Knight }, get_piece(set, "black-knight.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Bishop }, get_piece(set, "white-bishop.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Bishop }, get_piece(set, "black-bishop.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Rook }, get_piece(set, "white-rook.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Rook }, get_piece(set, "black-rook.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::Queen }, get_piece(set, "white-queen.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::Queen }, get_piece(set, "black-queen.png"sv));
|
||||
m_pieces.set({ Chess::Color::White, Chess::Type::King }, get_piece(set, "white-king.png"sv));
|
||||
m_pieces.set({ Chess::Color::Black, Chess::Type::King }, get_piece(set, "black-king.png"sv));
|
||||
}
|
||||
|
||||
Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
|
||||
|
@ -436,7 +436,7 @@ void ChessWidget::set_board_theme(StringView name)
|
|||
} else if (name == "Blue") {
|
||||
m_board_theme = { "Blue", Color::from_rgb(0x8ca2ad), Color::from_rgb(0xdee3e6) };
|
||||
} else {
|
||||
set_board_theme("Beige");
|
||||
set_board_theme("Beige"sv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -596,15 +596,15 @@ bool ChessWidget::import_pgn(StringView import_path)
|
|||
if (token.contains("*"))
|
||||
break;
|
||||
// FIXME: When we become able to set more of the game state, fix these end results
|
||||
if (token.contains("1-0")) {
|
||||
if (token.contains("1-0"sv)) {
|
||||
m_board.set_resigned(Chess::Color::Black);
|
||||
break;
|
||||
}
|
||||
if (token.contains("0-1")) {
|
||||
if (token.contains("0-1"sv)) {
|
||||
m_board.set_resigned(Chess::Color::White);
|
||||
break;
|
||||
}
|
||||
if (token.contains("1/2-1/2")) {
|
||||
if (token.contains("1/2-1/2"sv)) {
|
||||
break;
|
||||
}
|
||||
if (!token.ends_with(".")) {
|
||||
|
@ -633,24 +633,24 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
auto& file = *file_or_error.value();
|
||||
|
||||
// Tag Pair Section
|
||||
file.write("[Event \"Casual Game\"]\n");
|
||||
file.write("[Site \"SerenityOS Chess\"]\n");
|
||||
file.write(String::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_string("%Y.%m.%d")));
|
||||
file.write("[Round \"1\"]\n");
|
||||
file.write("[Event \"Casual Game\"]\n"sv);
|
||||
file.write("[Site \"SerenityOS Chess\"]\n"sv);
|
||||
file.write(String::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_string("%Y.%m.%d"sv)));
|
||||
file.write("[Round \"1\"]\n"sv);
|
||||
|
||||
String username(getlogin());
|
||||
const String player1 = (!username.is_empty() ? username : "?");
|
||||
const String player2 = (!m_engine.is_null() ? "SerenityOS ChessEngine" : "?");
|
||||
const String player1 = (!username.is_empty() ? username.view() : "?"sv);
|
||||
const String player2 = (!m_engine.is_null() ? "SerenityOS ChessEngine"sv : "?"sv);
|
||||
file.write(String::formatted("[White \"{}\"]\n", m_side == Chess::Color::White ? player1 : player2));
|
||||
file.write(String::formatted("[Black \"{}\"]\n", m_side == Chess::Color::Black ? player1 : player2));
|
||||
|
||||
file.write(String::formatted("[Result \"{}\"]\n", Chess::Board::result_to_points(m_board.game_result(), m_board.turn())));
|
||||
file.write("[WhiteElo \"?\"]\n");
|
||||
file.write("[BlackElo \"?\"]\n");
|
||||
file.write("[Variant \"Standard\"]\n");
|
||||
file.write("[TimeControl \"-\"]\n");
|
||||
file.write("[Annotator \"SerenityOS Chess\"]\n");
|
||||
file.write("\n");
|
||||
file.write("[WhiteElo \"?\"]\n"sv);
|
||||
file.write("[BlackElo \"?\"]\n"sv);
|
||||
file.write("[Variant \"Standard\"]\n"sv);
|
||||
file.write("[TimeControl \"-\"]\n"sv);
|
||||
file.write("[Annotator \"SerenityOS Chess\"]\n"sv);
|
||||
file.write("\n"sv);
|
||||
|
||||
// Movetext Section
|
||||
for (size_t i = 0, move_no = 1; i < m_board.moves().size(); i += 2, move_no++) {
|
||||
|
@ -664,11 +664,11 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
}
|
||||
}
|
||||
|
||||
file.write("{ ");
|
||||
file.write("{ "sv);
|
||||
file.write(Chess::Board::result_to_string(m_board.game_result(), m_board.turn()));
|
||||
file.write(" } ");
|
||||
file.write(" } "sv);
|
||||
file.write(Chess::Board::result_to_points(m_board.game_result(), m_board.turn()));
|
||||
file.write("\n");
|
||||
file.write("\n"sv);
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
|
@ -677,7 +677,7 @@ bool ChessWidget::export_pgn(StringView export_path) const
|
|||
void ChessWidget::flip_board()
|
||||
{
|
||||
if (want_engine_move()) {
|
||||
GUI::MessageBox::show(window(), "You can only flip the board on your turn.", "Flip Board", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), "You can only flip the board on your turn."sv, "Flip Board"sv, GUI::MessageBox::Type::Information);
|
||||
return;
|
||||
}
|
||||
m_side = Chess::opposing_color(m_side);
|
||||
|
@ -688,11 +688,11 @@ void ChessWidget::flip_board()
|
|||
int ChessWidget::resign()
|
||||
{
|
||||
if (want_engine_move()) {
|
||||
GUI::MessageBox::show(window(), "You can only resign on your turn.", "Resign", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), "You can only resign on your turn."sv, "Resign"sv, GUI::MessageBox::Type::Information);
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto result = GUI::MessageBox::show(window(), "Are you sure you wish to resign?", "Resign", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNo);
|
||||
auto result = GUI::MessageBox::show(window(), "Are you sure you wish to resign?"sv, "Resign"sv, GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNo);
|
||||
if (result != GUI::MessageBox::ExecResult::Yes)
|
||||
return -1;
|
||||
|
||||
|
@ -701,7 +701,7 @@ int ChessWidget::resign()
|
|||
set_drag_enabled(false);
|
||||
update();
|
||||
const String msg = Chess::Board::result_to_string(m_board.game_result(), m_board.turn());
|
||||
GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window(), msg, "Game Over"sv, GUI::MessageBox::Type::Information);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
TRY(Core::System::pledge("stdio rpath wpath cpath recvfd sendfd thread proc exec"));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-chess"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
auto widget = TRY(window->try_set_main_widget<ChessWidget>());
|
||||
|
@ -42,10 +42,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/bin/ChessEngine", "x"));
|
||||
TRY(Core::System::unveil("/etc/passwd", "r"));
|
||||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(Core::StandardPaths::home_directory().characters(), "wcbr"));
|
||||
TRY(Core::System::unveil(Core::StandardPaths::home_directory(), "wcbr"sv));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto size = Config::read_i32("Chess", "Display", "size", 512);
|
||||
auto size = Config::read_i32("Chess"sv, "Display"sv, "size"sv, 512);
|
||||
window->set_title("Chess");
|
||||
window->set_base_size({ 4, 4 });
|
||||
window->set_size_increment({ 8, 8 });
|
||||
|
@ -53,10 +53,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
widget->set_piece_set(Config::read_string("Chess", "Style", "PieceSet", "stelar7"));
|
||||
widget->set_board_theme(Config::read_string("Chess", "Style", "BoardTheme", "Beige"));
|
||||
widget->set_coordinates(Config::read_bool("Chess", "Style", "Coordinates", true));
|
||||
widget->set_show_available_moves(Config::read_bool("Chess", "Style", "ShowAvailableMoves", true));
|
||||
widget->set_piece_set(Config::read_string("Chess"sv, "Style"sv, "PieceSet"sv, "stelar7"sv));
|
||||
widget->set_board_theme(Config::read_string("Chess"sv, "Style"sv, "BoardTheme"sv, "Beige"sv));
|
||||
widget->set_coordinates(Config::read_bool("Chess"sv, "Style"sv, "Coordinates"sv, true));
|
||||
widget->set_show_available_moves(Config::read_bool("Chess"sv, "Style"sv, "ShowAvailableMoves"sv, true));
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
|
@ -75,7 +75,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
|
||||
if (!widget->import_pgn(import_path.value())) {
|
||||
GUI::MessageBox::show(window, "Unable to import game.\n", "Error", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window, "Unable to import game.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
|
||||
if (!widget->export_pgn(export_path.value())) {
|
||||
GUI::MessageBox::show(window, "Unable to export game.\n", "Error", GUI::MessageBox::Type::Error);
|
||||
GUI::MessageBox::show(window, "Unable to export game.\n"sv, "Error"sv, GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -96,11 +96,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
})));
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Copy FEN", { Mod_Ctrl, Key_C }, [&](auto&) {
|
||||
GUI::Clipboard::the().set_data(widget->get_fen().bytes());
|
||||
GUI::MessageBox::show(window, "Board state copied to clipboard as FEN.", "Copy FEN", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window, "Board state copied to clipboard as FEN."sv, "Copy FEN"sv, GUI::MessageBox::Type::Information);
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
if (widget->board().game_result() == Chess::Board::Result::NotFinished) {
|
||||
if (widget->resign() < 0)
|
||||
return;
|
||||
|
@ -124,7 +124,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto action = GUI::Action::create_checkable(set, [&](auto& action) {
|
||||
widget->set_piece_set(action.text());
|
||||
widget->update();
|
||||
Config::write_string("Chess", "Style", "PieceSet", action.text());
|
||||
Config::write_string("Chess"sv, "Style"sv, "PieceSet"sv, action.text());
|
||||
});
|
||||
|
||||
piece_set_action_group.add_action(*action);
|
||||
|
@ -136,13 +136,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
GUI::ActionGroup board_theme_action_group;
|
||||
board_theme_action_group.set_exclusive(true);
|
||||
auto board_theme_menu = TRY(style_menu->try_add_submenu("Board Theme"));
|
||||
board_theme_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png").release_value_but_fixme_should_propagate_errors());
|
||||
board_theme_menu->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/chess/mini-board.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
for (auto const& theme : { "Beige", "Green", "Blue" }) {
|
||||
auto action = GUI::Action::create_checkable(theme, [&](auto& action) {
|
||||
widget->set_board_theme(action.text());
|
||||
widget->update();
|
||||
Config::write_string("Chess", "Style", "BoardTheme", action.text());
|
||||
Config::write_string("Chess"sv, "Style"sv, "BoardTheme"sv, action.text());
|
||||
});
|
||||
board_theme_action_group.add_action(*action);
|
||||
if (widget->board_theme().name == theme)
|
||||
|
@ -153,7 +153,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto coordinates_action = GUI::Action::create_checkable("Coordinates", [&](auto& action) {
|
||||
widget->set_coordinates(action.is_checked());
|
||||
widget->update();
|
||||
Config::write_bool("Chess", "Style", "Coordinates", action.is_checked());
|
||||
Config::write_bool("Chess"sv, "Style"sv, "Coordinates"sv, action.is_checked());
|
||||
});
|
||||
coordinates_action->set_checked(widget->coordinates());
|
||||
TRY(style_menu->try_add_action(coordinates_action));
|
||||
|
@ -161,7 +161,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto show_available_moves_action = GUI::Action::create_checkable("Show Available Moves", [&](auto& action) {
|
||||
widget->set_show_available_moves(action.is_checked());
|
||||
widget->update();
|
||||
Config::write_bool("Chess", "Style", "ShowAvailableMoves", action.is_checked());
|
||||
Config::write_bool("Chess"sv, "Style"sv, "ShowAvailableMoves"sv, action.is_checked());
|
||||
});
|
||||
show_available_moves_action->set_checked(widget->show_available_moves());
|
||||
TRY(style_menu->try_add_action(show_available_moves_action));
|
||||
|
|
|
@ -76,7 +76,7 @@ void Game::paint_event(GUI::PaintEvent& event)
|
|||
auto message = String::formatted("Your score: {:.0}\nHigh score: {:.0}\n\n{}", m_last_score, m_high_score.value(), m_restart_cooldown < 0 ? "Press any key to play again" : " ");
|
||||
painter.draw_text(m_text_rect, message, Gfx::TextAlignment::Center, Color::White);
|
||||
} else {
|
||||
painter.draw_text(m_text_rect, "Press any key to start", Gfx::TextAlignment::Center, Color::White);
|
||||
painter.draw_text(m_text_rect, "Press any key to start"sv, Gfx::TextAlignment::Center, Color::White);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ public:
|
|||
public:
|
||||
static ErrorOr<Bug> construct()
|
||||
{
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png"));
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png"));
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png"sv));
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png"sv));
|
||||
return Bug(move(falling_bitmap), move(flapping_bitmap));
|
||||
}
|
||||
|
||||
|
@ -139,9 +139,9 @@ public:
|
|||
static ErrorOr<Cloud> construct()
|
||||
{
|
||||
Vector<NonnullRefPtr<Gfx::Bitmap>> const cloud_bitmaps {
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_0.png")),
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_1.png")),
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_2.png")),
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_0.png"sv)),
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_1.png"sv)),
|
||||
TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/cloud_2.png"sv)),
|
||||
};
|
||||
return Cloud(move(cloud_bitmaps));
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ private:
|
|||
float m_last_score {};
|
||||
float m_difficulty {};
|
||||
float m_restart_cooldown {};
|
||||
NonnullRefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/background.png").release_value_but_fixme_should_propagate_errors() };
|
||||
NonnullRefPtr<Gfx::Bitmap> m_background_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/background.png"sv).release_value_but_fixme_should_propagate_errors() };
|
||||
const Gfx::IntRect m_score_rect { 10, 10, 20, 20 };
|
||||
const Gfx::IntRect m_text_rect { game_width / 2 - 80, game_height / 2 - 40, 160, 80 };
|
||||
|
||||
|
|
|
@ -34,11 +34,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
u32 high_score = Config::read_i32("FlappyBug", "Game", "HighScore", 0);
|
||||
u32 high_score = Config::read_i32("FlappyBug"sv, "Game"sv, "HighScore"sv, 0);
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->resize(FlappyBug::Game::game_width, FlappyBug::Game::game_height);
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-flappybug"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-flappybug"sv));
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
window->set_title("Flappy Bug");
|
||||
window->set_double_buffering_enabled(false);
|
||||
|
@ -49,7 +49,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (score <= high_score)
|
||||
return high_score;
|
||||
|
||||
Config::write_i32("FlappyBug", "Game", "HighScore", score);
|
||||
Config::write_i32("FlappyBug"sv, "Game"sv, "HighScore"sv, score);
|
||||
high_score = score;
|
||||
|
||||
return high_score;
|
||||
|
|
|
@ -40,7 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-gameoflife"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-gameoflife"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
@ -90,8 +90,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
interval_spinbox.set_value(150);
|
||||
|
||||
auto paused_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png").release_value_but_fixme_should_propagate_errors();
|
||||
auto play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png").release_value_but_fixme_should_propagate_errors();
|
||||
auto paused_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
auto play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
auto toggle_running_action = GUI::Action::create("&Toggle Running", { Mod_None, Key_Return }, *play_icon, [&](GUI::Action&) {
|
||||
board_widget->set_running(!board_widget->is_running());
|
||||
|
@ -100,27 +100,27 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
toggle_running_action->set_checkable(true);
|
||||
auto toggle_running_toolbar_button = TRY(main_toolbar.try_add_action(toggle_running_action));
|
||||
|
||||
auto run_one_generation_action = GUI::Action::create("Run &Next Generation", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [&](const GUI::Action&) {
|
||||
auto run_one_generation_action = GUI::Action::create("Run &Next Generation", { Mod_Ctrl, Key_Equal }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors(), [&](const GUI::Action&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget->run_generation();
|
||||
});
|
||||
(void)TRY(main_toolbar.try_add_action(run_one_generation_action));
|
||||
|
||||
auto clear_board_action = GUI::Action::create("&Clear board", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
auto clear_board_action = GUI::Action::create("&Clear board", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/delete.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget->clear_cells();
|
||||
board_widget->update();
|
||||
});
|
||||
(void)TRY(main_toolbar.try_add_action(clear_board_action));
|
||||
|
||||
auto randomize_cells_action = GUI::Action::create("&Randomize board", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
auto randomize_cells_action = GUI::Action::create("&Randomize board", { Mod_Ctrl, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
statusbar.set_text(click_tip);
|
||||
board_widget->randomize_cells();
|
||||
board_widget->update();
|
||||
});
|
||||
(void)TRY(main_toolbar.try_add_action(randomize_cells_action));
|
||||
|
||||
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
|
||||
board_widget->selected_pattern()->rotate_clockwise();
|
||||
});
|
||||
rotate_pattern_action->set_enabled(false);
|
||||
|
|
|
@ -146,9 +146,9 @@ void Game::show_score_card(bool game_over)
|
|||
score_dialog->resize({ 20 + score_card.width() + 15 + close_button.width(), 20 + score_card.height() });
|
||||
|
||||
StringBuilder title_builder;
|
||||
title_builder.append("Score Card");
|
||||
title_builder.append("Score Card"sv);
|
||||
if (game_over)
|
||||
title_builder.append(" - Game Over");
|
||||
title_builder.append(" - Game Over"sv);
|
||||
score_dialog->set_title(title_builder.to_string());
|
||||
|
||||
RefPtr<Core::Timer> close_timer;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-hearts"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-hearts"sv));
|
||||
|
||||
Config::pledge_domain("Hearts");
|
||||
|
||||
|
@ -56,7 +56,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto& statusbar = *widget->find_descendant_of_type_named<GUI::Statusbar>("statusbar");
|
||||
statusbar.set_text(0, "Score: 0");
|
||||
|
||||
String player_name = Config::read_string("Hearts", "", "player_name", "Gunnar");
|
||||
String player_name = Config::read_string("Hearts"sv, ""sv, "player_name"sv, "Gunnar"sv);
|
||||
|
||||
game.on_status_change = [&](const AK::StringView& status) {
|
||||
statusbar.set_override_text(status);
|
||||
|
@ -80,18 +80,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
player_name = settings_dialog->player_name();
|
||||
|
||||
Config::write_string("Hearts", "", "player_name", player_name);
|
||||
Config::write_string("Hearts"sv, ""sv, "player_name"sv, player_name);
|
||||
|
||||
GUI::MessageBox::show(window, "Settings have been successfully saved and will take effect in the next game.", "Settings Changed Successfully", GUI::MessageBox::Type::Information);
|
||||
GUI::MessageBox::show(window, "Settings have been successfully saved and will take effect in the next game."sv, "Settings Changed Successfully"sv, GUI::MessageBox::Type::Information);
|
||||
};
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
game.setup(player_name);
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Settings", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&Settings", TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv)), [&](auto&) {
|
||||
change_settings();
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
WordGame::WordGame()
|
||||
{
|
||||
read_words();
|
||||
m_num_letters = Config::read_i32("MasterWord", "", "word_length", 5);
|
||||
m_max_guesses = Config::read_i32("MasterWord", "", "max_guesses", 6);
|
||||
m_check_guesses = Config::read_bool("MasterWord", "", "check_guesses_in_dictionary", false);
|
||||
m_num_letters = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);
|
||||
m_max_guesses = Config::read_i32("MasterWord"sv, ""sv, "max_guesses"sv, 6);
|
||||
m_check_guesses = Config::read_bool("MasterWord"sv, ""sv, "check_guesses_in_dictionary"sv, false);
|
||||
reset();
|
||||
pick_font();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void WordGame::reset()
|
|||
if (maybe_word.has_value())
|
||||
m_current_word = maybe_word.value();
|
||||
else {
|
||||
GUI::MessageBox::show(window(), String::formatted("Could not get a random {} letter word. Defaulting to 5.", m_num_letters), "MasterWord");
|
||||
GUI::MessageBox::show(window(), String::formatted("Could not get a random {} letter word. Defaulting to 5.", m_num_letters), "MasterWord"sv);
|
||||
if (m_num_letters != 5) {
|
||||
m_num_letters = 5;
|
||||
reset();
|
||||
|
@ -90,10 +90,10 @@ void WordGame::keydown_event(GUI::KeyEvent& event)
|
|||
auto won = m_current_guess == m_current_word;
|
||||
m_current_guess = {};
|
||||
if (won) {
|
||||
GUI::MessageBox::show(window(), "You win!", "MasterWord");
|
||||
GUI::MessageBox::show(window(), "You win!"sv, "MasterWord"sv);
|
||||
reset();
|
||||
} else if (m_guesses.size() == m_max_guesses) {
|
||||
GUI::MessageBox::show(window(), String::formatted("You lose!\nThe word was {}", m_current_word), "MasterWord");
|
||||
GUI::MessageBox::show(window(), String::formatted("You lose!\nThe word was {}", m_current_word), "MasterWord"sv);
|
||||
reset();
|
||||
}
|
||||
} else {
|
||||
|
@ -161,7 +161,7 @@ void WordGame::read_words()
|
|||
m_words.clear();
|
||||
auto response = Core::File::open("/res/words.txt", Core::OpenMode::ReadOnly);
|
||||
if (response.is_error()) {
|
||||
GUI::MessageBox::show(nullptr, "Could not read /res/words.txt.\nPlease ensure this file exists and restart MasterWord.", "MasterWord");
|
||||
GUI::MessageBox::show(nullptr, "Could not read /res/words.txt.\nPlease ensure this file exists and restart MasterWord."sv, "MasterWord"sv);
|
||||
exit(0);
|
||||
}
|
||||
auto words_file = response.value();
|
||||
|
|
|
@ -36,7 +36,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-masterword"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-masterword"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
|
||||
|
@ -46,7 +46,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto game = TRY(window->try_set_main_widget<WordGame>());
|
||||
|
||||
auto use_system_theme = Config::read_bool("MasterWord", "", "use_system_theme", false);
|
||||
auto use_system_theme = Config::read_bool("MasterWord"sv, ""sv, "use_system_theme"sv, false);
|
||||
game->set_use_system_theme(use_system_theme);
|
||||
|
||||
auto shortest_word = game->shortest_word();
|
||||
|
@ -68,33 +68,33 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto settings_menu = TRY(window->try_add_menu("&Settings"));
|
||||
|
||||
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Word Length", [&](auto&) {
|
||||
auto word_length = Config::read_i32("MasterWord", "", "word_length", 5);
|
||||
auto word_length = Config::read_i32("MasterWord"sv, ""sv, "word_length"sv, 5);
|
||||
auto word_length_string = String::number(word_length);
|
||||
if (GUI::InputBox::show(window, word_length_string, "Word length:", "MasterWord") == GUI::InputBox::ExecResult::OK && !word_length_string.is_empty()) {
|
||||
if (GUI::InputBox::show(window, word_length_string, "Word length:"sv, "MasterWord"sv) == GUI::InputBox::ExecResult::OK && !word_length_string.is_empty()) {
|
||||
auto maybe_word_length = word_length_string.template to_uint();
|
||||
if (!maybe_word_length.has_value() || maybe_word_length.value() < shortest_word || maybe_word_length.value() > longest_word) {
|
||||
GUI::MessageBox::show(window, String::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord");
|
||||
GUI::MessageBox::show(window, String::formatted("Please enter a number between {} and {}.", shortest_word, longest_word), "MasterWord"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
word_length = maybe_word_length.value();
|
||||
Config::write_i32("MasterWord", "", "word_length", word_length);
|
||||
Config::write_i32("MasterWord"sv, ""sv, "word_length"sv, word_length);
|
||||
game->set_word_length(word_length);
|
||||
window->resize(game->game_size());
|
||||
}
|
||||
})));
|
||||
TRY(settings_menu->try_add_action(GUI::Action::create("Set &Number Of Guesses", [&](auto&) {
|
||||
auto max_guesses = Config::read_i32("MasterWord", "", "max_guesses", 5);
|
||||
auto max_guesses = Config::read_i32("MasterWord"sv, ""sv, "max_guesses"sv, 5);
|
||||
auto max_guesses_string = String::number(max_guesses);
|
||||
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:", "MasterWord") == GUI::InputBox::ExecResult::OK && !max_guesses_string.is_empty()) {
|
||||
if (GUI::InputBox::show(window, max_guesses_string, "Maximum number of guesses:"sv, "MasterWord"sv) == GUI::InputBox::ExecResult::OK && !max_guesses_string.is_empty()) {
|
||||
auto maybe_max_guesses = max_guesses_string.template to_uint();
|
||||
if (!maybe_max_guesses.has_value() || maybe_max_guesses.value() < 1 || maybe_max_guesses.value() > 20) {
|
||||
GUI::MessageBox::show(window, "Please enter a number between 1 and 20.", "MasterWord");
|
||||
GUI::MessageBox::show(window, "Please enter a number between 1 and 20."sv, "MasterWord"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
max_guesses = maybe_max_guesses.value();
|
||||
Config::write_i32("MasterWord", "", "max_guesses", max_guesses);
|
||||
Config::write_i32("MasterWord"sv, ""sv, "max_guesses"sv, max_guesses);
|
||||
game->set_max_guesses(max_guesses);
|
||||
window->resize(game->game_size());
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto toggle_check_guesses = GUI::Action::create_checkable("Check &Guesses in dictionary", [&](auto& action) {
|
||||
auto checked = action.is_checked();
|
||||
game->set_check_guesses_in_dictionary(checked);
|
||||
Config::write_bool("MasterWord", "", "check_guesses_in_dictionary", checked);
|
||||
Config::write_bool("MasterWord"sv, ""sv, "check_guesses_in_dictionary"sv, checked);
|
||||
});
|
||||
toggle_check_guesses->set_checked(game->is_checking_guesses());
|
||||
TRY(settings_menu->try_add_action(toggle_check_guesses));
|
||||
|
@ -111,7 +111,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto theme_menu = TRY(window->try_add_menu("&Theme"));
|
||||
auto system_theme_action = GUI::Action::create("&System", [&](auto&) {
|
||||
game->set_use_system_theme(true);
|
||||
Config::write_bool("MasterWord", "", "use_system_theme", true);
|
||||
Config::write_bool("MasterWord"sv, ""sv, "use_system_theme"sv, true);
|
||||
});
|
||||
system_theme_action->set_checkable(true);
|
||||
system_theme_action->set_checked(use_system_theme);
|
||||
|
@ -119,7 +119,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto wordle_theme_action = GUI::Action::create("&Wordle", [&](auto&) {
|
||||
game->set_use_system_theme(false);
|
||||
Config::write_bool("MasterWord", "", "use_system_theme", false);
|
||||
Config::write_bool("MasterWord"sv, ""sv, "use_system_theme"sv, false);
|
||||
});
|
||||
wordle_theme_action->set_checkable(true);
|
||||
wordle_theme_action->set_checked(!use_system_theme);
|
||||
|
|
|
@ -118,13 +118,13 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
|
|||
m_time_label.set_text(String::formatted("{}.{}", m_time_elapsed / 10, m_time_elapsed % 10));
|
||||
};
|
||||
m_timer->set_interval(100);
|
||||
m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png").release_value_but_fixme_should_propagate_errors();
|
||||
m_mine_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/mine.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_flag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_badflag_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/badflag.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_consider_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/consider.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_default_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-default.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_good_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-good.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
m_bad_face_bitmap = Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/face-bad.png"sv).release_value_but_fixme_should_propagate_errors();
|
||||
for (int i = 0; i < 8; ++i)
|
||||
m_number_bitmap[i] = Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/minesweeper/{}.png", i + 1)).release_value_but_fixme_should_propagate_errors();
|
||||
// Square with mine will be filled with background color later, i.e. red
|
||||
|
@ -137,11 +137,11 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
|
|||
set_face(Face::Default);
|
||||
|
||||
{
|
||||
bool single_chording = Config::read_bool("Minesweeper", "Game", "SingleChording", false);
|
||||
int mine_count = Config::read_i32("Minesweeper", "Game", "MineCount", 10);
|
||||
int rows = Config::read_i32("Minesweeper", "Game", "Rows", 9);
|
||||
int columns = Config::read_i32("Minesweeper", "Game", "Columns", 9);
|
||||
auto difficulty_string = Config::read_string("Minesweeper", "Game", "Difficulty", "beginner");
|
||||
bool single_chording = Config::read_bool("Minesweeper"sv, "Game"sv, "SingleChording"sv, false);
|
||||
int mine_count = Config::read_i32("Minesweeper"sv, "Game"sv, "MineCount"sv, 10);
|
||||
int rows = Config::read_i32("Minesweeper"sv, "Game"sv, "Rows"sv, 9);
|
||||
int columns = Config::read_i32("Minesweeper"sv, "Game"sv, "Columns"sv, 9);
|
||||
auto difficulty_string = Config::read_string("Minesweeper"sv, "Game"sv, "Difficulty"sv, "beginner"sv);
|
||||
auto difficulty = difficulty_from_string(difficulty_string);
|
||||
|
||||
// Do a quick sanity check to make sure the user hasn't tried anything crazy
|
||||
|
@ -507,10 +507,10 @@ void Field::set_field_size(Difficulty difficulty, size_t rows, size_t columns, s
|
|||
if (m_rows == rows && m_columns == columns && m_mine_count == mine_count)
|
||||
return;
|
||||
{
|
||||
Config::write_i32("Minesweeper", "Game", "MineCount", mine_count);
|
||||
Config::write_i32("Minesweeper", "Game", "Rows", rows);
|
||||
Config::write_i32("Minesweeper", "Game", "Columns", columns);
|
||||
Config::write_string("Minesweeper", "Game", "Difficulty", difficulty_to_string(difficulty));
|
||||
Config::write_i32("Minesweeper"sv, "Game"sv, "MineCount"sv, mine_count);
|
||||
Config::write_i32("Minesweeper"sv, "Game"sv, "Rows"sv, rows);
|
||||
Config::write_i32("Minesweeper"sv, "Game"sv, "Columns"sv, columns);
|
||||
Config::write_string("Minesweeper"sv, "Game"sv, "Difficulty"sv, difficulty_to_string(difficulty));
|
||||
}
|
||||
m_difficulty = difficulty;
|
||||
m_rows = rows;
|
||||
|
@ -524,7 +524,7 @@ void Field::set_field_size(Difficulty difficulty, size_t rows, size_t columns, s
|
|||
void Field::set_single_chording(bool enabled)
|
||||
{
|
||||
m_single_chording = enabled;
|
||||
Config::write_bool("Minesweeper", "Game", "SingleChording", m_single_chording);
|
||||
Config::write_bool("Minesweeper"sv, "Game"sv, "SingleChording"sv, m_single_chording);
|
||||
}
|
||||
|
||||
template<typename Callback>
|
||||
|
|
|
@ -74,19 +74,19 @@ public:
|
|||
|
||||
Optional<Difficulty> difficulty_from_string(StringView difficulty_string) const
|
||||
{
|
||||
if (difficulty_string.matches("beginner"))
|
||||
if (difficulty_string.matches("beginner"sv))
|
||||
return Difficulty::Beginner;
|
||||
|
||||
if (difficulty_string.equals_ignoring_case("intermediate"))
|
||||
if (difficulty_string.equals_ignoring_case("intermediate"sv))
|
||||
return Difficulty::Intermediate;
|
||||
|
||||
if (difficulty_string.equals_ignoring_case("expert"))
|
||||
if (difficulty_string.equals_ignoring_case("expert"sv))
|
||||
return Difficulty::Expert;
|
||||
|
||||
if (difficulty_string.equals_ignoring_case("madwoman"))
|
||||
if (difficulty_string.equals_ignoring_case("madwoman"sv))
|
||||
return Difficulty::Madwoman;
|
||||
|
||||
if (difficulty_string.equals_ignoring_case("custom"))
|
||||
if (difficulty_string.equals_ignoring_case("custom"sv))
|
||||
return Difficulty::Custom;
|
||||
|
||||
return {};
|
||||
|
|
|
@ -41,7 +41,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-minesweeper"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-minesweeper"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_resizable(false);
|
||||
|
@ -63,7 +63,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
container->layout()->add_spacer();
|
||||
|
||||
auto flag_image = TRY(container->try_add<GUI::Label>());
|
||||
flag_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png").release_value_but_fixme_should_propagate_errors());
|
||||
flag_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/flag.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
flag_image->set_fixed_width(16);
|
||||
|
||||
auto flag_label = TRY(container->try_add<GUI::Label>());
|
||||
|
@ -81,7 +81,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto time_image = TRY(container->try_add<GUI::Label>());
|
||||
time_image->set_fixed_width(16);
|
||||
time_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png").release_value_but_fixme_should_propagate_errors());
|
||||
time_image->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/minesweeper/timer.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
auto time_label = TRY(container->try_add<GUI::Label>());
|
||||
time_label->set_fixed_width(50);
|
||||
|
@ -96,7 +96,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
field->reset();
|
||||
})));
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
SnakeGame::SnakeGame()
|
||||
{
|
||||
set_font(Gfx::FontDatabase::default_fixed_width_font().bold_variant());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/paprika.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png").release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/paprika.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/eggplant.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/cauliflower.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_fruit_bitmaps.append(*Gfx::Bitmap::try_load_from_file("/res/icons/snake/tomato.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
reset();
|
||||
|
||||
m_high_score = Config::read_i32("Snake", "Snake", "HighScore", 0);
|
||||
m_high_score = Config::read_i32("Snake"sv, "Snake"sv, "HighScore"sv, 0);
|
||||
m_high_score_text = String::formatted("Best: {}", m_high_score);
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ void SnakeGame::timer_event(Core::TimerEvent&)
|
|||
m_high_score = m_score;
|
||||
m_high_score_text = String::formatted("Best: {}", m_high_score);
|
||||
update(high_score_rect());
|
||||
Config::write_i32("Snake", "Snake", "HighScore", m_high_score);
|
||||
Config::write_i32("Snake"sv, "Snake"sv, "HighScore"sv, m_high_score);
|
||||
}
|
||||
update(score_rect());
|
||||
dirty_cells.append(m_fruit);
|
||||
|
|
|
@ -37,7 +37,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::unveil("/tmp/portal/launch", "rw"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-snake"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-snake"sv));
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
|
||||
|
@ -49,7 +49,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
game->reset();
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
|
|
@ -27,7 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
||||
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-solitaire"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-solitaire"sv));
|
||||
|
||||
Config::pledge_domain("Solitaire");
|
||||
|
||||
|
@ -39,19 +39,19 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_title("Solitaire");
|
||||
|
||||
auto mode = static_cast<Solitaire::Mode>(Config::read_i32("Solitaire", "Settings", "Mode", static_cast<int>(Solitaire::Mode::SingleCardDraw)));
|
||||
auto mode = static_cast<Solitaire::Mode>(Config::read_i32("Solitaire"sv, "Settings"sv, "Mode"sv, static_cast<int>(Solitaire::Mode::SingleCardDraw)));
|
||||
|
||||
auto update_mode = [&](Solitaire::Mode new_mode) {
|
||||
mode = new_mode;
|
||||
Config::write_i32("Solitaire", "Settings", "Mode", static_cast<int>(mode));
|
||||
Config::write_i32("Solitaire"sv, "Settings"sv, "Mode"sv, static_cast<int>(mode));
|
||||
};
|
||||
|
||||
auto high_score = [&]() {
|
||||
switch (mode) {
|
||||
case Solitaire::Mode::SingleCardDraw:
|
||||
return static_cast<u32>(Config::read_i32("Solitaire", "HighScores", "SingleCardDraw", 0));
|
||||
return static_cast<u32>(Config::read_i32("Solitaire"sv, "HighScores"sv, "SingleCardDraw"sv, 0));
|
||||
case Solitaire::Mode::ThreeCardDraw:
|
||||
return static_cast<u32>(Config::read_i32("Solitaire", "HighScores", "ThreeCardDraw", 0));
|
||||
return static_cast<u32>(Config::read_i32("Solitaire"sv, "HighScores"sv, "ThreeCardDraw"sv, 0));
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto update_high_score = [&](u32 new_high_score) {
|
||||
switch (mode) {
|
||||
case Solitaire::Mode::SingleCardDraw:
|
||||
Config::write_i32("Solitaire", "HighScores", "SingleCardDraw", static_cast<int>(new_high_score));
|
||||
Config::write_i32("Solitaire"sv, "HighScores"sv, "SingleCardDraw"sv, static_cast<int>(new_high_score));
|
||||
break;
|
||||
case Solitaire::Mode::ThreeCardDraw:
|
||||
Config::write_i32("Solitaire", "HighScores", "ThreeCardDraw", static_cast<int>(new_high_score));
|
||||
Config::write_i32("Solitaire"sv, "HighScores"sv, "ThreeCardDraw"sv, static_cast<int>(new_high_score));
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
@ -139,8 +139,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto game_in_progress = timer->is_active();
|
||||
if (game_in_progress) {
|
||||
auto result = GUI::MessageBox::show(window,
|
||||
"A game is still in progress, are you sure you would like to quit?",
|
||||
"Game in progress",
|
||||
"A game is still in progress, are you sure you would like to quit?"sv,
|
||||
"Game in progress"sv,
|
||||
GUI::MessageBox::Type::Warning,
|
||||
GUI::MessageBox::InputType::YesNo);
|
||||
|
||||
|
@ -174,18 +174,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
three_card_draw_action->set_status_tip("Draw three cards at a time");
|
||||
draw_setting_actions.add_action(three_card_draw_action);
|
||||
|
||||
game.set_auto_collect(Config::read_bool("Solitaire", "Settings", "AutoCollect", false));
|
||||
game.set_auto_collect(Config::read_bool("Solitaire"sv, "Settings"sv, "AutoCollect"sv, false));
|
||||
auto toggle_auto_collect_action = GUI::Action::create_checkable("Auto-&Collect", [&](auto& action) {
|
||||
auto checked = action.is_checked();
|
||||
game.set_auto_collect(checked);
|
||||
Config::write_bool("Solitaire", "Settings", "AutoCollect", checked);
|
||||
Config::write_bool("Solitaire"sv, "Settings"sv, "AutoCollect"sv, checked);
|
||||
});
|
||||
toggle_auto_collect_action->set_checked(game.is_auto_collecting());
|
||||
toggle_auto_collect_action->set_status_tip("Auto-collect to foundation piles");
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
game.setup(mode);
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
|
|
@ -42,7 +42,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
||||
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-spider"));
|
||||
auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-spider"sv));
|
||||
|
||||
Config::pledge_domain("Spider");
|
||||
|
||||
|
@ -54,58 +54,58 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto window = TRY(GUI::Window::try_create());
|
||||
window->set_title("Spider");
|
||||
|
||||
auto mode = static_cast<Spider::Mode>(Config::read_i32("Spider", "Settings", "Mode", static_cast<int>(Spider::Mode::SingleSuit)));
|
||||
auto mode = static_cast<Spider::Mode>(Config::read_i32("Spider"sv, "Settings"sv, "Mode"sv, static_cast<int>(Spider::Mode::SingleSuit)));
|
||||
|
||||
auto update_mode = [&](Spider::Mode new_mode) {
|
||||
mode = new_mode;
|
||||
Config::write_i32("Spider", "Settings", "Mode", static_cast<int>(mode));
|
||||
Config::write_i32("Spider"sv, "Settings"sv, "Mode"sv, static_cast<int>(mode));
|
||||
};
|
||||
|
||||
auto mode_id = [&]() {
|
||||
switch (mode) {
|
||||
case Spider::Mode::SingleSuit:
|
||||
return "SingleSuit";
|
||||
return "SingleSuit"sv;
|
||||
case Spider::Mode::TwoSuit:
|
||||
return "TwoSuit";
|
||||
return "TwoSuit"sv;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
auto statistic_display = static_cast<StatisticDisplay>(Config::read_i32("Spider", "Settings", "StatisticDisplay", static_cast<int>(StatisticDisplay::HighScore)));
|
||||
auto statistic_display = static_cast<StatisticDisplay>(Config::read_i32("Spider"sv, "Settings"sv, "StatisticDisplay"sv, static_cast<int>(StatisticDisplay::HighScore)));
|
||||
auto update_statistic_display = [&](StatisticDisplay new_statistic_display) {
|
||||
statistic_display = new_statistic_display;
|
||||
Config::write_i32("Spider", "Settings", "StatisticDisplay", static_cast<int>(statistic_display));
|
||||
Config::write_i32("Spider"sv, "Settings"sv, "StatisticDisplay"sv, static_cast<int>(statistic_display));
|
||||
};
|
||||
|
||||
auto high_score = [&]() {
|
||||
return static_cast<u32>(Config::read_i32("Spider", "HighScores", mode_id(), 0));
|
||||
return static_cast<u32>(Config::read_i32("Spider"sv, "HighScores"sv, mode_id(), 0));
|
||||
};
|
||||
|
||||
auto update_high_score = [&](u32 new_high_score) {
|
||||
Config::write_i32("Spider", "HighScores", mode_id(), static_cast<int>(new_high_score));
|
||||
Config::write_i32("Spider"sv, "HighScores"sv, mode_id(), static_cast<int>(new_high_score));
|
||||
};
|
||||
|
||||
auto best_time = [&]() {
|
||||
return static_cast<u32>(Config::read_i32("Spider", "BestTimes", mode_id(), 0));
|
||||
return static_cast<u32>(Config::read_i32("Spider"sv, "BestTimes"sv, mode_id(), 0));
|
||||
};
|
||||
|
||||
auto update_best_time = [&](u32 new_best_time) {
|
||||
Config::write_i32("Spider", "BestTimes", mode_id(), static_cast<int>(new_best_time));
|
||||
Config::write_i32("Spider"sv, "BestTimes"sv, mode_id(), static_cast<int>(new_best_time));
|
||||
};
|
||||
|
||||
auto total_wins = [&]() {
|
||||
return static_cast<u32>(Config::read_i32("Spider", "TotalWins", mode_id(), 0));
|
||||
return static_cast<u32>(Config::read_i32("Spider"sv, "TotalWins"sv, mode_id(), 0));
|
||||
};
|
||||
auto increment_total_wins = [&]() {
|
||||
Config::write_i32("Spider", "TotalWins", mode_id(), static_cast<int>(total_wins() + 1));
|
||||
Config::write_i32("Spider"sv, "TotalWins"sv, mode_id(), static_cast<int>(total_wins() + 1));
|
||||
};
|
||||
|
||||
auto total_losses = [&]() {
|
||||
return static_cast<u32>(Config::read_i32("Spider", "TotalLosses", mode_id(), 0));
|
||||
return static_cast<u32>(Config::read_i32("Spider"sv, "TotalLosses"sv, mode_id(), 0));
|
||||
};
|
||||
auto increment_total_losses = [&]() {
|
||||
Config::write_i32("Spider", "TotalLosses", mode_id(), static_cast<int>(total_losses() + 1));
|
||||
Config::write_i32("Spider"sv, "TotalLosses"sv, mode_id(), static_cast<int>(total_losses() + 1));
|
||||
};
|
||||
|
||||
if (mode >= Spider::Mode::__Count)
|
||||
|
@ -196,8 +196,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto game_in_progress = timer->is_active();
|
||||
if (game_in_progress) {
|
||||
auto result = GUI::MessageBox::show(window,
|
||||
"A game is still in progress, are you sure you would like to quit? Doing so will count as a loss.",
|
||||
"Game in progress",
|
||||
"A game is still in progress, are you sure you would like to quit? Doing so will count as a loss."sv,
|
||||
"Game in progress"sv,
|
||||
GUI::MessageBox::Type::Warning,
|
||||
GUI::MessageBox::InputType::YesNo);
|
||||
|
||||
|
@ -233,7 +233,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
suit_actions.add_action(two_suit_action);
|
||||
|
||||
auto game_menu = TRY(window->try_add_menu("&Game"));
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png")), [&](auto&) {
|
||||
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
|
||||
game.setup(mode);
|
||||
})));
|
||||
TRY(game_menu->try_add_separator());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue