diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-05-24 01:35:47 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-05-24 01:35:47 -0300 |
commit | 1cad087969efefa401a11051343cd0689f660770 (patch) | |
tree | 1595dd049bdb7289752012dca4398b2251fb08fa /modules | |
parent | f9ff086235cd4ff406b136f62fff77b85c0873f9 (diff) |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gd_compiler.cpp | 10 | ||||
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 64 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 23 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 3 | ||||
-rw-r--r-- | modules/gdscript/gd_script.h | 8 |
6 files changed, 104 insertions, 6 deletions
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<String> lines = p_code.split("\n"); + List<int> indent_stack; + + for(int i=0;i<lines.size();i++) { + + String l = lines[i]; + int tc=0; + for(int j=0;j<l.length();j++) { + if (l[j]==' ' || l[j]=='\t') { + + tc++; + } else { + break; + } + } + + + String st = l.substr(tc,l.length()).strip_edges(); + if (st=="" || st.begins_with("#")) + continue; //ignore! + + int ilevel=0; + if (indent_stack.size()) { + ilevel=indent_stack.back()->get(); + } + + if (tc>ilevel) { + indent_stack.push_back(tc); + } else if (tc<ilevel) { + while(indent_stack.size() && indent_stack.back()->get()>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;j<indent_stack.size();j++) + l+="\t"; + l+=st; + + + } else if (i>p_to_line) { + break; + } + + //print_line(itos(indent_stack.size())+","+itos(tc)+": "+l); + lines[i]=l; + } + + p_code=""; + for(int i=0;i<lines.size();i++) { + if (i>0) + 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<NewLineNode>(); + 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<NewLineNode>(); - 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<NewLineNode>(); + 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<int> 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="<anonymous>"; +#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<Variant> constants; Vector<StringName> global_names; Vector<int> default_arguments; - Vector<int> code; +#ifdef DEBUG_ENABLED + CharString func_cname; + const char*_func_cname; +#endif - List<StackDebug> stack_debug; + List<StackDebug> 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<String>* r_options); + virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const; /* DEBUGGER FUNCTIONS */ |