pluginscript_script.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*************************************************************************/
  2. /* pluginscript_script.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef PLUGINSCRIPT_SCRIPT_H
  31. #define PLUGINSCRIPT_SCRIPT_H
  32. // Godot imports
  33. #include "core/doc_data.h"
  34. #include "core/object/script_language.h"
  35. // PluginScript imports
  36. #include "pluginscript_language.h"
  37. #include <pluginscript/godot_pluginscript.h>
  38. class PluginScript : public Script {
  39. GDCLASS(PluginScript, Script);
  40. friend class PluginScriptInstance;
  41. friend class PluginScriptLanguage;
  42. private:
  43. godot_pluginscript_script_data *_data = nullptr;
  44. const godot_pluginscript_script_desc *_desc = nullptr;
  45. PluginScriptLanguage *_language = nullptr;
  46. bool _tool = false;
  47. bool _valid = false;
  48. Ref<Script> _ref_base_parent;
  49. StringName _native_parent;
  50. SelfList<PluginScript> _script_list;
  51. Map<StringName, int> _member_lines;
  52. Map<StringName, Variant> _properties_default_values;
  53. Map<StringName, PropertyInfo> _properties_info;
  54. Map<StringName, MethodInfo> _signals_info;
  55. Map<StringName, MethodInfo> _methods_info;
  56. Vector<MultiplayerAPI::RPCConfig> _rpc_methods;
  57. Set<Object *> _instances;
  58. //exported members
  59. String _source;
  60. String _path;
  61. StringName _name;
  62. String _icon_path;
  63. protected:
  64. static void _bind_methods();
  65. bool inherits_script(const Ref<Script> &p_script) const override;
  66. PluginScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error);
  67. Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  68. #ifdef TOOLS_ENABLED
  69. Set<PlaceHolderScriptInstance *> placeholders;
  70. //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
  71. virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
  72. #endif
  73. public:
  74. String get_script_class_name() const {
  75. return _name;
  76. }
  77. String get_script_class_icon_path() const {
  78. return _icon_path;
  79. }
  80. virtual bool can_instance() const override;
  81. virtual Ref<Script> get_base_script() const override; //for script inheritance
  82. virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so
  83. virtual ScriptInstance *instance_create(Object *p_this) override;
  84. virtual bool instance_has(const Object *p_this) const override;
  85. virtual bool has_source_code() const override;
  86. virtual String get_source_code() const override;
  87. virtual void set_source_code(const String &p_code) override;
  88. virtual Error reload(bool p_keep_state = false) override;
  89. // TODO: load_source_code only allow utf-8 file, should handle bytecode as well ?
  90. virtual Error load_source_code(const String &p_path);
  91. #ifdef TOOLS_ENABLED
  92. virtual const Vector<DocData::ClassDoc> &get_documentation() const override {
  93. static Vector<DocData::ClassDoc> docs;
  94. return docs;
  95. }
  96. #endif // TOOLS_ENABLED
  97. virtual bool has_method(const StringName &p_method) const override;
  98. virtual MethodInfo get_method_info(const StringName &p_method) const override;
  99. bool has_property(const StringName &p_method) const;
  100. PropertyInfo get_property_info(const StringName &p_property) const;
  101. bool is_tool() const override { return _tool; }
  102. bool is_valid() const override { return true; }
  103. virtual ScriptLanguage *get_language() const override;
  104. virtual bool has_script_signal(const StringName &p_signal) const override;
  105. virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override;
  106. virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
  107. virtual void update_exports() override;
  108. virtual void get_script_method_list(List<MethodInfo> *r_methods) const override;
  109. virtual void get_script_property_list(List<PropertyInfo> *r_properties) const override;
  110. virtual int get_member_line(const StringName &p_member) const override;
  111. virtual const Vector<MultiplayerAPI::RPCConfig> get_rpc_methods() const override;
  112. PluginScript();
  113. void init(PluginScriptLanguage *language);
  114. virtual ~PluginScript();
  115. };
  116. #endif // PLUGINSCRIPT_SCRIPT_H