feat(scenes): data/scenes/game.yaml amb timings i corbes de transició
This commit is contained in:
1 parent
651db50a93
commit
368f9d2d6a
4 files changed
+117
No files matched your search
@@ -74,6 +74,63 @@ namespace {
|
||||
return yaml[key].get_value<float>();
|
||||
}
|
||||
|
||||
// Llegeix un sub-camp sencer del bloc `parent` (o el fallback) sense
|
||||
// imprimir res. Pensat per a la lectura puntual del data/scenes/game.yaml.
|
||||
auto readChildInt(const fkyaml::node& parent, const char* key, int fallback) -> int {
|
||||
if (!parent.contains(key)) { return fallback; }
|
||||
return parent[key].get_value<int>();
|
||||
}
|
||||
|
||||
// Carrega `data/scenes/game.yaml` i emplena un SceneTransitionConfig.
|
||||
// Si el fitxer falta o algun camp no hi és, els valors de fallback
|
||||
// que ja porta l'estructura es conserven. Les dues corbes es resolen
|
||||
// per nom amb `UiConfig::curveByName` (mateix mecanisme que la pausa);
|
||||
// si el nom és desconegut, cau a `Easing::linear` amb warning al log.
|
||||
auto readSceneConfig(const std::string& yaml_path) -> GameScene::SceneTransitionConfig {
|
||||
GameScene::SceneTransitionConfig cfg{};
|
||||
cfg.text_enter_curve = UiConfig::curveByName("outCubic");
|
||||
cfg.text_exit_curve = UiConfig::curveByName("inCubic");
|
||||
|
||||
auto bytes = Resource::Helper::loadFile(yaml_path);
|
||||
if (bytes.empty()) {
|
||||
std::cout << "GameScene: " << yaml_path << " absent — uso fallbacks compilats\n";
|
||||
return cfg;
|
||||
}
|
||||
const auto* begin = reinterpret_cast<const char*>(bytes.data());
|
||||
const auto* end = begin + bytes.size();
|
||||
auto yaml = fkyaml::node::deserialize(begin, end);
|
||||
|
||||
if (yaml.contains("room_intro")) {
|
||||
const auto& n = yaml["room_intro"];
|
||||
cfg.intro_fade_in_ms = readChildInt(n, "fade_in_ms", cfg.intro_fade_in_ms);
|
||||
cfg.intro_text_delay_ms = readChildInt(n, "text_delay_ms", cfg.intro_text_delay_ms);
|
||||
cfg.intro_text_enter_ms = readChildInt(n, "text_enter_ms", cfg.intro_text_enter_ms);
|
||||
cfg.intro_text_hold_ms = readChildInt(n, "text_hold_ms", cfg.intro_text_hold_ms);
|
||||
cfg.intro_text_exit_ms = readChildInt(n, "text_exit_ms", cfg.intro_text_exit_ms);
|
||||
}
|
||||
if (yaml.contains("room_outro")) {
|
||||
const auto& n = yaml["room_outro"];
|
||||
cfg.outro_text_enter_ms = readChildInt(n, "text_enter_ms", cfg.outro_text_enter_ms);
|
||||
cfg.outro_text_hold_ms = readChildInt(n, "text_hold_ms", cfg.outro_text_hold_ms);
|
||||
cfg.outro_text_exit_ms = readChildInt(n, "text_exit_ms", cfg.outro_text_exit_ms);
|
||||
cfg.outro_fade_out_ms = readChildInt(n, "fade_out_ms", cfg.outro_fade_out_ms);
|
||||
}
|
||||
if (yaml.contains("text")) {
|
||||
const auto& n = yaml["text"];
|
||||
if (n.contains("enter_curve")) {
|
||||
cfg.text_enter_curve = UiConfig::curveByName(n["enter_curve"].get_value<std::string>());
|
||||
}
|
||||
if (n.contains("exit_curve")) {
|
||||
cfg.text_exit_curve = UiConfig::curveByName(n["exit_curve"].get_value<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "GameScene: timings carregats des de " << yaml_path
|
||||
<< " (intro fade " << cfg.intro_fade_in_ms
|
||||
<< "ms, outro fade " << cfg.outro_fade_out_ms << "ms)\n";
|
||||
return cfg;
|
||||
}
|
||||
|
||||
// Comprova si `a` i `b` se solapen amb una tolerància positiva al
|
||||
// contacte perfecte (cantos que es toquen = no-solapament). SDL3 ja
|
||||
// ofereix `SDL_HasRectIntersectionFloat`, però aquí volem la mateixa
|
||||
@@ -398,6 +455,10 @@ GameScene::GameScene(Config config)
|
||||
pause_font_ = std::make_shared<Text>(pause_surface, UiConfig::get().placeholderFont().fnt);
|
||||
pause_font_->setDefaultKerning(UiConfig::get().placeholderFont().kerning);
|
||||
|
||||
// Timings i corbes de la FSM de sala. Llegits del YAML una sola
|
||||
// vegada; canvis requereixen reiniciar el joc.
|
||||
transition_config_ = readSceneConfig(Defaults::GameScene::CONFIG_YAML);
|
||||
|
||||
// Log d'estat inicial: la FSM arrenca a ROOM_INTRO. En aquesta fita
|
||||
// les transicions són instantànies (sense fades ni text) i el primer
|
||||
// tick d'`updateRoomTransition` ja saltarà a PLAYING.
|
||||
|
||||
Reference in new issue
Block a user