From 1cad087969efefa401a11051343cd0689f660770 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 24 May 2014 01:35:47 -0300 Subject: Making Godot Easier to Use.. -=-=-=-=-=-=-=-=-=-=-=-=-=-= -Auto indenter in code editor, this makes it much easier to paste external code. -Zoom in 2D viewport now uses the mouse pointer as reference. -Obscure hack to see where code/line of GDScript in C++ backtrace. -Fixed a bug where keys would get stuck on X11 if pressed simultaneously -Added Api on IP singleton to request local IPs. -Premultiplied alpha support when importing texture, editing PNGs and as a blend mode. --- modules/gdscript/gd_compiler.cpp | 10 +++++++ modules/gdscript/gd_editor.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ modules/gdscript/gd_parser.cpp | 23 ++++++++++++--- modules/gdscript/gd_parser.h | 2 ++ modules/gdscript/gd_script.cpp | 3 ++ modules/gdscript/gd_script.h | 8 +++-- 6 files changed, 104 insertions(+), 6 deletions(-) (limited to 'modules') diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 48f0092827..548b10cf15 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1263,6 +1263,16 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * gdfunc->name=func_name; gdfunc->_script=p_script; gdfunc->source=source; + +#ifdef DEBUG_ENABLED + + { + gdfunc->func_cname=(String(source)+" - "+String(func_name)).utf8(); + gdfunc->_func_cname=gdfunc->func_cname.get_data(); + + } + +#endif if (p_func) { gdfunc->_initial_line=p_func->line; } else { diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index f8717c292f..5f5de8b5db 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -787,3 +787,67 @@ Error GDScriptLanguage::complete_keyword(const String& p_code, int p_line, const return OK; } +void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const { + + + Vector lines = p_code.split("\n"); + List indent_stack; + + for(int i=0;iget(); + } + + if (tc>ilevel) { + indent_stack.push_back(tc); + } else if (tcget()>tc) { + indent_stack.pop_back(); + } + + if (indent_stack.size() && indent_stack.back()->get()!=tc) + indent_stack.push_back(tc); //this is not right but gets the job done + } + + if (i>=p_from_line) { + + l=""; + for(int j=0;jp_to_line) { + break; + } + + //print_line(itos(indent_stack.size())+","+itos(tc)+": "+l); + lines[i]=l; + } + + p_code=""; + for(int i=0;i0) + p_code+="\n"; + p_code+=lines[i]; + } + +} diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index f540660cd3..2829132d99 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1221,6 +1221,15 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { return; //go back a level } + if (pending_newline!=-1) { + + NewLineNode *nl = alloc_node(); + nl->line=pending_newline; + p_block->statements.push_back(nl); + pending_newline=-1; + + } + switch(token) { @@ -1234,16 +1243,19 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } break; case GDTokenizer::TK_NEWLINE: { - NewLineNode *nl = alloc_node(); - nl->line=tokenizer->get_token_line(); - p_block->statements.push_back(nl); - if (!_parse_newline()) { if (!error_set) { p_block->end_line=tokenizer->get_token_line(); + pending_newline=p_block->end_line; + } return; } + + NewLineNode *nl = alloc_node(); + nl->line=tokenizer->get_token_line(); + p_block->statements.push_back(nl); + } break; case GDTokenizer::TK_CF_PASS: { if (tokenizer->get_token(1)!=GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE ) { @@ -1782,6 +1794,7 @@ void GDParser::_parse_class(ClassNode *p_class) { case GDTokenizer::TK_PR_FUNCTION: { bool _static=false; + pending_newline=-1; if (tokenizer->get_token(-1)==GDTokenizer::TK_PR_STATIC) { @@ -2490,6 +2503,7 @@ void GDParser::clear() { tab_level.push_back(0); error_line=0; error_column=0; + pending_newline=-1; parenthesis=0; current_export.type=Variant::NIL; error=""; @@ -2501,6 +2515,7 @@ GDParser::GDParser() { head=NULL; list=NULL; tokenizer=NULL; + pending_newline=-1; clear(); } diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index 278e5f543d..825bd954d1 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -362,6 +362,8 @@ private: int error_line; int error_column; + int pending_newline; + List tab_level; String base_path; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index c6183aadc4..0d49f79f1c 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1159,6 +1159,9 @@ GDFunction::GDFunction() { _stack_size=0; _call_size=0; name=""; +#ifdef DEBUG_ENABLED + _func_cname=NULL; +#endif } diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 983899240a..56da0bb2e3 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -118,10 +118,13 @@ friend class GDCompiler; Vector constants; Vector global_names; Vector default_arguments; - Vector code; +#ifdef DEBUG_ENABLED + CharString func_cname; + const char*_func_cname; +#endif - List stack_debug; + List stack_debug; _FORCE_INLINE_ Variant *_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self,Variant *p_stack,String& r_error) const; _FORCE_INLINE_ String _get_call_error(const Variant::CallError& p_err, const String& p_where,const Variant**argptrs) const; @@ -427,6 +430,7 @@ public: virtual int find_function(const String& p_function,const String& p_code) const; virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const; virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path,const String& p_keyword, List* r_options); + virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const; /* DEBUGGER FUNCTIONS */ -- cgit v1.2.3