refactor(log): migra core/resources i core/system a Log::
- resource_pack.cpp i resource_cache.cpp: tots els std::cerr passen a Log::error. - director.cpp: std::cout/cerr/fprintf → Log::info / error / critical segons severitat. - printWithDots (utils.cpp): ara és un wrapper sobre Log::info que manté l'amplada total (~50 chars) reproduint l'alineació de punts. Els callers pasen el tag sense " : " (ja l'afegeix el logger). - pack_resources: afegit log.cpp i SDL3 al target perquè resource_pack.cpp ara depèn de Log::. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1243b457be
commit
6e99fd0a8b
8 files changed
+51
-44
No files matched your search
@@ -1,12 +1,12 @@
|
||||
#include "core/resources/resource_cache.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "core/audio/jail_audio.hpp"
|
||||
#include "core/resources/palette_loader.hpp"
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
// Deleters dels recursos d'àudio: necessiten veure el tipus complet de
|
||||
@@ -37,19 +37,19 @@ namespace Resource {
|
||||
throw std::runtime_error("Cache: cannot load animation " + file_path);
|
||||
}
|
||||
animations_.emplace_back(AnimationResource{.name = name, .yaml_data = std::move(bytes)});
|
||||
printWithDots("Animation : ", getFileName(file_path), "[ LOADED ]");
|
||||
printWithDots("Animation", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
void Cache::loadPalette(const std::string& name, const std::string& file_path) {
|
||||
auto palette = PaletteLoader::loadFromFile(file_path);
|
||||
palettes_.emplace_back(PaletteResource{.name = name, .palette = palette});
|
||||
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
||||
printWithDots("Palette", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
auto Cache::getSurface(const std::string& name) -> std::shared_ptr<Surface> {
|
||||
auto it = std::ranges::find_if(surfaces_, [&name](const auto& s) { return s.name == name; });
|
||||
if (it == surfaces_.end()) {
|
||||
std::cerr << "Cache: surface not found: " << name << '\n';
|
||||
Log::error("Cache", "surface not found: {}", name);
|
||||
throw std::runtime_error("Surface not found: " + name);
|
||||
}
|
||||
return it->surface;
|
||||
@@ -58,7 +58,7 @@ namespace Resource {
|
||||
auto Cache::getAnimationData(const std::string& name) -> const AnimationResource& {
|
||||
auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
|
||||
if (it == animations_.end()) {
|
||||
std::cerr << "Cache: animation not found: " << name << '\n';
|
||||
Log::error("Cache", "animation not found: {}", name);
|
||||
throw std::runtime_error("Animation not found: " + name);
|
||||
}
|
||||
return *it;
|
||||
@@ -67,7 +67,7 @@ namespace Resource {
|
||||
auto Cache::getPalette(const std::string& name) -> const Palette& {
|
||||
auto it = std::ranges::find_if(palettes_, [&name](const auto& p) { return p.name == name; });
|
||||
if (it == palettes_.end()) {
|
||||
std::cerr << "Cache: palette not found: " << name << '\n';
|
||||
Log::error("Cache", "palette not found: {}", name);
|
||||
throw std::runtime_error("Palette not found: " + name);
|
||||
}
|
||||
return it->palette;
|
||||
@@ -83,7 +83,7 @@ namespace Resource {
|
||||
throw std::runtime_error("Cache: Ja::loadMusic failed for " + file_path);
|
||||
}
|
||||
musics_.emplace_back(MusicResource{.name = name, .music = std::unique_ptr<Ja::Music, MusicDeleter>(raw)});
|
||||
printWithDots("Music : ", getFileName(file_path), "[ LOADED ]");
|
||||
printWithDots("Music", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
void Cache::loadSound(const std::string& name, const std::string& file_path) {
|
||||
@@ -96,13 +96,13 @@ namespace Resource {
|
||||
throw std::runtime_error("Cache: Ja::loadSound failed for " + file_path);
|
||||
}
|
||||
sounds_.emplace_back(SoundResource{.name = name, .sound = std::unique_ptr<Ja::Sound, SoundDeleter>(raw)});
|
||||
printWithDots("Sound : ", getFileName(file_path), "[ LOADED ]");
|
||||
printWithDots("Sound", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
|
||||
auto Cache::getMusic(const std::string& name) -> Ja::Music* {
|
||||
auto it = std::ranges::find_if(musics_, [&name](const auto& m) { return m.name == name; });
|
||||
if (it == musics_.end()) {
|
||||
std::cerr << "Cache: music not found: " << name << '\n';
|
||||
Log::error("Cache", "music not found: {}", name);
|
||||
throw std::runtime_error("Music not found: " + name);
|
||||
}
|
||||
return it->music.get();
|
||||
@@ -111,7 +111,7 @@ namespace Resource {
|
||||
auto Cache::getSound(const std::string& name) -> Ja::Sound* {
|
||||
auto it = std::ranges::find_if(sounds_, [&name](const auto& s) { return s.name == name; });
|
||||
if (it == sounds_.end()) {
|
||||
std::cerr << "Cache: sound not found: " << name << '\n';
|
||||
Log::error("Cache", "sound not found: {}", name);
|
||||
throw std::runtime_error("Sound not found: " + name);
|
||||
}
|
||||
return it->sound.get();
|
||||
|
||||
Reference in new issue
Block a user