ScriptComponent.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Components/SceneComponent.h>
  7. #include <AnKi/Resource/Forward.h>
  8. #include <AnKi/Script/ScriptEnvironment.h>
  9. namespace anki {
  10. // Component of scripts. It can point to a resource with the script code or have the script code embedded to it.
  11. class ScriptComponent : public SceneComponent
  12. {
  13. ANKI_SCENE_COMPONENT(ScriptComponent)
  14. public:
  15. ScriptComponent(SceneNode* node);
  16. ~ScriptComponent();
  17. void setScriptResourceFilename(CString fname);
  18. CString getScriptResourceFilename() const;
  19. void setScriptText(CString text);
  20. CString getScriptText() const;
  21. Bool hasScriptText() const
  22. {
  23. return !m_text.isEmpty();
  24. }
  25. Bool hasScriptResource() const
  26. {
  27. return m_resource.isCreated();
  28. }
  29. Bool isEnabled() const
  30. {
  31. return m_environments[0] || m_environments[1];
  32. }
  33. private:
  34. ScriptResourcePtr m_resource;
  35. SceneString m_text;
  36. Array<ScriptEnvironment*, 2> m_environments = {};
  37. void update(SceneComponentUpdateInfo& info, Bool& updated) override;
  38. Error serialize(SceneSerializer& serializer) override;
  39. };
  40. } // end namespace anki