CSComponent.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include <Atomic/IO/Log.h>
  24. #include <Atomic/IO/FileSystem.h>
  25. #include <Atomic/Core/Context.h>
  26. #include <Atomic/Resource/ResourceCache.h>
  27. #include <Atomic/Scene/Scene.h>
  28. #include <Atomic/Scene/SceneEvents.h>
  29. #include "NETScriptEvents.h"
  30. #include "CSComponent.h"
  31. namespace Atomic
  32. {
  33. extern const char* LOGIC_CATEGORY;
  34. CSComponent::CSComponent(Context* context) :
  35. ScriptComponent(context)
  36. {
  37. }
  38. CSComponent::~CSComponent()
  39. {
  40. }
  41. void CSComponent::RegisterObject(Context* context)
  42. {
  43. context->RegisterFactory<CSComponent>(LOGIC_CATEGORY);
  44. ATOMIC_ACCESSOR_ATTRIBUTE("Class", GetComponentClassName, SetComponentClassName, String, String::EMPTY, AM_DEFAULT);
  45. ATOMIC_COPY_BASE_ATTRIBUTES(ScriptComponent);
  46. }
  47. void CSComponent::OnSetEnabled()
  48. {
  49. }
  50. void CSComponent::ApplyAttributes()
  51. {
  52. }
  53. void CSComponent::ApplyFieldValues()
  54. {
  55. if (!fieldValues_.Size())
  56. return;
  57. }
  58. void CSComponent::SetComponentClassName(const String& name)
  59. {
  60. if (componentClassName_ == name)
  61. return;
  62. componentClassName_ = name;
  63. if (context_->GetEditorContext())
  64. {
  65. using namespace CSComponentClassChanged;
  66. VariantMap eventData;
  67. eventData[P_CSCOMPONENT] = this;
  68. eventData[P_CLASSNAME] = name;
  69. SendEvent(E_CSCOMPONENTCLASSCHANGED, eventData);
  70. }
  71. }
  72. void CSComponent::OnNodeSet(Node* node)
  73. {
  74. }
  75. void CSComponent::OnSceneSet(Scene* scene)
  76. {
  77. }
  78. void CSComponent::SendLoadEvent()
  79. {
  80. if (!componentClassName_.Length())
  81. return;
  82. using namespace CSComponentLoad;
  83. VariantMap eventData;
  84. eventData[P_CLASSNAME] = componentClassName_;
  85. eventData[P_NATIVEINSTANCE] = (void*) this;
  86. if (!fieldValues_.Empty())
  87. eventData[P_FIELDVALUES] = (void*) &fieldValues_;
  88. if (node_ && node_->GetScene())
  89. node_->GetScene()->SendEvent(E_CSCOMPONENTLOAD, eventData);
  90. }
  91. bool CSComponent::Load(Deserializer& source, bool setInstanceDefault)
  92. {
  93. bool success = ScriptComponent::Load(source, setInstanceDefault);
  94. if (success)
  95. SendLoadEvent();
  96. return success;
  97. }
  98. bool CSComponent::LoadXML(const XMLElement& source, bool setInstanceDefault)
  99. {
  100. bool success = ScriptComponent::LoadXML(source, setInstanceDefault);
  101. if (success)
  102. SendLoadEvent();
  103. return success;
  104. }
  105. ScriptComponentFile* CSComponent::GetComponentFile() const
  106. {
  107. if (!componentClassName_.Length())
  108. return 0;
  109. return CSComponentAssembly::ResolveClassAssembly(componentClassName_);
  110. }
  111. }