fix(player): llegeix sprite.size al loadFrom (frameWidth/Height ja no existeixen)
This commit is contained in:
1 parent
d5a73a7dad
commit
1af43ef052
1 file changed
+14
-2
@@ -25,6 +25,19 @@ namespace {
|
||||
// repòs i no contribueix a la velocitat.
|
||||
constexpr Sint16 STICK_DEADZONE = 12000;
|
||||
|
||||
// Llegeix la mida del frame des del bloc `sprite: { path, size: [w, h] }`
|
||||
// (mateix format que la resta de plantilles d'entitat, vegeu
|
||||
// AnimatedSprite). Extracció per mantenir `Player::loadFrom` sota el
|
||||
// llindar de complexitat cognitiva (25).
|
||||
void readSpriteSize(const fkyaml::node& yaml, const std::string& yaml_path, int& w, int& h) {
|
||||
if (!yaml.contains("sprite") || !yaml["sprite"].contains("size")) {
|
||||
throw std::runtime_error("Player: manca `sprite.size` a " + yaml_path);
|
||||
}
|
||||
const auto& size_node = yaml["sprite"]["size"];
|
||||
w = size_node[0].get_value<int>();
|
||||
h = size_node[1].get_value<int>();
|
||||
}
|
||||
|
||||
// Acumula la contribució del mando assignat al jugador (cruceta +
|
||||
// stick esquerre) sobre els acumuladors de velocitat. Extracció
|
||||
// d'`update()` per a mantenir la complexitat cognitiva sota llindar
|
||||
@@ -60,8 +73,7 @@ void Player::loadFrom(const std::string& yaml_path) {
|
||||
const auto* end = begin + bytes.size();
|
||||
auto yaml = fkyaml::node::deserialize(begin, end);
|
||||
|
||||
sprite_w = yaml["frameWidth"].get_value<int>();
|
||||
sprite_h = yaml["frameHeight"].get_value<int>();
|
||||
readSpriteSize(yaml, yaml_path, sprite_w, sprite_h);
|
||||
|
||||
if (!yaml.contains("collision")) {
|
||||
throw std::runtime_error("Player: manca bloc `collision:` a " + yaml_path);
|
||||
|
||||
Reference in new issue
Block a user