diff --git a/ChapterMaster.yyp b/ChapterMaster.yyp index 1599b11422..1fdacf59dc 100644 --- a/ChapterMaster.yyp +++ b/ChapterMaster.yyp @@ -737,7 +737,7 @@ {"id":{"name":"__HTTPParent","path":"scripts/__HTTPParent/__HTTPParent.yy",},}, {"id":{"name":"__StructToDSMap","path":"scripts/__StructToDSMap/__StructToDSMap.yy",},}, {"id":{"name":"Armamentarium","path":"scripts/Armamentarium/Armamentarium.yy",},}, - {"id":{"name":"artifact_functions","path":"scripts/artifact_functions/artifact_functions.yy",},}, + {"id":{"name":"scr_artifact_functions","path":"scripts/scr_artifact_functions/scr_artifact_functions.yy",},}, {"id":{"name":"ArtifactStruct","path":"scripts/ArtifactStruct/ArtifactStruct.yy",},}, {"id":{"name":"AudioManager","path":"scripts/AudioManager/AudioManager.yy",},}, {"id":{"name":"ColourItem","path":"scripts/ColourItem/ColourItem.yy",},}, @@ -767,7 +767,7 @@ {"id":{"name":"HTTPGet","path":"scripts/HTTPGet/HTTPGet.yy",},}, {"id":{"name":"HTTPGetFile","path":"scripts/HTTPGetFile/HTTPGetFile.yy",},}, {"id":{"name":"HTTPRequest","path":"scripts/HTTPRequest/HTTPRequest.yy",},}, - {"id":{"name":"instance_create","path":"scripts/instance_create/instance_create.yy",},}, + {"id":{"name":"scr_instance_functions","path":"scripts/scr_instance_functions/scr_instance_functions.yy",},}, {"id":{"name":"is_specialist","path":"scripts/is_specialist/is_specialist.yy",},}, {"id":{"name":"JsonFileListLoader","path":"scripts/JsonFileListLoader/JsonFileListLoader.yy",},}, {"id":{"name":"LocalizationManager","path":"scripts/LocalizationManager/LocalizationManager.yy",},}, diff --git a/objects/obj_fleet/Create_0.gml b/objects/obj_fleet/Create_0.gml index 9beb450e3a..b6bb644746 100644 --- a/objects/obj_fleet/Create_0.gml +++ b/objects/obj_fleet/Create_0.gml @@ -51,11 +51,7 @@ pla_fleet = instance_nearest(x, y, obj_p_fleet); ene_fleet = instance_nearest(x, y, obj_en_fleet); victory = false; -instance_deactivate_all(true); -instance_activate_object(obj_controller); -instance_activate_object(obj_ini); -instance_activate_object(obj_cursor); -instance_activate_object(obj_img); +instance_deactivate_all_safe(); column[0] = ""; column_width[0] = 0; // This is determined at the pre-battle screen diff --git a/objects/obj_popup/Alarm_0.gml b/objects/obj_popup/Alarm_0.gml index f5fd2074f1..0e7178a9b1 100644 --- a/objects/obj_popup/Alarm_0.gml +++ b/objects/obj_popup/Alarm_0.gml @@ -21,9 +21,7 @@ if (battle_special == 3.1) { obj_ncombat.threat = 4; obj_ncombat.formation_set = 3; - instance_deactivate_all(true); - instance_activate_object(obj_ini); - instance_activate_object(obj_controller); + instance_deactivate_all_safe(); instance_activate_object(obj_ncombat); _roster = new Roster(); diff --git a/objects/obj_popup/Destroy_0.gml b/objects/obj_popup/Destroy_0.gml index 368b33e8b1..2dc93e5032 100644 --- a/objects/obj_popup/Destroy_0.gml +++ b/objects/obj_popup/Destroy_0.gml @@ -4,9 +4,7 @@ if ((image == "chaos_symbol") && (title == "Concealed Heresy") && instance_exist // ** Starts the battle ** is_in_combat = true; - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_drop_select); instance_create(0, 0, obj_ncombat); @@ -97,9 +95,7 @@ if (instance_exists(obj_controller)) { scr_civil_roster(obj_ncombat.battle_loc, obj_ncombat.battle_id, true); - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_temp_meeting); instance_activate_object(obj_ncombat); instance_activate_object(obj_centerline); diff --git a/objects/obj_star_select/Mouse_50.gml b/objects/obj_star_select/Mouse_50.gml index ee6a23ade0..c936e05ebb 100644 --- a/objects/obj_star_select/Mouse_50.gml +++ b/objects/obj_star_select/Mouse_50.gml @@ -175,9 +175,7 @@ if (!instance_exists(obj_saveload) && !instance_exists(obj_drop_select)) { combating = 1; - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(p_fleet); instance_activate_object(obj_star); diff --git a/objects/obj_turn_end/Mouse_56.gml b/objects/obj_turn_end/Mouse_56.gml index 8fc167c5c4..a67db2d289 100644 --- a/objects/obj_turn_end/Mouse_56.gml +++ b/objects/obj_turn_end/Mouse_56.gml @@ -83,11 +83,8 @@ if (!instance_exists(obj_saveload) && !instance_exists(obj_popup) && !instance_e add_fleet_ships_to_combat(battle_pobject[current_battle], _battle_instance); - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(_battle_instance); - instance_activate_object(obj_cursor); } } @@ -111,9 +108,7 @@ if (!instance_exists(obj_saveload) && !instance_exists(obj_popup) && !instance_e combating = 1; - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(battle_object[current_battle]); var _battle_obj = battle_object[current_battle]; diff --git a/scripts/GitHubOAuth/GitHubOAuth.gml b/scripts/GitHubOAuth/GitHubOAuth.gml index e3750fb772..63cc0a5aaa 100644 --- a/scripts/GitHubOAuth/GitHubOAuth.gml +++ b/scripts/GitHubOAuth/GitHubOAuth.gml @@ -22,8 +22,8 @@ function GitHubOAuth(_clientID, _clientSecret = undefined) constructor { __GitHubError("requestAuthenticationViaWebPage: Web-flow authentication is only supported on desktop platforms, please use device-flow for non-desktop platforms"); } - // Ensure server does not exist - if (__github_worker.__server != undefined || __GitHubSystem().__pollTimesource != undefined) { + // Ensure no active request (centralized check handles deactivated worker) + if (__GitHubHasActiveRequest()) { __GitHubWarn("requestAuthenticationViaWebPage: Request is already in progress, ensure there is not another authentication request in-progress."); return; } @@ -49,8 +49,8 @@ function GitHubOAuth(_clientID, _clientSecret = undefined) constructor { /// @arg {Array.String} scope An array of authentication scopes. /// @returns {Struct.GitHubRequest} static requestAuthentication = function(_scope) { - // Ensure server does not exist - if (__GitHubSystem().__pollTimesource != undefined || __github_worker.__server != undefined) { + // Ensure no active request (centralized check handles deactivated worker) + if (__GitHubHasActiveRequest()) { __GitHubWarn("requestAuthentication: Request is already in progress, ensure there is not another authentication request in-progress."); return; } @@ -134,7 +134,7 @@ function GitHubOAuth(_clientID, _clientSecret = undefined) constructor { /// @desc Returns if there is an active authentication request in-progress. /// @returns {Bool} static hasActiveRequest = function() { - return __GitHubSystem().__pollTimesource != undefined || __github_worker.__server != undefined; + return __GitHubHasActiveRequest(); }; /// @func setAuthenticationCallback(callback) @@ -371,6 +371,13 @@ function GitHubOAuth(_clientID, _clientSecret = undefined) constructor { }; } +/// @ignore +// Centralized active-request check - ensures worker is visible before checking __server (deactivated hides handle) +function __GitHubHasActiveRequest() { + __GitHubEnsureInstance(); + return __GitHubSystem().__pollTimesource != undefined || (__github_worker.__server != undefined); +} + /// Stops and destroys the device-flow polling timesource and clears the poll state. /// Shared by the timeout branch, terminal-error path, success callback, errorback /// and cancelAuthentication so lifecycle handling cannot diverge. diff --git a/scripts/__GitHubRequestServerShutdown/__GitHubRequestServerShutdown.gml b/scripts/__GitHubRequestServerShutdown/__GitHubRequestServerShutdown.gml index 977796c1b8..df81e9ff4c 100644 --- a/scripts/__GitHubRequestServerShutdown/__GitHubRequestServerShutdown.gml +++ b/scripts/__GitHubRequestServerShutdown/__GitHubRequestServerShutdown.gml @@ -3,6 +3,8 @@ /// Request a server shutdown /// @ignore function __GitHubRequestServerShutdown() { + __GitHubEnsureInstance(); + // Only schedule a shutdown when a web-flow server exists. Starting the delayed shutdown // without a server would destroy a server created by a later request. if (__github_worker.__server == undefined) { diff --git a/scripts/__GitHubServerShutdown/__GitHubServerShutdown.gml b/scripts/__GitHubServerShutdown/__GitHubServerShutdown.gml index 7bcc19ccce..acc5e5d463 100644 --- a/scripts/__GitHubServerShutdown/__GitHubServerShutdown.gml +++ b/scripts/__GitHubServerShutdown/__GitHubServerShutdown.gml @@ -3,6 +3,8 @@ /// Actual shutdown /// @ignore function __GitHubServerShutdown() { + __GitHubEnsureInstance(); + // Check server for an active web-flow authentication if (__github_worker.__server != undefined) { // Destroy the network diff --git a/scripts/__GitHubTick/__GitHubTick.gml b/scripts/__GitHubTick/__GitHubTick.gml index 0231ef4df5..a8c4e0ea38 100644 --- a/scripts/__GitHubTick/__GitHubTick.gml +++ b/scripts/__GitHubTick/__GitHubTick.gml @@ -3,17 +3,29 @@ /// @ignore function __GitHubTick() { var _system = __GitHubSystem(); + var _expire = _system.__authenticationExpireTime; - if (_system.__authenticationExpireTime != undefined && _system.__authenticationExpireTime > 0) { + if (_expire != undefined && _expire > 0) { _system.__authenticationExpireTime--; - } else if (_system.__authenticationExpireTime != undefined && _system.__authenticationExpireTime <= 0 && __github_worker.__server != undefined && !__GitHubServerShuttingDown()) { - // Always request the shutdown first so a throwing timeout callback - // cannot leave the authentication server active - __GitHubRequestServerShutdown(); + return; + } + + if (_expire == undefined || _expire > 0) { + return; + } + + __GitHubEnsureInstance(); + + if (__github_worker.__server == undefined || __GitHubServerShuttingDown()) { + return; + } + + // Always request the shutdown first so a throwing timeout callback + // cannot leave the authentication server active + __GitHubRequestServerShutdown(); - // Fire the timeout callback only once per shutdown sequence. - if (is_callable(_system.__authenticationTimeoutCallback)) { - _system.__authenticationTimeoutCallback(); - } + // Fire the timeout callback only once per shutdown sequence. + if (is_callable(_system.__authenticationTimeoutCallback)) { + _system.__authenticationTimeoutCallback(); } } diff --git a/scripts/__GitHubWarn/__GitHubWarn.gml b/scripts/__GitHubWarn/__GitHubWarn.gml index 30dca1561f..7a34396f6e 100644 --- a/scripts/__GitHubWarn/__GitHubWarn.gml +++ b/scripts/__GitHubWarn/__GitHubWarn.gml @@ -2,9 +2,5 @@ /// @ignore function __GitHubWarn(_string) { - if (GITHUB_GML_RUNNING_FROM_IDE) { - show_error($" \nGitHub.gml:\n{_string}\n ", true); - } else { - show_debug_message($"GitHub.gml: Warning! {_string}"); - } + show_debug_message($"GitHub.gml: Warning! {_string}"); } diff --git a/scripts/instance_create/instance_create.yy b/scripts/instance_create/instance_create.yy deleted file mode 100644 index 5ccf8ab83b..0000000000 --- a/scripts/instance_create/instance_create.yy +++ /dev/null @@ -1,13 +0,0 @@ -{ - "$GMScript":"v1", - "%Name":"instance_create", - "isCompatibility":true, - "isDnD":false, - "name":"instance_create", - "parent":{ - "name":"instance", - "path":"folders/Scripts/compatibility/instance.yy", - }, - "resourceType":"GMScript", - "resourceVersion":"2.0", -} \ No newline at end of file diff --git a/scripts/scr_ancient_ruins/scr_ancient_ruins.gml b/scripts/scr_ancient_ruins/scr_ancient_ruins.gml index 479d61743d..76bc8a6a9b 100644 --- a/scripts/scr_ancient_ruins/scr_ancient_ruins.gml +++ b/scripts/scr_ancient_ruins/scr_ancient_ruins.gml @@ -18,9 +18,7 @@ function scr_ancient_ruins_setup() { /// @self Struct.PlanetData function scr_ruins_suprise_attack_player() { try { - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_star_select); instance_activate_object(obj_star); instance_activate_object(obj_ground_mission); @@ -342,7 +340,7 @@ function ruins_exploration_main_sequence() { add_option({ str1: "To Battle", choice_func: function() { - instance_deactivate_all(true); + instance_deactivate_all_safe(); instance_activate_object(obj_ground_mission); instance_activate_object(obj_popup); var _explore_feature = obj_ground_mission.explore_feature; diff --git a/scripts/artifact_functions/artifact_functions.gml b/scripts/scr_artifact_functions/scr_artifact_functions.gml similarity index 100% rename from scripts/artifact_functions/artifact_functions.gml rename to scripts/scr_artifact_functions/scr_artifact_functions.gml diff --git a/scripts/artifact_functions/artifact_functions.yy b/scripts/scr_artifact_functions/scr_artifact_functions.yy similarity index 73% rename from scripts/artifact_functions/artifact_functions.yy rename to scripts/scr_artifact_functions/scr_artifact_functions.yy index 4453233631..05f9f24d28 100644 --- a/scripts/artifact_functions/artifact_functions.yy +++ b/scripts/scr_artifact_functions/scr_artifact_functions.yy @@ -1,9 +1,9 @@ { "$GMScript":"v1", - "%Name":"artifact_functions", + "%Name":"scr_artifact_functions", "isCompatibility":false, "isDnD":false, - "name":"artifact_functions", + "name":"scr_artifact_functions", "parent":{ "name":"Scripts", "path":"folders/Scripts.yy", diff --git a/scripts/scr_dialogue/scr_dialogue.gml b/scripts/scr_dialogue/scr_dialogue.gml index afdb0a2c5e..ca9c4dfe58 100644 --- a/scripts/scr_dialogue/scr_dialogue.gml +++ b/scripts/scr_dialogue/scr_dialogue.gml @@ -452,9 +452,7 @@ function scr_dialogue(diplo_keyphrase, data = {}) { } scr_civil_roster(obj_ncombat.battle_loc, obj_ncombat.battle_id, true); - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_temp_meeting); instance_activate_object(obj_ncombat); instance_activate_object(obj_centerline); diff --git a/scripts/scr_drop_select_function/scr_drop_select_function.gml b/scripts/scr_drop_select_function/scr_drop_select_function.gml index bf88902bff..f68ce53f45 100644 --- a/scripts/scr_drop_select_function/scr_drop_select_function.gml +++ b/scripts/scr_drop_select_function/scr_drop_select_function.gml @@ -228,9 +228,7 @@ function drop_select_unit_selection() { obj_controller.last_raid_form = formation_possible[formation_current]; } - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_drop_select); // 135 ; temporary balancing diff --git a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml index 970edeae0c..8d265d0714 100644 --- a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml +++ b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml @@ -786,9 +786,7 @@ function necron_tomb_mission_sequence() { } if (battle > 0) { - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_star); instance_create(0, 0, obj_ncombat); diff --git a/scripts/instance_create/instance_create.gml b/scripts/scr_instance_functions/scr_instance_functions.gml similarity index 64% rename from scripts/instance_create/instance_create.gml rename to scripts/scr_instance_functions/scr_instance_functions.gml index 89d7c8b462..2aa77c974d 100644 --- a/scripts/instance_create/instance_create.gml +++ b/scripts/scr_instance_functions/scr_instance_functions.gml @@ -23,3 +23,16 @@ function instances_exist_any(instance_set = []) { } return _exists; } + +/// @desc Deactivates all instances but preserves critical infrastructure workers. +function instance_deactivate_all_safe() { + instance_deactivate_all(true); + instance_activate_object(__github_worker); + instance_activate_object(obj_persistent); + instance_activate_object(obj_garbage_collector); + instance_activate_object(obj_img); + instance_activate_object(obj_controller); + instance_activate_object(obj_ini); + instance_activate_object(obj_cursor); + instance_activate_object(obj_timer); +} diff --git a/scripts/scr_instance_functions/scr_instance_functions.yy b/scripts/scr_instance_functions/scr_instance_functions.yy new file mode 100644 index 0000000000..603bfd03b4 --- /dev/null +++ b/scripts/scr_instance_functions/scr_instance_functions.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"v1", + "%Name":"scr_instance_functions", + "isCompatibility":false, + "isDnD":false, + "name":"scr_instance_functions", + "parent":{ + "name":"Global Functions", + "path":"folders/Scripts/Global Functions.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/scr_purge_world/scr_purge_world.gml b/scripts/scr_purge_world/scr_purge_world.gml index 698e58142b..d1f7bdeef7 100644 --- a/scripts/scr_purge_world/scr_purge_world.gml +++ b/scripts/scr_purge_world/scr_purge_world.gml @@ -178,9 +178,7 @@ function scr_purge_world(action_type, action_score) { obj_controller.cooldown = 30; combating = 1; // Start battle here - instance_deactivate_all(true); - instance_activate_object(obj_controller); - instance_activate_object(obj_ini); + instance_deactivate_all_safe(); instance_activate_object(obj_drop_select); instance_create(0, 0, obj_ncombat);