1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:27:35 +00:00

Snake: Implement image-based skins

Co-authored-by: HawDevelopment <hawdevelopment@gmail.com>
This commit is contained in:
Sam Atkins 2023-03-16 14:00:20 +00:00 committed by Andreas Kling
parent da7c883dfa
commit 5708a47157
20 changed files with 425 additions and 33 deletions

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "SnakeSkin.h"
#include "ClassicSkin.h"
#include "ImageSkin.h"
#include <AK/String.h>
#include <LibCore/DeprecatedFile.h>
namespace Snake {
ErrorOr<NonnullOwnPtr<SnakeSkin>> SnakeSkin::create(StringView skin_name, Color color)
{
if (skin_name == "classic"sv)
return try_make<ClassicSkin>(color);
// Try to find an image-based skin matching the name.
if (Core::DeprecatedFile::exists(TRY(String::formatted("/res/graphics/snake/skins/{}", skin_name))))
return ImageSkin::create(skin_name);
// Fall-back on classic
return try_make<ClassicSkin>(color);
}
}