patch [#29679] Expose connected logic bricks from python
authorDalai Felinto <dfelinto@gmail.com>
Wed, 18 Jan 2012 22:42:57 +0000 (22:42 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Wed, 18 Jan 2012 22:42:57 +0000 (22:42 +0000)
it exposes sensor.controllers and controller.actuators
this is how the data is exposed in blender.

to have controller.sensors or actuator.controllers is not that straightforward

source/blender/makesrna/intern/rna_controller.c
source/blender/makesrna/intern/rna_sensor.c

index 5278c1e3532021f4cea5782418d3a8712530a4ac..7dfb3597a295c81358f57415ebcfd91d71533fc2 100644 (file)
@@ -48,6 +48,7 @@ EnumPropertyItem controller_type_items[] ={
 #ifdef RNA_RUNTIME
 
 #include "BKE_sca.h"
+#include "DNA_actuator_types.h"
 
 static struct StructRNA* rna_Controller_refine(struct PointerRNA *ptr)
 {
@@ -132,6 +133,18 @@ static void rna_Controller_state_number_set(struct PointerRNA *ptr, const int va
        cont->state_mask = (1 << (value - 1));
 }
 
+static void rna_Controller_actuators_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+       bController *cont = (bController *)ptr->data;
+       rna_iterator_array_begin(iter, cont->links, sizeof(bActuator *), (int)cont->totlinks, 0, NULL);
+}
+
+static int rna_Controller_actuators_length(PointerRNA *ptr)
+{
+       bController *cont = (bController *)ptr->data;
+       return (int) cont->totlinks;
+}
+
 #if 0 /* editable is set to false, comment for now. */
 static void rna_Controller_state_get(PointerRNA *ptr, int *values)
 {
@@ -212,6 +225,12 @@ void RNA_def_controller(BlenderRNA *brna)
        RNA_def_property_ui_icon(prop, ICON_BOOKMARKS, 1);
        RNA_def_property_update(prop, NC_LOGIC, NULL);
 
+       prop= RNA_def_property(srna, "actuators", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+       RNA_def_property_struct_type(prop, "Actuator");
+       RNA_def_property_ui_text(prop, "Actuators", "The list containing the actuators connected to the controller");
+       RNA_def_property_collection_funcs(prop, "rna_Controller_actuators_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Controller_actuators_length", NULL, NULL, NULL);
+
        /* State */
        
        // array of OB_MAX_STATES
index 6459c145a3acf7ee4f2ce74565347ef8ec6bf4c4..4413eee93951c3e61f2c74698006526c9afd2faf 100644 (file)
@@ -61,6 +61,7 @@ EnumPropertyItem sensor_type_items[] ={
 #ifdef RNA_RUNTIME
 
 #include "BKE_sca.h"
+#include "DNA_controller_types.h"
 
 static StructRNA* rna_Sensor_refine(struct PointerRNA *ptr)
 {
@@ -125,6 +126,19 @@ static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
 }
 
 /* Always keep in alphabetical order */
+
+static void rna_Sensor_controllers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+       bSensor *sens = (bSensor *)ptr->data;
+       rna_iterator_array_begin(iter, sens->links, sizeof(bController *), (int)sens->totlinks, 0, NULL);
+}
+
+static int rna_Sensor_controllers_length(PointerRNA *ptr)
+{
+       bSensor *sens = (bSensor *)ptr->data;
+       return (int) sens->totlinks;
+}
+
 EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
 {
        EnumPropertyItem *item= NULL;
@@ -327,6 +341,13 @@ static void rna_def_sensor(BlenderRNA *brna)
        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);
 
+       prop= RNA_def_property(srna, "controllers", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
+       RNA_def_property_struct_type(prop, "Controller");
+       RNA_def_property_ui_text(prop, "Controllers", "The list containing the controllers connected to the sensor");
+       RNA_def_property_collection_funcs(prop, "rna_Sensor_controllers_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", "rna_Sensor_controllers_length", NULL, NULL, NULL);
+
+
        RNA_api_sensor(srna);
 }