| 588 | } |
| 589 | |
| 590 | void InitializeScripting(int levelIndex, bool loadGame) |
| 591 | { |
| 592 | TENLog("Loading level script...", LogLevel::Info); |
| 593 | |
| 594 | g_GameStringsHandler->ClearDisplayStrings(); |
| 595 | g_GameScript->ResetScripts(!levelIndex || loadGame); |
| 596 | |
| 597 | const auto& level = *g_GameFlow->GetLevel(levelIndex); |
| 598 | |
| 599 | // Run level script if it exists. |
| 600 | if (!level.ScriptFileName.empty()) |
| 601 | { |
| 602 | auto levelScriptName = g_GameFlow->GetGameDir() + level.ScriptFileName; |
| 603 | if (std::filesystem::is_regular_file(levelScriptName)) |
| 604 | { |
| 605 | g_GameScript->ExecuteScriptFile(levelScriptName); |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | TENLog("Level script not found: " + levelScriptName, LogLevel::Warning); |
| 610 | } |
| 611 | |
| 612 | g_GameScript->InitCallbacks(); |
| 613 | g_GameStringsHandler->SetCallbackDrawString([](const std::string& key, D3DCOLOR color, const Vec2& pos, Vec2& area, float scale, int flags) |
| 614 | { |
| 615 | g_Renderer.AddString( |
| 616 | key, |
| 617 | Vector2((pos.x / g_Configuration.ScreenWidth) * DISPLAY_SPACE_RES.x, |
| 618 | (pos.y / g_Configuration.ScreenHeight) * DISPLAY_SPACE_RES.y), |
| 619 | Vector2((area.x / g_Configuration.ScreenWidth) * DISPLAY_SPACE_RES.x, |
| 620 | (area.y / g_Configuration.ScreenHeight) * DISPLAY_SPACE_RES.y), |
| 621 | Color(color), scale, flags); |
| 622 | }); |
| 623 | } |
| 624 | |
| 625 | // Play default background music. |
| 626 | if (!loadGame) |
| 627 | PlaySoundTrack(level.GetAmbientTrack(), SoundTrackType::BGM, 0, SOUND_XFADETIME_LEVELJUMP); |
| 628 | } |
| 629 | |
| 630 | void DeInitializeScripting(int levelIndex, GameStatus reason) |
| 631 | { |
no test coverage detected