Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPBGE: Add the option to disable component execution on game start #694

Merged
merged 3 commits into from
May 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions source/blender/editors/space_logic/logic_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "BKE_main.h"
#include "BKE_sca.h"
#include "BKE_python_component.h"
#include "BKE_global.h"
#include "BKE_report.h"

#include "ED_logic.h"
#include "ED_object.h"
Expand Down Expand Up @@ -746,6 +748,11 @@ static int component_add_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
char import[MAX_NAME];

if ((G.f & G_SCRIPT_AUTOEXEC) == 0) {
BKE_report(op->reports, RPT_WARNING, "Python script/component auto-execution disable, look in the userpref to activate...");
return OPERATOR_CANCELLED;
}

if (!ob) {
return OPERATOR_CANCELLED;
}
Expand Down Expand Up @@ -836,6 +843,11 @@ static int component_reload_exec(bContext *C, wmOperator *op)
PythonComponent *pc = NULL, *prev_pc = NULL;
int index = RNA_int_get(op->ptr, "index");

if ((G.f & G_SCRIPT_AUTOEXEC) == 0) {
BKE_report(op->reports, RPT_WARNING, "Python script/component auto-execution disable, look in the userpref to activate...");
return OPERATOR_CANCELLED;
}

if(!ob) {
return OPERATOR_CANCELLED;
}
Expand Down
2 changes: 1 addition & 1 deletion source/blender/makesrna/intern/rna_userdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -4036,7 +4036,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)

prop = RNA_def_property(srna, "use_scripts_auto_execute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_SCRIPT_AUTOEXEC_DISABLE);
RNA_def_property_ui_text(prop, "Auto Run Python Scripts",
RNA_def_property_ui_text(prop, "Auto Run Python Scripts and Components",
"Allow any .blend file to run scripts automatically "
"(unsafe with blend files from an untrusted source)");
RNA_def_property_update(prop, 0, "rna_userdef_script_autoexec_update");
Expand Down
23 changes: 14 additions & 9 deletions source/gameengine/Converter/BL_BlenderDataConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,18 +1730,23 @@ void BL_ConvertBlenderObjects(struct Main *maggie,
gameobj->ResetState();
}

// Convert the python components of each object.
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}
// Convert the python components of each object if the component execution is available.
if (G.f & G_SCRIPT_AUTOEXEC) {
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}

for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
}
}
}
else {
CM_Warning("Python components auto-execution disabled");
}

// Cleanup converted set of group objects.
convertedlist->Release();
Expand Down