1 /**
2 A class stored as a resource.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.script;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.resource;
23 import godot.reference;
24 /**
25 A class stored as a resource.
26 
27 A script exends the functionality of all objects that instance it.
28 The `new` method of a script subclass creates a new instance. $(D GodotObject.setScript) extends an existing object, if that object's class matches one of the script's base classes.
29 */
30 @GodotBaseClass struct Script
31 {
32 	enum string _GODOT_internal_name = "Script";
33 public:
34 @nogc nothrow:
35 	union { godot_object _godot_object; Resource _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct _classBinding
40 	{
41 		__gshared:
42 		@GodotName("can_instance") GodotMethod!(bool) canInstance;
43 		@GodotName("instance_has") GodotMethod!(bool, GodotObject) instanceHas;
44 		@GodotName("has_source_code") GodotMethod!(bool) hasSourceCode;
45 		@GodotName("get_source_code") GodotMethod!(String) getSourceCode;
46 		@GodotName("set_source_code") GodotMethod!(void, String) setSourceCode;
47 		@GodotName("reload") GodotMethod!(GodotError, bool) reload;
48 		@GodotName("get_base_script") GodotMethod!(Script) getBaseScript;
49 		@GodotName("get_instance_base_type") GodotMethod!(String) getInstanceBaseType;
50 		@GodotName("has_script_signal") GodotMethod!(bool, String) hasScriptSignal;
51 		@GodotName("is_tool") GodotMethod!(bool) isTool;
52 	}
53 	bool opEquals(in Script other) const { return _godot_object.ptr is other._godot_object.ptr; }
54 	Script opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
55 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
56 	mixin baseCasts;
57 	static Script _new()
58 	{
59 		static godot_class_constructor constructor;
60 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Script");
61 		if(constructor is null) return typeof(this).init;
62 		return cast(Script)(constructor());
63 	}
64 	@disable new(size_t s);
65 	/**
66 	Returns `true` if the script can be instanced.
67 	*/
68 	bool canInstance() const
69 	{
70 		checkClassBinding!(typeof(this))();
71 		return ptrcall!(bool)(_classBinding.canInstance, _godot_object);
72 	}
73 	/**
74 	Returns `true` if `base_object` is an instance of this script.
75 	*/
76 	bool instanceHas(GodotObject base_object) const
77 	{
78 		checkClassBinding!(typeof(this))();
79 		return ptrcall!(bool)(_classBinding.instanceHas, _godot_object, base_object);
80 	}
81 	/**
82 	Returns `true` if the script contains non-empty source code.
83 	*/
84 	bool hasSourceCode() const
85 	{
86 		checkClassBinding!(typeof(this))();
87 		return ptrcall!(bool)(_classBinding.hasSourceCode, _godot_object);
88 	}
89 	/**
90 	
91 	*/
92 	String getSourceCode() const
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(String)(_classBinding.getSourceCode, _godot_object);
96 	}
97 	/**
98 	
99 	*/
100 	void setSourceCode(StringArg0)(in StringArg0 source)
101 	{
102 		checkClassBinding!(typeof(this))();
103 		ptrcall!(void)(_classBinding.setSourceCode, _godot_object, source);
104 	}
105 	/**
106 	Reloads the script's class implementation. Returns an error code.
107 	*/
108 	GodotError reload(in bool keep_state = false)
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(GodotError)(_classBinding.reload, _godot_object, keep_state);
112 	}
113 	/**
114 	Returns the script directly inherited by this script.
115 	*/
116 	Ref!Script getBaseScript() const
117 	{
118 		checkClassBinding!(typeof(this))();
119 		return ptrcall!(Script)(_classBinding.getBaseScript, _godot_object);
120 	}
121 	/**
122 	Returns the script's base type.
123 	*/
124 	String getInstanceBaseType() const
125 	{
126 		checkClassBinding!(typeof(this))();
127 		return ptrcall!(String)(_classBinding.getInstanceBaseType, _godot_object);
128 	}
129 	/**
130 	Returns `true` if the script, or a base class, defines a signal with the given name.
131 	*/
132 	bool hasScriptSignal(StringArg0)(in StringArg0 signal_name) const
133 	{
134 		checkClassBinding!(typeof(this))();
135 		return ptrcall!(bool)(_classBinding.hasScriptSignal, _godot_object, signal_name);
136 	}
137 	/**
138 	Returns `true` if the script is a tool script. A tool script can run in the editor.
139 	*/
140 	bool isTool() const
141 	{
142 		checkClassBinding!(typeof(this))();
143 		return ptrcall!(bool)(_classBinding.isTool, _godot_object);
144 	}
145 	/**
146 	The script source code or an empty string if source code is not available. When set, does not reload the class implementation automatically.
147 	*/
148 	@property String sourceCode()
149 	{
150 		return getSourceCode();
151 	}
152 	/// ditto
153 	@property void sourceCode(String v)
154 	{
155 		setSourceCode(v);
156 	}
157 }