MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / InitializeScripting

Function InitializeScripting

TombEngine/Game/control/control.cpp:590–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588}
589
590void 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
630void DeInitializeScripting(int levelIndex, GameStatus reason)
631{

Callers 1

DoLevelFunction · 0.85

Calls 13

TENLogFunction · 0.85
PlaySoundTrackFunction · 0.85
ClearDisplayStringsMethod · 0.80
ResetScriptsMethod · 0.80
GetLevelMethod · 0.80
GetGameDirMethod · 0.80
ExecuteScriptFileMethod · 0.80
InitCallbacksMethod · 0.80
SetCallbackDrawStringMethod · 0.80
AddStringMethod · 0.80
GetAmbientTrackMethod · 0.80
Vector2Function · 0.50

Tested by

no test coverage detected