MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / ScriptableUICallback

Method ScriptableUICallback

Source/Main/engine.cpp:6250–6422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6248}
6249
6250void Engine::ScriptableUICallback(const std::string& level) {
6251 LOGW << "Got a callback to switch to: " << level << std::endl;
6252
6253 if (config["global_time_scale_mult"].toNumber<float>() < 0.1f) {
6254 config.GetRef("global_time_scale_mult") = 0.1f;
6255 }
6256 game_timer.target_time_scale = config["global_time_scale_mult"].toNumber<float>();
6257 current_global_scale_mult = config["global_time_scale_mult"].toNumber<float>();
6258
6259 if (hasEnding(level, ".as")) {
6260 std::string short_path = script_dir_path + level;
6261 const std::string& long_path = level;
6262
6263 // First check if a full path was entered.
6264 if (FileExists(long_path, kAnyPath)) {
6265 LOGI << "L " << long_path << std::endl;
6266 Path path = FindFilePath(long_path, kAnyPath);
6267 QueueState(EngineState("", kEngineScriptableUIState, path));
6268 }
6269 // Then check if it a path relative to script_dir_path as root.
6270 else if (FileExists(short_path, kAnyPath)) {
6271 LOGI << "S " << long_path << std::endl;
6272 Path path = FindFilePath(short_path, kAnyPath);
6273 QueueState(EngineState("", kEngineScriptableUIState, path));
6274 } else {
6275 std::string message = "Unable to find script: " + short_path + " or " + long_path + ". Will not change state";
6276
6277 DisplayError("Unable to find script", message.c_str(), _ok, true);
6278 }
6279 } else if (hasEnding(level, ".xml")) {
6280 std::string short_path = "Data/Levels/" + level;
6281 const std::string& long_path = level;
6282
6283 EngineStateType target_state_type = kEngineLevelState;
6284 if (current_engine_state_.type == kEngineEditorLevelState) {
6285 target_state_type = kEngineEditorLevelState;
6286 }
6287
6288 Path level_path;
6289 // First check if a full path was entered.
6290 if (FileExists(long_path, kAnyPath)) {
6291 level_path = FindFilePath(long_path, kAnyPath);
6292 }
6293 // Then check if it a path relative to Data/Levels as root.
6294 else if (FileExists(short_path, kAnyPath)) {
6295 level_path = FindFilePath(short_path, kAnyPath);
6296 }
6297
6298 if (level_path.isValid()) {
6299 LevelInfoAssetRef levelinfo = Engine::Instance()->GetAssetManager()->LoadSync<LevelInfoAsset>(level_path.GetFullPath());
6300 std::string level_id;
6301 if (levelinfo.valid()) {
6302 level_id = levelinfo->GetName();
6303 }
6304
6305 ScriptableCampaign* sc = GetCurrentCampaign();
6306 if (sc) {
6307 std::string campaign_id = sc->GetCampaignID();

Callers 8

StopMultiplayerMethod · 0.80
ExecuteMethod · 0.80
LevelMenuItemFunction · 0.80
DrawImGuiFunction · 0.80
ASLoadLevelFunction · 0.80
ASLoadLevelIDFunction · 0.80
ASSetCampaignIDFunction · 0.80

Calls 15

hasEndingFunction · 0.85
FileExistsFunction · 0.85
FindFilePathFunction · 0.85
EngineStateClass · 0.85
hasBeginningFunction · 0.85
GetAssetManagerMethod · 0.80
GetFullPathMethod · 0.80
GetCampaignIDMethod · 0.80
GetCampaignMethod · 0.80
CanGoBackMethod · 0.80
StopMultiplayerMethod · 0.80
DisplayErrorFunction · 0.50

Tested by

no test coverage detected