BGE Python api
[blender.git] / source / gameengine / Ketsji / KX_VisibilityActuator.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  * Actuator to toggle visibility/invisibility of objects
29  */
30
31 #include "KX_VisibilityActuator.h"
32 #include "KX_GameObject.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 KX_VisibilityActuator::KX_VisibilityActuator(
39         SCA_IObject* gameobj,
40         bool visible,
41         bool recursive,
42         PyTypeObject* T
43         ) 
44         : SCA_IActuator(gameobj,T),
45           m_visible(visible),
46           m_recursive(recursive)
47 {
48         // intentionally empty
49 }
50
51 KX_VisibilityActuator::~KX_VisibilityActuator(
52         void
53         )
54 {
55         // intentionally empty
56 }
57
58 CValue*
59 KX_VisibilityActuator::GetReplica(
60         void
61         )
62 {
63         KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
64         replica->ProcessReplica();
65         // this will copy properties and so on...
66         CValue::AddDataToReplica(replica);
67         return replica;
68 }
69
70 bool
71 KX_VisibilityActuator::Update()
72 {
73         bool bNegativeEvent = IsNegativeEvent();
74         
75         RemoveAllEvents();
76         if (bNegativeEvent) return false;
77
78         KX_GameObject *obj = (KX_GameObject*) GetParent();
79         
80         obj->SetVisible(m_visible, m_recursive);
81         obj->UpdateBuckets(m_recursive);
82
83         return false;
84 }
85
86 /* ------------------------------------------------------------------------- */
87 /* Python functions                                                          */
88 /* ------------------------------------------------------------------------- */
89
90
91
92 /* Integration hooks ------------------------------------------------------- */
93 PyTypeObject KX_VisibilityActuator::Type = {
94         PyObject_HEAD_INIT(&PyType_Type)
95         0,
96         "KX_VisibilityActuator",
97         sizeof(KX_VisibilityActuator),
98         0,
99         PyDestructor,
100         0,
101         __getattr,
102         __setattr,
103         0,
104         __repr,
105         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
106         Methods
107
108 };
109
110 PyParentObject 
111 KX_VisibilityActuator::Parents[] = {
112         &KX_VisibilityActuator::Type,
113         &SCA_IActuator::Type,
114         &SCA_ILogicBrick::Type,
115         &CValue::Type,
116         NULL
117 };
118
119 PyMethodDef 
120 KX_VisibilityActuator::Methods[] = {
121         // Deprecated ----->
122         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS,
123                 (PY_METHODCHAR) SetVisible_doc},
124         // <-----
125         {NULL,NULL} //Sentinel
126 };
127
128 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
129         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
130         KX_PYATTRIBUTE_BOOL_RW("recursion", KX_VisibilityActuator, m_recursive),
131         { NULL }        //Sentinel
132 };
133
134 PyObject* KX_VisibilityActuator::_getattr(const char *attr)
135 {
136         PyObject* object = _getattr_self(Attributes, this, attr);
137         if (object != NULL)
138                 return object;
139         _getattr_up(SCA_IActuator);
140 }
141
142 int KX_VisibilityActuator::_setattr(const char *attr, PyObject *value)
143 {
144         int ret = _setattr_self(Attributes, this, attr, value);
145         if (ret >= 0)
146                 return ret;
147         return SCA_IActuator::_setattr(attr, value);
148 }
149
150
151 /* set visibility ---------------------------------------------------------- */
152 const char 
153 KX_VisibilityActuator::SetVisible_doc[] = 
154 "setVisible(visible?)\n"
155 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
156 "\tSet the properties of the actuator.\n";
157 PyObject* 
158
159 KX_VisibilityActuator::PySetVisible(PyObject* self, 
160                                     PyObject* args, 
161                                     PyObject* kwds) {
162         int vis;
163         ShowDeprecationWarning("SetVisible()", "the visible property");
164
165         if(!PyArg_ParseTuple(args, "i", &vis)) {
166                 return NULL;
167         }
168
169         m_visible = PyArgToBool(vis);
170
171         Py_RETURN_NONE;
172 }
173
174