seperate assets as constants
This commit is contained in:
@ -58,6 +58,7 @@
|
||||
#include "states/State.h"
|
||||
|
||||
#include "ui/BottomMenu.h"
|
||||
#include "../resources/AssetPaths.h"
|
||||
#include "ui/MenuLayout.h"
|
||||
|
||||
#include "utils/ImagePathResolver.h"
|
||||
@ -962,20 +963,20 @@ void TetrisApp::Impl::runLoop()
|
||||
musicLoaded = true;
|
||||
}
|
||||
|
||||
pixelFont.init(AssetPath::resolveWithBase("assets/fonts/Orbitron.ttf"), 22);
|
||||
pixelFont.init(AssetPath::resolveWithBase(Assets::FONT_ORBITRON), 22);
|
||||
loadedTasks.fetch_add(1);
|
||||
font.init(AssetPath::resolveWithBase("assets/fonts/Exo2.ttf"), 20);
|
||||
font.init(AssetPath::resolveWithBase(Assets::FONT_EXO2), 20);
|
||||
loadedTasks.fetch_add(1);
|
||||
|
||||
queuedPaths = {
|
||||
"assets/images/spacetris.png",
|
||||
"assets/images/spacetris.png",
|
||||
"assets/images/main_screen.png",
|
||||
"assets/images/blocks90px_001.bmp",
|
||||
"assets/images/panel_score.png",
|
||||
"assets/images/statistics_panel.png",
|
||||
"assets/images/next_panel.png",
|
||||
"assets/images/hold_panel.png"
|
||||
Assets::LOGO,
|
||||
Assets::LOGO,
|
||||
Assets::MAIN_SCREEN,
|
||||
Assets::BLOCKS_SPRITE,
|
||||
Assets::PANEL_SCORE,
|
||||
Assets::PANEL_STATS,
|
||||
Assets::NEXT_PANEL,
|
||||
Assets::HOLD_PANEL
|
||||
};
|
||||
for (auto &p : queuedPaths) {
|
||||
loadingManager->queueTexture(p);
|
||||
@ -1006,14 +1007,14 @@ void TetrisApp::Impl::runLoop()
|
||||
|
||||
bool texturesDone = loadingManager->update();
|
||||
if (texturesDone) {
|
||||
logoTex = assetLoader.getTexture("assets/images/spacetris.png");
|
||||
logoSmallTex = assetLoader.getTexture("assets/images/spacetris.png");
|
||||
mainScreenTex = assetLoader.getTexture("assets/images/main_screen.png");
|
||||
blocksTex = assetLoader.getTexture("assets/images/blocks90px_001.png");
|
||||
scorePanelTex = assetLoader.getTexture("assets/images/panel_score.png");
|
||||
statisticsPanelTex = assetLoader.getTexture("assets/images/statistics_panel.png");
|
||||
nextPanelTex = assetLoader.getTexture("assets/images/next_panel.png");
|
||||
holdPanelTex = assetLoader.getTexture("assets/images/hold_panel.png");
|
||||
logoTex = assetLoader.getTexture(Assets::LOGO);
|
||||
logoSmallTex = assetLoader.getTexture(Assets::LOGO);
|
||||
mainScreenTex = assetLoader.getTexture(Assets::MAIN_SCREEN);
|
||||
blocksTex = assetLoader.getTexture(Assets::BLOCKS_SPRITE);
|
||||
scorePanelTex = assetLoader.getTexture(Assets::PANEL_SCORE);
|
||||
statisticsPanelTex = assetLoader.getTexture(Assets::PANEL_STATS);
|
||||
nextPanelTex = assetLoader.getTexture(Assets::NEXT_PANEL);
|
||||
holdPanelTex = assetLoader.getTexture(Assets::HOLD_PANEL);
|
||||
|
||||
auto ensureTextureSize = [&](SDL_Texture* tex, int& outW, int& outH) {
|
||||
if (!tex) return;
|
||||
@ -1038,14 +1039,14 @@ void TetrisApp::Impl::runLoop()
|
||||
}
|
||||
};
|
||||
|
||||
legacyLoad("assets/images/spacetris.png", logoTex);
|
||||
legacyLoad("assets/images/spacetris.png", logoSmallTex, &logoSmallW, &logoSmallH);
|
||||
legacyLoad("assets/images/main_screen.png", mainScreenTex, &mainScreenW, &mainScreenH);
|
||||
legacyLoad("assets/images/blocks90px_001.png", blocksTex);
|
||||
legacyLoad("assets/images/panel_score.png", scorePanelTex);
|
||||
legacyLoad("assets/images/statistics_panel.png", statisticsPanelTex);
|
||||
legacyLoad("assets/images/next_panel.png", nextPanelTex);
|
||||
legacyLoad("assets/images/hold_panel.png", holdPanelTex);
|
||||
legacyLoad(Assets::LOGO, logoTex);
|
||||
legacyLoad(Assets::LOGO, logoSmallTex, &logoSmallW, &logoSmallH);
|
||||
legacyLoad(Assets::MAIN_SCREEN, mainScreenTex, &mainScreenW, &mainScreenH);
|
||||
legacyLoad(Assets::BLOCKS_SPRITE, blocksTex);
|
||||
legacyLoad(Assets::PANEL_SCORE, scorePanelTex);
|
||||
legacyLoad(Assets::PANEL_STATS, statisticsPanelTex);
|
||||
legacyLoad(Assets::NEXT_PANEL, nextPanelTex);
|
||||
legacyLoad(Assets::HOLD_PANEL, holdPanelTex);
|
||||
|
||||
if (!blocksTex) {
|
||||
blocksTex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 630, 90);
|
||||
@ -1061,7 +1062,7 @@ void TetrisApp::Impl::runLoop()
|
||||
SDL_SetRenderTarget(renderer, nullptr);
|
||||
|
||||
// Ensure the generated fallback texture is cleaned up with other assets.
|
||||
assetLoader.adoptTexture("assets/images/blocks90px_001.png", blocksTex);
|
||||
assetLoader.adoptTexture(Assets::BLOCKS_SPRITE, blocksTex);
|
||||
}
|
||||
|
||||
if (musicLoaded) {
|
||||
@ -1429,12 +1430,12 @@ void TetrisApp::Impl::runLoop()
|
||||
break;
|
||||
case AppState::Menu:
|
||||
if (!mainScreenTex) {
|
||||
mainScreenTex = assetLoader.getTexture("assets/images/main_screen.png");
|
||||
mainScreenTex = assetLoader.getTexture(Assets::MAIN_SCREEN);
|
||||
}
|
||||
if (!mainScreenTex) {
|
||||
SDL_Texture* loaded = textureLoader->loadFromImage(renderer, "assets/images/main_screen.png", &mainScreenW, &mainScreenH);
|
||||
SDL_Texture* loaded = textureLoader->loadFromImage(renderer, Assets::MAIN_SCREEN, &mainScreenW, &mainScreenH);
|
||||
if (loaded) {
|
||||
assetLoader.adoptTexture("assets/images/main_screen.png", loaded);
|
||||
assetLoader.adoptTexture(Assets::MAIN_SCREEN, loaded);
|
||||
mainScreenTex = loaded;
|
||||
}
|
||||
}
|
||||
|
||||
17
src/resources/AssetPaths.h
Normal file
17
src/resources/AssetPaths.h
Normal file
@ -0,0 +1,17 @@
|
||||
// Centralized asset path constants
|
||||
#pragma once
|
||||
|
||||
namespace Assets {
|
||||
inline constexpr const char* FONT_ORBITRON = "assets/fonts/Orbitron.ttf";
|
||||
inline constexpr const char* FONT_EXO2 = "assets/fonts/Exo2.ttf";
|
||||
|
||||
inline constexpr const char* LOGO = "assets/images/spacetris.png";
|
||||
inline constexpr const char* MAIN_SCREEN = "assets/images/main_screen.png";
|
||||
inline constexpr const char* BLOCKS_SPRITE = "assets/images/blocks90px_003.png";
|
||||
inline constexpr const char* PANEL_SCORE = "assets/images/panel_score.png";
|
||||
inline constexpr const char* PANEL_STATS = "assets/images/statistics_panel.png";
|
||||
inline constexpr const char* NEXT_PANEL = "assets/images/next_panel.png";
|
||||
inline constexpr const char* HOLD_PANEL = "assets/images/hold_panel.png";
|
||||
|
||||
inline constexpr const char* MUSIC_DIR = "assets/music/";
|
||||
}
|
||||
Reference in New Issue
Block a user