| 136 | } |
| 137 | |
| 138 | void Sprite_Actor::SetAnimationState(int state, LoopState loop, int animation_id) { |
| 139 | // Default value is 100 (function called with val+1) |
| 140 | // 100 maps all states to "Bad state" (7) |
| 141 | if (state == 101) { |
| 142 | state = 7; |
| 143 | } |
| 144 | |
| 145 | anim_state = state; |
| 146 | |
| 147 | loop_state = loop; |
| 148 | |
| 149 | cycle = 0; |
| 150 | |
| 151 | idling = false; |
| 152 | |
| 153 | auto* battler = GetBattler(); |
| 154 | |
| 155 | if (battler->GetBattleAnimationId() > 0) { |
| 156 | const lcf::rpg::BattlerAnimation* anim = lcf::ReaderUtil::GetElement(lcf::Data::battleranimations, battler->GetBattleAnimationId()); |
| 157 | if (!anim) { |
| 158 | Output::Warning("Invalid battler animation ID {}", battler->GetBattleAnimationId()); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | const auto* ext = lcf::ReaderUtil::GetElement(anim->poses, anim_state); |
| 163 | if (!ext) { |
| 164 | Output::Warning("Animation {}: Invalid battler anim-extension state {}", anim->ID, anim_state); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | std::string_view sprite_file = ext->battler_name; |
| 169 | |
| 170 | if (ext->animation_type == lcf::rpg::BattlerAnimationPose::AnimType_battle) { |
| 171 | do_not_draw = false; |
| 172 | SetBitmap(BitmapRef()); |
| 173 | if (animation_id == 0) { |
| 174 | animation_id = ext->battle_animation_id; |
| 175 | } |
| 176 | lcf::rpg::Animation* battle_anim = lcf::ReaderUtil::GetElement(lcf::Data::animations, animation_id); |
| 177 | if (!battle_anim) { |
| 178 | Output::Warning("Invalid battle animation ID {}", animation_id); |
| 179 | animation.reset(); |
| 180 | } else { |
| 181 | animation.reset(new BattleAnimationBattler(*battle_anim, { battler })); |
| 182 | animation->SetZ(GetZ()); |
| 183 | } |
| 184 | animation->SetInvert(battler->IsDirectionFlipped()); |
| 185 | } |
| 186 | else { |
| 187 | do_not_draw = sprite_file.empty(); |
| 188 | animation.reset(); |
| 189 | if (!sprite_file.empty()) { |
| 190 | FileRequestAsync* request = AsyncHandler::RequestFile("BattleCharSet", sprite_file); |
| 191 | request->SetGraphicFile(true); |
| 192 | request_id = request->Bind(&Sprite_Actor::OnBattlercharsetReady, this, ext->battler_index); |
| 193 | request->Start(); |
| 194 | } |
| 195 | } |
no test coverage detected