component.cpp 23 KB

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