From 4b07eb8deb03ce8c7870d621cd03d04d45f4caaa Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 24 Feb 2014 09:53:33 -0300 Subject: -moved script to modules --- modules/multiscript/SCsub | 7 + modules/multiscript/config.py | 11 + modules/multiscript/multi_script.cpp | 498 +++++++++++++++++++++++++++++++++ modules/multiscript/multi_script.h | 158 +++++++++++ modules/multiscript/register_types.cpp | 32 +++ modules/multiscript/register_types.h | 30 ++ 6 files changed, 736 insertions(+) create mode 100644 modules/multiscript/SCsub create mode 100644 modules/multiscript/config.py create mode 100644 modules/multiscript/multi_script.cpp create mode 100644 modules/multiscript/multi_script.h create mode 100644 modules/multiscript/register_types.cpp create mode 100644 modules/multiscript/register_types.h (limited to 'modules/multiscript') diff --git a/modules/multiscript/SCsub b/modules/multiscript/SCsub new file mode 100644 index 0000000000..d20da72b72 --- /dev/null +++ b/modules/multiscript/SCsub @@ -0,0 +1,7 @@ +Import('env') + +env.add_source_files(env.modules_sources,"*.cpp") + +Export('env') + + diff --git a/modules/multiscript/config.py b/modules/multiscript/config.py new file mode 100644 index 0000000000..f9bd7da08d --- /dev/null +++ b/modules/multiscript/config.py @@ -0,0 +1,11 @@ + + +def can_build(platform): + return True + + +def configure(env): + pass + + + diff --git a/modules/multiscript/multi_script.cpp b/modules/multiscript/multi_script.cpp new file mode 100644 index 0000000000..1924cf2a6e --- /dev/null +++ b/modules/multiscript/multi_script.cpp @@ -0,0 +1,498 @@ +/*************************************************************************/ +/* multi_script.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "multi_script.h" + +bool MultiScriptInstance::set(const StringName& p_name, const Variant& p_value) { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;iset(p_name,p_value); + if (found) + return true; + } + + if (String(p_name).begins_with("script_")) { + bool valid; + owner->set(p_name,p_value,&valid); + return valid; + } + return false; + +} + +bool MultiScriptInstance::get(const StringName& p_name, Variant &r_ret) const{ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;iget(p_name,r_ret); + if (found) + return true; + } + if (String(p_name).begins_with("script_")) { + bool valid; + r_ret=owner->get(p_name,&valid); + return valid; + } + return false; + +} +void MultiScriptInstance::get_property_list(List *p_properties) const{ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + + Set existing; + + for(int i=0;i pl; + sarr[i]->get_property_list(&pl); + + for(List::Element *E=pl.front();E;E=E->next()) { + + if (existing.has(E->get().name)) + continue; + + p_properties->push_back(E->get()); + existing.insert(E->get().name); + } + } + + p_properties->push_back( PropertyInfo(Variant::NIL,"Scripts",PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY) ); + + for(int i=0;iscripts.size();i++) { + + p_properties->push_back( PropertyInfo(Variant::OBJECT,"script_"+String::chr('a'+i),PROPERTY_HINT_RESOURCE_TYPE,"Script",PROPERTY_USAGE_EDITOR) ); + + } + + if (owner->scripts.size()<25) { + + p_properties->push_back( PropertyInfo(Variant::OBJECT,"script_"+String::chr('a'+(owner->scripts.size())),PROPERTY_HINT_RESOURCE_TYPE,"Script",PROPERTY_USAGE_EDITOR) ); + } + +} + +void MultiScriptInstance::get_method_list(List *p_list) const{ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + + Set existing; + + for(int i=0;i ml; + sarr[i]->get_method_list(&ml); + + for(List::Element *E=ml.front();E;E=E->next()) { + + if (existing.has(E->get().name)) + continue; + + p_list->push_back(E->get()); + existing.insert(E->get().name); + } + } + +} +bool MultiScriptInstance::has_method(const StringName& p_method) const{ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;ihas_method(p_method)) + return true; + } + + return false; + +} + +Variant MultiScriptInstance::call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error) { + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;icall(p_method,p_args,p_argcount,r_error); + if (r_error.error==Variant::CallError::CALL_OK) + return r; + else if (r_error.error!=Variant::CallError::CALL_ERROR_INVALID_METHOD) + return r; + } + + r_error.error=Variant::CallError::CALL_ERROR_INVALID_METHOD; + return Variant(); + +} + +void MultiScriptInstance::call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount){ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;icall_multilevel(p_method,p_args,p_argcount); + } + + +} +void MultiScriptInstance::notification(int p_notification){ + + ScriptInstance **sarr = instances.ptr(); + int sc = instances.size(); + + for(int i=0;inotification(p_notification); + } + +} + + +Ref