seperate assets as constants
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
@ -58,6 +58,7 @@
|
|||||||
#include "states/State.h"
|
#include "states/State.h"
|
||||||
|
|
||||||
#include "ui/BottomMenu.h"
|
#include "ui/BottomMenu.h"
|
||||||
|
#include "../resources/AssetPaths.h"
|
||||||
#include "ui/MenuLayout.h"
|
#include "ui/MenuLayout.h"
|
||||||
|
|
||||||
#include "utils/ImagePathResolver.h"
|
#include "utils/ImagePathResolver.h"
|
||||||
@ -962,20 +963,20 @@ void TetrisApp::Impl::runLoop()
|
|||||||
musicLoaded = true;
|
musicLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixelFont.init(AssetPath::resolveWithBase("assets/fonts/Orbitron.ttf"), 22);
|
pixelFont.init(AssetPath::resolveWithBase(Assets::FONT_ORBITRON), 22);
|
||||||
loadedTasks.fetch_add(1);
|
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);
|
loadedTasks.fetch_add(1);
|
||||||
|
|
||||||
queuedPaths = {
|
queuedPaths = {
|
||||||
"assets/images/spacetris.png",
|
Assets::LOGO,
|
||||||
"assets/images/spacetris.png",
|
Assets::LOGO,
|
||||||
"assets/images/main_screen.png",
|
Assets::MAIN_SCREEN,
|
||||||
"assets/images/blocks90px_001.bmp",
|
Assets::BLOCKS_SPRITE,
|
||||||
"assets/images/panel_score.png",
|
Assets::PANEL_SCORE,
|
||||||
"assets/images/statistics_panel.png",
|
Assets::PANEL_STATS,
|
||||||
"assets/images/next_panel.png",
|
Assets::NEXT_PANEL,
|
||||||
"assets/images/hold_panel.png"
|
Assets::HOLD_PANEL
|
||||||
};
|
};
|
||||||
for (auto &p : queuedPaths) {
|
for (auto &p : queuedPaths) {
|
||||||
loadingManager->queueTexture(p);
|
loadingManager->queueTexture(p);
|
||||||
@ -1006,14 +1007,14 @@ void TetrisApp::Impl::runLoop()
|
|||||||
|
|
||||||
bool texturesDone = loadingManager->update();
|
bool texturesDone = loadingManager->update();
|
||||||
if (texturesDone) {
|
if (texturesDone) {
|
||||||
logoTex = assetLoader.getTexture("assets/images/spacetris.png");
|
logoTex = assetLoader.getTexture(Assets::LOGO);
|
||||||
logoSmallTex = assetLoader.getTexture("assets/images/spacetris.png");
|
logoSmallTex = assetLoader.getTexture(Assets::LOGO);
|
||||||
mainScreenTex = assetLoader.getTexture("assets/images/main_screen.png");
|
mainScreenTex = assetLoader.getTexture(Assets::MAIN_SCREEN);
|
||||||
blocksTex = assetLoader.getTexture("assets/images/blocks90px_001.png");
|
blocksTex = assetLoader.getTexture(Assets::BLOCKS_SPRITE);
|
||||||
scorePanelTex = assetLoader.getTexture("assets/images/panel_score.png");
|
scorePanelTex = assetLoader.getTexture(Assets::PANEL_SCORE);
|
||||||
statisticsPanelTex = assetLoader.getTexture("assets/images/statistics_panel.png");
|
statisticsPanelTex = assetLoader.getTexture(Assets::PANEL_STATS);
|
||||||
nextPanelTex = assetLoader.getTexture("assets/images/next_panel.png");
|
nextPanelTex = assetLoader.getTexture(Assets::NEXT_PANEL);
|
||||||
holdPanelTex = assetLoader.getTexture("assets/images/hold_panel.png");
|
holdPanelTex = assetLoader.getTexture(Assets::HOLD_PANEL);
|
||||||
|
|
||||||
auto ensureTextureSize = [&](SDL_Texture* tex, int& outW, int& outH) {
|
auto ensureTextureSize = [&](SDL_Texture* tex, int& outW, int& outH) {
|
||||||
if (!tex) return;
|
if (!tex) return;
|
||||||
@ -1038,14 +1039,14 @@ void TetrisApp::Impl::runLoop()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
legacyLoad("assets/images/spacetris.png", logoTex);
|
legacyLoad(Assets::LOGO, logoTex);
|
||||||
legacyLoad("assets/images/spacetris.png", logoSmallTex, &logoSmallW, &logoSmallH);
|
legacyLoad(Assets::LOGO, logoSmallTex, &logoSmallW, &logoSmallH);
|
||||||
legacyLoad("assets/images/main_screen.png", mainScreenTex, &mainScreenW, &mainScreenH);
|
legacyLoad(Assets::MAIN_SCREEN, mainScreenTex, &mainScreenW, &mainScreenH);
|
||||||
legacyLoad("assets/images/blocks90px_001.png", blocksTex);
|
legacyLoad(Assets::BLOCKS_SPRITE, blocksTex);
|
||||||
legacyLoad("assets/images/panel_score.png", scorePanelTex);
|
legacyLoad(Assets::PANEL_SCORE, scorePanelTex);
|
||||||
legacyLoad("assets/images/statistics_panel.png", statisticsPanelTex);
|
legacyLoad(Assets::PANEL_STATS, statisticsPanelTex);
|
||||||
legacyLoad("assets/images/next_panel.png", nextPanelTex);
|
legacyLoad(Assets::NEXT_PANEL, nextPanelTex);
|
||||||
legacyLoad("assets/images/hold_panel.png", holdPanelTex);
|
legacyLoad(Assets::HOLD_PANEL, holdPanelTex);
|
||||||
|
|
||||||
if (!blocksTex) {
|
if (!blocksTex) {
|
||||||
blocksTex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 630, 90);
|
blocksTex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 630, 90);
|
||||||
@ -1061,7 +1062,7 @@ void TetrisApp::Impl::runLoop()
|
|||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer, nullptr);
|
||||||
|
|
||||||
// Ensure the generated fallback texture is cleaned up with other assets.
|
// 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) {
|
if (musicLoaded) {
|
||||||
@ -1429,12 +1430,12 @@ void TetrisApp::Impl::runLoop()
|
|||||||
break;
|
break;
|
||||||
case AppState::Menu:
|
case AppState::Menu:
|
||||||
if (!mainScreenTex) {
|
if (!mainScreenTex) {
|
||||||
mainScreenTex = assetLoader.getTexture("assets/images/main_screen.png");
|
mainScreenTex = assetLoader.getTexture(Assets::MAIN_SCREEN);
|
||||||
}
|
}
|
||||||
if (!mainScreenTex) {
|
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) {
|
if (loaded) {
|
||||||
assetLoader.adoptTexture("assets/images/main_screen.png", loaded);
|
assetLoader.adoptTexture(Assets::MAIN_SCREEN, loaded);
|
||||||
mainScreenTex = 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