Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2010-07-11 01:15:10 +0400
committerDalai Felinto <dfelinto@gmail.com>2010-07-11 01:15:10 +0400
commit96a7e478b6ef0c9f4b15e27ab22db548bbab1fe5 (patch)
treec1c326457af385fbe455e310f16d77c7daaf8238 /source/blender/makesrna
parente531f3736df13d9143f4b4c7589d65b12df1ff1b (diff)
Logic Editor Python API: link/unlink logics through python
After initial talk with Matt (awhile ago) we realzed that rna_api would fit well for this instead of an operator. The next step would be to move the current UI code to use the rna funcs instead. Note: it takes the s/c/a as argument, not its name. (e.g. cont.link(actuator=act) ) Sample code to link all the logic bricks between each other: ob = bpy.context.object for cont in ob.game.controllers: for sens in ob.game.sensors: cont.link(sensor=sens) for act in ob.game.actuators: cont.link(actuator=act) For a script to create bricks, link bricks, unlink bricks and remove them: http://www.pasteall.org/14266
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/makesrna.c6
-rw-r--r--source/blender/makesrna/intern/rna_actuator.c2
-rw-r--r--source/blender/makesrna/intern/rna_actuator_api.c72
-rw-r--r--source/blender/makesrna/intern/rna_controller.c2
-rw-r--r--source/blender/makesrna/intern/rna_controller_api.c81
-rw-r--r--source/blender/makesrna/intern/rna_internal.h3
-rw-r--r--source/blender/makesrna/intern/rna_sensor.c2
-rw-r--r--source/blender/makesrna/intern/rna_sensor_api.c72
8 files changed, 237 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index d37f390919d..40f6c1de67e 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -2237,7 +2237,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
{"rna_action.c", "rna_action_api.c", RNA_def_action},
{"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
{"rna_animviz.c", NULL, RNA_def_animviz},
- {"rna_actuator.c", NULL, RNA_def_actuator},
+ {"rna_actuator.c", "rna_actuator_api.c", RNA_def_actuator},
{"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
{"rna_boid.c", NULL, RNA_def_boid},
{"rna_brush.c", NULL, RNA_def_brush},
@@ -2246,7 +2246,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
{"rna_color.c", NULL, RNA_def_color},
{"rna_constraint.c", NULL, RNA_def_constraint},
{"rna_context.c", NULL, RNA_def_context},
- {"rna_controller.c", NULL, RNA_def_controller},
+ {"rna_controller.c", "rna_controller_api.c", RNA_def_controller},
{"rna_curve.c", NULL, RNA_def_curve},
{"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
{"rna_fluidsim.c", NULL, RNA_def_fluidsim},
@@ -2273,7 +2273,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
{"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
{"rna_screen.c", NULL, RNA_def_screen},
{"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
- {"rna_sensor.c", NULL, RNA_def_sensor},
+ {"rna_sensor.c", "rna_sensor_api.c", RNA_def_sensor},
{"rna_sequencer.c", "rna_sequencer_api.c", RNA_def_sequencer},
{"rna_smoke.c", NULL, RNA_def_smoke},
{"rna_space.c", NULL, RNA_def_space},
diff --git a/source/blender/makesrna/intern/rna_actuator.c b/source/blender/makesrna/intern/rna_actuator.c
index 2a29f3332b5..e7031ad8517 100644
--- a/source/blender/makesrna/intern/rna_actuator.c
+++ b/source/blender/makesrna/intern/rna_actuator.c
@@ -486,6 +486,8 @@ void rna_def_actuator(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SHOW);
RNA_def_property_ui_text(prop, "Expanded", "Set actuator expanded in the user interface");
RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+
+ RNA_api_actuator(srna);
}
static void rna_def_action_actuator(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_actuator_api.c b/source/blender/makesrna/intern/rna_actuator_api.c
new file mode 100644
index 00000000000..b61f9e252a6
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_actuator_api.c
@@ -0,0 +1,72 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "WM_types.h"
+#include "RNA_define.h"
+
+#ifdef RNA_RUNTIME
+
+#include "BKE_sca.h"
+#include "DNA_controller_types.h"
+#include "DNA_actuator_types.h"
+
+static void rna_Actuator_link(bActuator *act, bController *cont)
+{
+ link_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks, sizeof(bActuator *));
+}
+
+static void rna_Actuator_unlink(bActuator *act, bController *cont)
+{
+ unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
+}
+
+#else
+
+void RNA_api_actuator(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ func= RNA_def_function(srna, "link", "rna_Actuator_link");
+ RNA_def_function_ui_description(func, "Link the actuator to a controller.");
+ parm= RNA_def_pointer(func, "controller", "Controller", "", "Controller to link to.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+
+ func= RNA_def_function(srna, "unlink", "rna_Actuator_unlink");
+ RNA_def_function_ui_description(func, "Unlink the actuator from a controller.");
+ parm= RNA_def_pointer(func, "controller", "Controller", "", "Controller to unlink from.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+}
+
+#endif
+
diff --git a/source/blender/makesrna/intern/rna_controller.c b/source/blender/makesrna/intern/rna_controller.c
index 275a34e3bbb..a004f2d11b2 100644
--- a/source/blender/makesrna/intern/rna_controller.c
+++ b/source/blender/makesrna/intern/rna_controller.c
@@ -156,6 +156,8 @@ void RNA_def_controller(BlenderRNA *brna)
RNA_def_struct_refine_func(srna, "rna_Controller_refine");
RNA_def_struct_ui_text(srna, "Controller", "Game engine logic brick to process events, connecting sensors to actuators");
+ RNA_api_controller(srna);
+
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "");
RNA_def_struct_name_property(srna, prop);
diff --git a/source/blender/makesrna/intern/rna_controller_api.c b/source/blender/makesrna/intern/rna_controller_api.c
new file mode 100644
index 00000000000..dab2ce8c3a1
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_controller_api.c
@@ -0,0 +1,81 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "WM_types.h"
+#include "RNA_define.h"
+
+#ifdef RNA_RUNTIME
+
+#include "BKE_sca.h"
+#include "DNA_sensor_types.h"
+#include "DNA_controller_types.h"
+#include "DNA_actuator_types.h"
+
+static void rna_Controller_link(bController *cont, bSensor *sens, bActuator *act)
+{
+ if(sens)
+ link_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks, sizeof(bController *));
+ if(act)
+ link_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks, sizeof(bActuator *));
+}
+
+static void rna_Controller_unlink(bController *cont, bSensor *sens, bActuator *act)
+{
+ if(sens)
+ unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
+ if(act)
+ unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
+}
+
+#else
+
+void RNA_api_controller(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ func= RNA_def_function(srna, "link", "rna_Controller_link");
+ RNA_def_function_ui_description(func, "Link the controller with a sensor/actuator.");
+ parm= RNA_def_pointer(func, "sensor", "Sensor", "", "Sensor to link the controller to.");
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+ parm= RNA_def_pointer(func, "actuator", "Actuator", "", "Actuator to link the controller to.");
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+
+ func= RNA_def_function(srna, "unlink", "rna_Controller_unlink");
+ RNA_def_function_ui_description(func, "Unlink the controller from a sensor/actuator.");
+ parm= RNA_def_pointer(func, "sensor", "Sensor", "", "Sensor to unlink the controller from.");
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+ parm= RNA_def_pointer(func, "actuator", "Actuator", "", "Actuator to unlink the controller from.");
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+}
+
+#endif
+
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 950811ef295..806a22dd3b8 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -237,6 +237,9 @@ void RNA_api_sequence_strip(StructRNA *srna);
void RNA_api_text(struct StructRNA *srna);
void RNA_api_ui_layout(struct StructRNA *srna);
void RNA_api_wm(struct StructRNA *srna);
+void RNA_api_sensor(struct StructRNA *srna);
+void RNA_api_controller(struct StructRNA *srna);
+void RNA_api_actuator(struct StructRNA *srna);
/* main collection functions */
void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop);
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c
index 17137d0d259..90a520d6d92 100644
--- a/source/blender/makesrna/intern/rna_sensor.c
+++ b/source/blender/makesrna/intern/rna_sensor.c
@@ -302,6 +302,8 @@ static void rna_def_sensor(BlenderRNA *brna)
RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
RNA_def_property_ui_text(prop, "Tap", "Trigger controllers only for an instant, even while the sensor remains true");
RNA_def_property_update(prop, NC_LOGIC, NULL);
+
+ RNA_api_sensor(srna);
}
static void rna_def_always_sensor(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_sensor_api.c b/source/blender/makesrna/intern/rna_sensor_api.c
new file mode 100644
index 00000000000..afdb71b4f3b
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_sensor_api.c
@@ -0,0 +1,72 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "WM_types.h"
+#include "RNA_define.h"
+
+#ifdef RNA_RUNTIME
+
+#include "BKE_sca.h"
+#include "DNA_sensor_types.h"
+#include "DNA_controller_types.h"
+
+static void rna_Sensor_link(bSensor *sens, bController *cont)
+{
+ link_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks, sizeof(bController *));
+}
+
+static void rna_Sensor_unlink(bSensor *sens, bController *cont)
+{
+ unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
+}
+
+#else
+
+void RNA_api_sensor(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ func= RNA_def_function(srna, "link", "rna_Sensor_link");
+ RNA_def_function_ui_description(func, "Link the sensor to a controller.");
+ parm= RNA_def_pointer(func, "controller", "Controller", "", "Controller to link to.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+
+ func= RNA_def_function(srna, "unlink", "rna_Sensor_unlink");
+ RNA_def_function_ui_description(func, "Unlink the sensor from a controller.");
+ parm= RNA_def_pointer(func, "controller", "Controller", "", "Controller to unlink from.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_property_update(parm, NC_LOGIC, NULL);
+}
+
+#endif
+