component.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "console/simBase.h"
  24. #include "console/consoleTypes.h"
  25. #include "T3D/components/component.h"
  26. #include "core/util/safeDelete.h"
  27. #include "core/resourceManager.h"
  28. #include "core/stream/fileStream.h"
  29. #include "core/stream/bitStream.h"
  30. #include "console/engineAPI.h"
  31. #include "sim/netConnection.h"
  32. #include "console/consoleInternal.h"
  33. #define DECLARE_NATIVE_COMPONENT( ComponentType ) \
  34. Component* staticComponentTemplate = new ComponentType; \
  35. Sim::gNativeComponentSet->addObject(staticComponentTemplate);
  36. //////////////////////////////////////////////////////////////////////////
  37. // Constructor/Destructor
  38. //////////////////////////////////////////////////////////////////////////
  39. Component::Component()
  40. {
  41. mFriendlyName = StringTable->EmptyString();
  42. mFromResource = StringTable->EmptyString();
  43. mComponentType = StringTable->EmptyString();
  44. mComponentGroup = StringTable->EmptyString();
  45. mNetworkType = StringTable->EmptyString();
  46. mTemplateName = StringTable->EmptyString();
  47. //mDependency = StringTable->EmptyString();
  48. mNetworked = false;
  49. // [tom, 1/12/2007] We manage the memory for the description since it
  50. // could be loaded from a file and thus massive. This is accomplished with
  51. // protected fields, but since they still call Con::getData() the field
  52. // needs to always be valid. This is pretty lame.
  53. mDescription = new char[1];
  54. ((char *)mDescription)[0] = 0;
  55. mOwner = NULL;
  56. mCanSaveFieldDictionary = false;
  57. mOriginatingAssetId = StringTable->EmptyString();
  58. mNetFlags.set(Ghostable);
  59. }
  60. Component::~Component()
  61. {
  62. for (S32 i = 0; i < mFields.size(); ++i)
  63. {
  64. ComponentField &field = mFields[i];
  65. SAFE_DELETE_ARRAY(field.mFieldDescription);
  66. }
  67. SAFE_DELETE_ARRAY(mDescription);
  68. }
  69. IMPLEMENT_CO_NETOBJECT_V1(Component);
  70. //////////////////////////////////////////////////////////////////////////
  71. void Component::initPersistFields()
  72. {
  73. addGroup("Component");
  74. addField("componentType", TypeCaseString, Offset(mComponentType, Component), "The type of behavior.", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  75. addField("networkType", TypeCaseString, Offset(mNetworkType, Component), "The type of behavior.", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  76. addField("friendlyName", TypeCaseString, Offset(mFriendlyName, Component), "Human friendly name of this behavior", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  77. addProtectedField("description", TypeCaseString, Offset(mDescription, Component), &setDescription, &getDescription,
  78. "The description of this behavior which can be set to a \"string\" or a fileName\n", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  79. addField("networked", TypeBool, Offset(mNetworked, Component), "Is this behavior ghosted to clients?", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  80. addProtectedField("Owner", TypeSimObjectPtr, Offset(mOwner, Component), &setOwner, &defaultProtectedGetFn, "", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  81. //addField("hidden", TypeBool, Offset(mHidden, Component), "Flags if this behavior is shown in the editor or not", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  82. addProtectedField("enabled", TypeBool, Offset(mEnabled, Component), &_setEnabled, &defaultProtectedGetFn, "");
  83. addField("originatingAsset", TypeComponentAssetPtr, Offset(mOriginatingAsset, Component),
  84. "Asset that spawned this component, used for tracking/housekeeping", AbstractClassRep::FieldFlags::FIELD_HideInInspectors);
  85. endGroup("Component");
  86. Parent::initPersistFields();
  87. //clear out irrelevent fields
  88. removeField("name");
  89. //removeField("internalName");
  90. removeField("parentGroup");
  91. //removeField("class");
  92. removeField("superClass");
  93. removeField("hidden");
  94. removeField("canSave");
  95. removeField("canSaveDynamicFields");
  96. removeField("persistentId");
  97. }
  98. bool Component::_setEnabled(void *object, const char *index, const char *data)
  99. {
  100. Component *c = static_cast<Component*>(object);
  101. c->mEnabled = dAtob(data);
  102. c->setMaskBits(EnableMask);
  103. return true;
  104. }
  105. //////////////////////////////////////////////////////////////////////////
  106. bool Component::setDescription(void *object, const char *index, const char *data)
  107. {
  108. Component *bT = static_cast<Component *>(object);
  109. SAFE_DELETE_ARRAY(bT->mDescription);
  110. bT->mDescription = bT->getDescriptionText(data);
  111. // We return false since we don't want the console to mess with the data
  112. return false;
  113. }
  114. const char * Component::getDescription(void* obj, const char* data)
  115. {
  116. Component *object = static_cast<Component *>(obj);
  117. return object->mDescription ? object->mDescription : "";
  118. }
  119. //////////////////////////////////////////////////////////////////////////
  120. bool Component::onAdd()
  121. {
  122. if (!Parent::onAdd())
  123. return false;
  124. setMaskBits(UpdateMask);
  125. setMaskBits(NamespaceMask);
  126. return true;
  127. }
  128. void Component::onRemove()
  129. {
  130. onDataSet.removeAll();
  131. if (mOwner)
  132. {
  133. //notify our removal to the owner, so we have no loose ends
  134. mOwner->removeComponent(this, false);
  135. }
  136. Parent::onRemove();
  137. }
  138. void Component::onComponentAdd()
  139. {
  140. if (isServerObject())
  141. {
  142. if (isMethod("onAdd"))
  143. Con::executef(this, "onAdd");
  144. }
  145. mEnabled = true;
  146. }
  147. void Component::onComponentRemove()
  148. {
  149. mEnabled = false;
  150. if (isServerObject())
  151. {
  152. if (isMethod("onRemove"))
  153. Con::executef(this, "onRemove");
  154. }
  155. if (mOwner)
  156. {
  157. mOwner->onComponentAdded.remove(this, &Component::componentAddedToOwner);
  158. mOwner->onComponentRemoved.remove(this, &Component::componentRemovedFromOwner);
  159. mOwner->onTransformSet.remove(this, &Component::ownerTransformSet);
  160. }
  161. mOwner = NULL;
  162. setDataField("owner", NULL, "");
  163. }
  164. void Component::setOwner(Entity* owner)
  165. {
  166. //first, catch if we have an existing owner, and we're changing from it
  167. if (mOwner && mOwner != owner)
  168. {
  169. mOwner->onComponentAdded.remove(this, &Component::componentAddedToOwner);
  170. mOwner->onComponentRemoved.remove(this, &Component::componentRemovedFromOwner);
  171. mOwner->onTransformSet.remove(this, &Component::ownerTransformSet);
  172. mOwner->removeComponent(this, false);
  173. }
  174. mOwner = owner;
  175. if (mOwner != NULL)
  176. {
  177. mOwner->onComponentAdded.notify(this, &Component::componentAddedToOwner);
  178. mOwner->onComponentRemoved.notify(this, &Component::componentRemovedFromOwner);
  179. mOwner->onTransformSet.notify(this, &Component::ownerTransformSet);
  180. }
  181. if (isServerObject())
  182. setMaskBits(OwnerMask);
  183. }
  184. void Component::componentAddedToOwner(Component *comp)
  185. {
  186. return;
  187. }
  188. void Component::componentRemovedFromOwner(Component *comp)
  189. {
  190. return;
  191. }
  192. void Component::ownerTransformSet(MatrixF *mat)
  193. {
  194. return;
  195. }
  196. U32 Component::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
  197. {
  198. U32 retMask = Parent::packUpdate(con, mask, stream);
  199. if (mask & OwnerMask)
  200. {
  201. if (mOwner != NULL)
  202. {
  203. S32 ghostIndex = con->getGhostIndex(mOwner);
  204. if (ghostIndex == -1)
  205. {
  206. stream->writeFlag(false);
  207. retMask |= OwnerMask;
  208. }
  209. else
  210. {
  211. stream->writeFlag(true);
  212. stream->writeFlag(true);
  213. stream->writeInt(ghostIndex, NetConnection::GhostIdBitSize);
  214. }
  215. }
  216. else
  217. {
  218. stream->writeFlag(true);
  219. stream->writeFlag(false);
  220. }
  221. }
  222. else
  223. stream->writeFlag(false);
  224. if (stream->writeFlag(mask & EnableMask))
  225. {
  226. stream->writeFlag(mEnabled);
  227. }
  228. /*if (stream->writeFlag(mask & NamespaceMask))
  229. {
  230. const char* name = getName();
  231. if (stream->writeFlag(name && name[0]))
  232. stream->writeString(String(name));
  233. if (stream->writeFlag(mSuperClassName && mSuperClassName[0]))
  234. stream->writeString(String(mSuperClassName));
  235. if (stream->writeFlag(mClassName && mClassName[0]))
  236. stream->writeString(String(mClassName));
  237. }*/
  238. return retMask;
  239. }
  240. void Component::unpackUpdate(NetConnection *con, BitStream *stream)
  241. {
  242. Parent::unpackUpdate(con, stream);
  243. if (stream->readFlag())
  244. {
  245. if (stream->readFlag())
  246. {
  247. //we have an owner object, so fetch it
  248. S32 gIndex = stream->readInt(NetConnection::GhostIdBitSize);
  249. Entity *e = dynamic_cast<Entity*>(con->resolveGhost(gIndex));
  250. if (e)
  251. e->addComponent(this);
  252. }
  253. else
  254. {
  255. //it's being nulled out
  256. setOwner(NULL);
  257. }
  258. }
  259. if (stream->readFlag())
  260. {
  261. mEnabled = stream->readFlag();
  262. }
  263. /*if (stream->readFlag())
  264. {
  265. if (stream->readFlag())
  266. {
  267. char name[256];
  268. stream->readString(name);
  269. assignName(name);
  270. }
  271. if (stream->readFlag())
  272. {
  273. char superClassname[256];
  274. stream->readString(superClassname);
  275. mSuperClassName = superClassname;
  276. }
  277. if (stream->readFlag())
  278. {
  279. char classname[256];
  280. stream->readString(classname);
  281. mClassName = classname;
  282. }
  283. linkNamespaces();
  284. }*/
  285. }
  286. void Component::packToStream(Stream &stream, U32 tabStop, S32 behaviorID, U32 flags /* = 0 */)
  287. {
  288. char buffer[1024];
  289. writeFields(stream, tabStop);
  290. // Write out the fields which the behavior template knows about
  291. for (int i = 0; i < getComponentFieldCount(); i++)
  292. {
  293. ComponentField *field = getComponentField(i);
  294. const char *objFieldValue = getDataField(field->mFieldName, NULL);
  295. // If the field holds the same value as the template's default value than it
  296. // will get initialized by the template, and so it won't be included just
  297. // to try to keep the object files looking as non-horrible as possible.
  298. if (dStrcmp(field->mDefaultValue, objFieldValue) != 0)
  299. {
  300. dSprintf(buffer, sizeof(buffer), "%s = \"%s\";\n", field->mFieldName, (dStrlen(objFieldValue) > 0 ? objFieldValue : "0"));
  301. stream.writeTabs(tabStop);
  302. stream.write(dStrlen(buffer), buffer);
  303. }
  304. }
  305. }
  306. void Component::processTick()
  307. {
  308. if (isServerObject() && mEnabled)
  309. {
  310. if (mOwner != NULL && isMethod("Update"))
  311. Con::executef(this, "Update");
  312. }
  313. }
  314. void Component::setDataField(StringTableEntry slotName, const char *array, const char *value)
  315. {
  316. Parent::setDataField(slotName, array, value);
  317. onDataSet.trigger(this, slotName, value);
  318. }
  319. StringTableEntry Component::getComponentName()
  320. {
  321. return getNamespace()->getName();
  322. }
  323. //catch any behavior field updates
  324. void Component::onStaticModified(const char* slotName, const char* newValue)
  325. {
  326. Parent::onStaticModified(slotName, newValue);
  327. //If we don't have an owner yet, then this is probably the initial setup, so we don't need the console callbacks yet.
  328. if (!mOwner)
  329. return;
  330. onDataSet.trigger(this, slotName, newValue);
  331. checkComponentFieldModified(slotName, newValue);
  332. }
  333. void Component::onDynamicModified(const char* slotName, const char* newValue)
  334. {
  335. Parent::onDynamicModified(slotName, newValue);
  336. //If we don't have an owner yet, then this is probably the initial setup, so we don't need the console callbacks yet.
  337. if (!mOwner)
  338. return;
  339. checkComponentFieldModified(slotName, newValue);
  340. }
  341. void Component::checkComponentFieldModified(const char* slotName, const char* newValue)
  342. {
  343. StringTableEntry slotNameEntry = StringTable->insert(slotName);
  344. //find if it's a behavior field
  345. for (int i = 0; i < mFields.size(); i++)
  346. {
  347. ComponentField *field = getComponentField(i);
  348. if (field->mFieldName == slotNameEntry)
  349. {
  350. //we have a match, do the script callback that we updated a field
  351. if (isMethod("onInspectorUpdate"))
  352. Con::executef(this, "onInspectorUpdate", slotName);
  353. return;
  354. }
  355. }
  356. }
  357. //////////////////////////////////////////////////////////////////////////
  358. //////////////////////////////////////////////////////////////////////////
  359. void Component::addComponentField(const char *fieldName, const char *desc, const char *type, const char *defaultValue /* = NULL */, const char *userData /* = NULL */, /*const char* dependency /* = NULL *//*,*/ bool hidden /* = false */)
  360. {
  361. StringTableEntry stFieldName = StringTable->insert(fieldName);
  362. for (S32 i = 0; i < mFields.size(); ++i)
  363. {
  364. if (mFields[i].mFieldName == stFieldName)
  365. return;
  366. }
  367. ComponentField field;
  368. field.mFieldName = stFieldName;
  369. //find the field type
  370. S32 fieldTypeMask = -1;
  371. StringTableEntry fieldType = StringTable->insert(type);
  372. if (fieldType == StringTable->insert("int"))
  373. fieldTypeMask = TypeS32;
  374. else if (fieldType == StringTable->insert("float"))
  375. fieldTypeMask = TypeF32;
  376. else if (fieldType == StringTable->insert("vector"))
  377. fieldTypeMask = TypePoint3F;
  378. else if (fieldType == StringTable->insert("material"))
  379. fieldTypeMask = TypeMaterialName;
  380. else if (fieldType == StringTable->insert("image"))
  381. fieldTypeMask = TypeImageFilename;
  382. else if (fieldType == StringTable->insert("shape"))
  383. fieldTypeMask = TypeShapeFilename;
  384. else if (fieldType == StringTable->insert("bool"))
  385. fieldTypeMask = TypeBool;
  386. else if (fieldType == StringTable->insert("object"))
  387. fieldTypeMask = TypeSimObjectPtr;
  388. else if (fieldType == StringTable->insert("string"))
  389. fieldTypeMask = TypeString;
  390. else if (fieldType == StringTable->insert("colorI"))
  391. fieldTypeMask = TypeColorI;
  392. else if (fieldType == StringTable->insert("colorF"))
  393. fieldTypeMask = TypeColorF;
  394. else if (fieldType == StringTable->insert("ease"))
  395. fieldTypeMask = TypeEaseF;
  396. else if (fieldType == StringTable->insert("gameObject"))
  397. fieldTypeMask = TypeGameObjectAssetPtr;
  398. else
  399. fieldTypeMask = TypeString;
  400. field.mFieldType = fieldTypeMask;
  401. field.mUserData = StringTable->insert(userData ? userData : "");
  402. field.mDefaultValue = StringTable->insert(defaultValue ? defaultValue : "");
  403. field.mFieldDescription = getDescriptionText(desc);
  404. field.mGroup = mComponentGroup;
  405. field.mHidden = hidden;
  406. mFields.push_back(field);
  407. //Before we set this, we need to do a test to see if this field was already set, like from the mission file or a taml file
  408. const char* curFieldData = getDataField(field.mFieldName, NULL);
  409. if (dStrIsEmpty(curFieldData))
  410. setDataField(field.mFieldName, NULL, field.mDefaultValue);
  411. }
  412. ComponentField* Component::getComponentField(const char *fieldName)
  413. {
  414. StringTableEntry stFieldName = StringTable->insert(fieldName);
  415. for (S32 i = 0; i < mFields.size(); ++i)
  416. {
  417. if (mFields[i].mFieldName == stFieldName)
  418. return &mFields[i];
  419. }
  420. return NULL;
  421. }
  422. //////////////////////////////////////////////////////////////////////////
  423. const char * Component::getDescriptionText(const char *desc)
  424. {
  425. if (desc == NULL)
  426. return NULL;
  427. char *newDesc;
  428. // [tom, 1/12/2007] If it isn't a file, just do it the easy way
  429. if (!Platform::isFile(desc))
  430. {
  431. newDesc = new char[dStrlen(desc) + 1];
  432. dStrcpy(newDesc, desc);
  433. return newDesc;
  434. }
  435. FileStream str;
  436. str.open(desc, Torque::FS::File::Read);
  437. Stream *stream = &str;
  438. if (stream == NULL){
  439. str.close();
  440. return NULL;
  441. }
  442. U32 size = stream->getStreamSize();
  443. if (size > 0)
  444. {
  445. newDesc = new char[size + 1];
  446. if (stream->read(size, (void *)newDesc))
  447. newDesc[size] = 0;
  448. else
  449. {
  450. SAFE_DELETE_ARRAY(newDesc);
  451. }
  452. }
  453. str.close();
  454. delete stream;
  455. return newDesc;
  456. }
  457. //////////////////////////////////////////////////////////////////////////
  458. void Component::beginFieldGroup(const char* groupName)
  459. {
  460. if (dStrcmp(mComponentGroup, ""))
  461. {
  462. Con::errorf("Component: attempting to begin new field group with a group already begun!");
  463. return;
  464. }
  465. mComponentGroup = StringTable->insert(groupName);
  466. }
  467. void Component::endFieldGroup()
  468. {
  469. mComponentGroup = StringTable->insert("");
  470. }
  471. void Component::addDependency(StringTableEntry name)
  472. {
  473. mDependencies.push_back_unique(name);
  474. }
  475. //////////////////////////////////////////////////////////////////////////
  476. // Console Methods
  477. //////////////////////////////////////////////////////////////////////////
  478. ConsoleMethod(Component, beginGroup, void, 3, 3, "(groupName)\n"
  479. "Starts the grouping for following fields being added to be grouped into\n"
  480. "@param groupName The name of this group\n"
  481. "@param desc The Description of this field\n"
  482. "@param type The DataType for this field (default, int, float, Point2F, bool, enum, Object, keybind, color)\n"
  483. "@param defaultValue The Default value for this field\n"
  484. "@param userData An extra data field that can be used for custom data on a per-field basis<br>Usage for default types<br>"
  485. "-enum: a TAB separated list of possible values<br>"
  486. "-object: the T2D object type that are valid choices for the field. The object types observe inheritance, so if you have a t2dSceneObject field you will be able to choose t2dStaticSrpites, t2dAnimatedSprites, etc.\n"
  487. "@return Nothing\n")
  488. {
  489. object->beginFieldGroup(argv[2]);
  490. }
  491. ConsoleMethod(Component, endGroup, void, 2, 2, "()\n"
  492. "Ends the grouping for prior fields being added to be grouped into\n"
  493. "@param groupName The name of this group\n"
  494. "@param desc The Description of this field\n"
  495. "@param type The DataType for this field (default, int, float, Point2F, bool, enum, Object, keybind, color)\n"
  496. "@param defaultValue The Default value for this field\n"
  497. "@param userData An extra data field that can be used for custom data on a per-field basis<br>Usage for default types<br>"
  498. "-enum: a TAB separated list of possible values<br>"
  499. "-object: the T2D object type that are valid choices for the field. The object types observe inheritance, so if you have a t2dSceneObject field you will be able to choose t2dStaticSrpites, t2dAnimatedSprites, etc.\n"
  500. "@return Nothing\n")
  501. {
  502. object->endFieldGroup();
  503. }
  504. DefineConsoleMethod(Component, addComponentField, void, (String fieldName, String fieldDesc, String fieldType, String defValue, String userData, bool hidden),
  505. ("", "", "", "", "", false),
  506. "Get the number of static fields on the object.\n"
  507. "@return The number of static fields defined on the object.")
  508. {
  509. object->addComponentField(fieldName, fieldDesc, fieldType, defValue, userData, hidden);
  510. }
  511. ConsoleMethod(Component, getComponentFieldCount, S32, 2, 2, "() - Get the number of ComponentField's on this object\n"
  512. "@return Returns the number of BehaviorFields as a nonnegative integer\n")
  513. {
  514. return object->getComponentFieldCount();
  515. }
  516. // [tom, 1/12/2007] Field accessors split into multiple methods to allow space
  517. // for long descriptions and type data.
  518. ConsoleMethod(Component, getComponentField, const char *, 3, 3, "(int index) - Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
  519. "@param index The index of the behavior\n"
  520. "@return FieldName, FieldType and FieldDefaultValue, each separated by a TAB character.\n")
  521. {
  522. ComponentField *field = object->getComponentField(dAtoi(argv[2]));
  523. if (field == NULL)
  524. return "";
  525. char *buf = Con::getReturnBuffer(1024);
  526. dSprintf(buf, 1024, "%s\t%s\t%s\t%s", field->mFieldName, field->mFieldType, field->mDefaultValue, field->mGroup);
  527. return buf;
  528. }
  529. ConsoleMethod(Component, setComponentield, const char *, 3, 3, "(int index) - Gets a Tab-Delimited list of information about a ComponentField specified by Index\n"
  530. "@param index The index of the behavior\n"
  531. "@return FieldName, FieldType and FieldDefaultValue, each separated by a TAB character.\n")
  532. {
  533. ComponentField *field = object->getComponentField(dAtoi(argv[2]));
  534. if (field == NULL)
  535. return "";
  536. char *buf = Con::getReturnBuffer(1024);
  537. dSprintf(buf, 1024, "%s\t%s\t%s", field->mFieldName, field->mFieldType, field->mDefaultValue);
  538. return buf;
  539. }
  540. DefineConsoleMethod(Component, getComponentFieldType, const char *, (String fieldName), ,
  541. "Get the number of static fields on the object.\n"
  542. "@return The number of static fields defined on the object.")
  543. {
  544. ComponentField *field = object->getComponentField(fieldName);
  545. if (field == NULL)
  546. return "";
  547. return field->mFieldTypeName;;
  548. }
  549. ConsoleMethod(Component, getBehaviorFieldUserData, const char *, 3, 3, "(int index) - Gets the UserData associated with a field by index in the field list\n"
  550. "@param index The index of the behavior\n"
  551. "@return Returns a string representing the user data of this field\n")
  552. {
  553. ComponentField *field = object->getComponentField(dAtoi(argv[2]));
  554. if (field == NULL)
  555. return "";
  556. return field->mUserData;
  557. }
  558. ConsoleMethod(Component, getComponentFieldDescription, const char *, 3, 3, "(int index) - Gets a field description by index\n"
  559. "@param index The index of the behavior\n"
  560. "@return Returns a string representing the description of this field\n")
  561. {
  562. ComponentField *field = object->getComponentField(dAtoi(argv[2]));
  563. if (field == NULL)
  564. return "";
  565. return field->mFieldDescription ? field->mFieldDescription : "";
  566. }
  567. ConsoleMethod(Component, addDependency, void, 3, 3, "(string behaviorName) - Gets a field description by index\n"
  568. "@param index The index of the behavior\n"
  569. "@return Returns a string representing the description of this field\n")
  570. {
  571. object->addDependency(argv[2]);
  572. }
  573. ConsoleMethod(Component, setDirty, void, 2, 2, "() - Gets a field description by index\n"
  574. "@param index The index of the behavior\n"
  575. "@return Returns a string representing the description of this field\n")
  576. {
  577. object->setMaskBits(Component::OwnerMask);
  578. }