summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/globals.cpp1
-rw-r--r--core/io/config_file.cpp585
-rw-r--r--core/variant_parser.cpp543
-rw-r--r--core/variant_parser.h21
-rw-r--r--scene/2d/navigation2d.cpp37
-rw-r--r--scene/resources/scene_format_text.cpp475
-rw-r--r--scene/resources/scene_format_text.h6
-rw-r--r--tools/editor/editor_node.cpp61
-rw-r--r--tools/editor/editor_node.h4
9 files changed, 709 insertions, 1024 deletions
diff --git a/core/globals.cpp b/core/globals.cpp
index eed37c2308..b48f34d2df 100644
--- a/core/globals.cpp
+++ b/core/globals.cpp
@@ -304,6 +304,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) {
return OK;
}
+
if (OS::get_singleton()->get_resource_dir()!="") {
//OS will call Globals->get_resource_path which will be empty if not overriden!
//if the OS would rather use somewhere else, then it will not be empty.
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 75388f514a..7f74b61630 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -29,6 +29,7 @@
#include "config_file.h"
#include "os/keyboard.h"
#include "os/file_access.h"
+#include "variant_parser.h"
StringArray ConfigFile::_get_sections() const {
@@ -118,151 +119,6 @@ void ConfigFile::get_section_keys(const String& p_section,List<String> *r_keys)
}
-static String _encode_variant(const Variant& p_variant) {
-
- switch(p_variant.get_type()) {
-
- case Variant::BOOL: {
- bool val = p_variant;
- return (val?"true":"false");
- } break;
- case Variant::INT: {
- int val = p_variant;
- return itos(val);
- } break;
- case Variant::REAL: {
- float val = p_variant;
- return rtos(val)+(val==int(val)?".0":"");
- } break;
- case Variant::STRING: {
- String val = p_variant;
- return "\""+val.xml_escape()+"\"";
- } break;
- case Variant::COLOR: {
-
- Color val = p_variant;
- return "#"+val.to_html();
- } break;
- case Variant::STRING_ARRAY:
- case Variant::INT_ARRAY:
- case Variant::REAL_ARRAY:
- case Variant::ARRAY: {
- Array arr = p_variant;
- String str="[";
- for(int i=0;i<arr.size();i++) {
-
- if (i>0)
- str+=", ";
- str+=_encode_variant(arr[i]);
- }
- str+="]";
- return str;
- } break;
- case Variant::DICTIONARY: {
- Dictionary d = p_variant;
- String str="{";
- List<Variant> keys;
- d.get_key_list(&keys);
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- if (E!=keys.front())
- str+=", ";
- str+=_encode_variant(E->get());
- str+=":";
- str+=_encode_variant(d[E->get()]);
-
- }
- str+="}";
- return str;
- } break;
- case Variant::IMAGE: {
- String str="img(";
-
- Image img=p_variant;
- if (!img.empty()) {
-
- String format;
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: format="grayscale"; break;
- case Image::FORMAT_INTENSITY: format="intensity"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: format="grayscale_alpha"; break;
- case Image::FORMAT_RGB: format="rgb"; break;
- case Image::FORMAT_RGBA: format="rgba"; break;
- case Image::FORMAT_INDEXED : format="indexed"; break;
- case Image::FORMAT_INDEXED_ALPHA: format="indexed_alpha"; break;
- case Image::FORMAT_BC1: format="bc1"; break;
- case Image::FORMAT_BC2: format="bc2"; break;
- case Image::FORMAT_BC3: format="bc3"; break;
- case Image::FORMAT_BC4: format="bc4"; break;
- case Image::FORMAT_BC5: format="bc5"; break;
- case Image::FORMAT_CUSTOM: format="custom custom_size="+itos(img.get_data().size())+""; break;
- default: {}
- }
-
- str+=format+", ";
- str+=itos(img.get_mipmaps())+", ";
- str+=itos(img.get_width())+", ";
- str+=itos(img.get_height())+", ";
- DVector<uint8_t> data = img.get_data();
- int ds=data.size();
- DVector<uint8_t>::Read r = data.read();
- for(int i=0;i<ds;i++) {
- uint8_t byte = r[i];
- const char hex[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char bstr[3]={ hex[byte>>4], hex[byte&0xF], 0};
- str+=bstr;
- }
- }
- str+=")";
- return str;
- } break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ev = p_variant;
-
- switch(ev.type) {
-
- case InputEvent::KEY: {
-
- String mods;
- if (ev.key.mod.control)
- mods+="C";
- if (ev.key.mod.shift)
- mods+="S";
- if (ev.key.mod.alt)
- mods+="A";
- if (ev.key.mod.meta)
- mods+="M";
- if (mods!="")
- mods=", "+mods;
-
- return "key("+keycode_get_string(ev.key.scancode)+mods+")";
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- return "mbutton("+itos(ev.device)+", "+itos(ev.mouse_button.button_index)+")";
- } break;
- case InputEvent::JOYSTICK_BUTTON: {
-
- return "jbutton("+itos(ev.device)+", "+itos(ev.joy_button.button_index)+")";
- } break;
- case InputEvent::JOYSTICK_MOTION: {
-
- return "jaxis("+itos(ev.device)+", "+itos(ev.joy_motion.axis)+")";
- } break;
- default: {
-
- return "nil";
- } break;
-
- }
- } break;
- default: {}
- }
-
- return "nil"; //don't know wha to do with this
-}
Error ConfigFile::save(const String& p_path){
@@ -283,7 +139,9 @@ Error ConfigFile::save(const String& p_path){
for(Map<String, Variant>::Element *F=E->get().front();F;F=F->next()) {
- file->store_string(F->key()+"="+_encode_variant(F->get())+"\n");
+ String vstr;
+ VariantWriter::write_to_string(F->get(),vstr);
+ file->store_string(F->key()+"="+vstr+"\n");
}
}
@@ -292,432 +150,43 @@ Error ConfigFile::save(const String& p_path){
return OK;
}
-static Vector<String> _decode_params(const String& p_string) {
-
- int begin=p_string.find("(");
- ERR_FAIL_COND_V(begin==-1,Vector<String>());
- begin++;
- int end=p_string.find(")");
- ERR_FAIL_COND_V(end<begin,Vector<String>());
- return p_string.substr(begin,end-begin).split(",");
-}
-
-static String _get_chunk(const String& str,int &pos, int close_pos) {
-
-
- enum {
- MIN_COMMA,
- MIN_COLON,
- MIN_CLOSE,
- MIN_QUOTE,
- MIN_PARENTHESIS,
- MIN_CURLY_OPEN,
- MIN_OPEN
- };
-
- int min_pos=close_pos;
- int min_what=MIN_CLOSE;
-
-#define TEST_MIN(m_how,m_what) \
-{\
-int res = str.find(m_how,pos);\
-if (res!=-1 && res < min_pos) {\
- min_pos=res;\
- min_what=m_what;\
-}\
-}\
-
-
- TEST_MIN(",",MIN_COMMA);
- TEST_MIN("[",MIN_OPEN);
- TEST_MIN("{",MIN_CURLY_OPEN);
- TEST_MIN("(",MIN_PARENTHESIS);
- TEST_MIN("\"",MIN_QUOTE);
-
- int end=min_pos;
-
-
- switch(min_what) {
-
- case MIN_COMMA: {
- } break;
- case MIN_CLOSE: {
- //end because it's done
- } break;
- case MIN_QUOTE: {
- end=str.find("\"",min_pos+1)+1;
- ERR_FAIL_COND_V(end==-1,Variant());
-
- } break;
- case MIN_PARENTHESIS: {
-
- end=str.find(")",min_pos+1)+1;
- ERR_FAIL_COND_V(end==-1,Variant());
-
- } break;
- case MIN_OPEN: {
- int level=1;
- end++;
- while(end<close_pos) {
-
- if (str[end]=='[')
- level++;
- if (str[end]==']') {
- level--;
- if (level==0)
- break;
- }
- end++;
- }
- ERR_FAIL_COND_V(level!=0,Variant());
- end++;
- } break;
- case MIN_CURLY_OPEN: {
- int level=1;
- end++;
- while(end<close_pos) {
-
- if (str[end]=='{')
- level++;
- if (str[end]=='}') {
- level--;
- if (level==0)
- break;
- }
- end++;
- }
- ERR_FAIL_COND_V(level!=0,Variant());
- end++;
- } break;
-
- }
-
- String ret = str.substr(pos,end-pos);
-
- pos=end;
- while(pos<close_pos) {
- if (str[pos]!=',' && str[pos]!=' ' && str[pos]!=':')
- break;
- pos++;
- }
-
- return ret;
-
-}
-
-
-static Variant _decode_variant(const String& p_string) {
-
-
- String str = p_string.strip_edges();
-
- if (str.nocasecmp_to("true")==0)
- return Variant(true);
- if (str.nocasecmp_to("false")==0)
- return Variant(false);
- if (str.nocasecmp_to("nil")==0)
- return Variant();
- if (str.is_valid_float()) {
- if (str.find(".")==-1)
- return str.to_int();
- else
- return str.to_double();
-
- }
- if (str.begins_with("#")) { //string
- return Color::html(str);
- }
- if (str.begins_with("\"")) { //string
- int end = str.find_last("\"");
- ERR_FAIL_COND_V(end==0,Variant());
- return str.substr(1,end-1).xml_unescape();
-
- }
-
- if (str.begins_with("[")) { //array
-
- int close_pos = str.find_last("]");
- ERR_FAIL_COND_V(close_pos==-1,Variant());
- Array array;
-
- int pos=1;
-
- while(pos<close_pos) {
-
- String s = _get_chunk(str,pos,close_pos);
- array.push_back(_decode_variant(s));
- }
- return array;
-
- }
-
- if (str.begins_with("{")) { //array
-
- int close_pos = str.find_last("}");
- ERR_FAIL_COND_V(close_pos==-1,Variant());
- Dictionary d;
-
- int pos=1;
-
- while(pos<close_pos) {
-
- String key = _get_chunk(str,pos,close_pos);
- String data = _get_chunk(str,pos,close_pos);
- d[_decode_variant(key)]=_decode_variant(data);
- }
- return d;
-
- }
- if (str.begins_with("key")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=1 && params.size()!=2,Variant());
- int scode=0;
-
- if (params[0].is_numeric()) {
- scode=params[0].to_int();
- if (scode < 10) {
- scode=KEY_0+scode;
- }
- } else
- scode=find_keycode(params[0]);
-
- InputEvent ie;
- ie.type=InputEvent::KEY;
- ie.key.scancode=scode;
-
- if (params.size()==2) {
- String mods=params[1];
- if (mods.findn("C")!=-1)
- ie.key.mod.control=true;
- if (mods.findn("A")!=-1)
- ie.key.mod.alt=true;
- if (mods.findn("S")!=-1)
- ie.key.mod.shift=true;
- if (mods.findn("M")!=-1)
- ie.key.mod.meta=true;
- }
- return ie;
-
- }
-
- if (str.begins_with("mbutton")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::MOUSE_BUTTON;
- ie.device=params[0].to_int();
- ie.mouse_button.button_index=params[1].to_int();
-
- return ie;
- }
-
- if (str.begins_with("jbutton")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::JOYSTICK_BUTTON;
- ie.device=params[0].to_int();
- ie.joy_button.button_index=params[1].to_int();
-
- return ie;
- }
-
- if (str.begins_with("jaxis")) {
- Vector<String> params = _decode_params(p_string);
- ERR_FAIL_COND_V(params.size()!=2,Variant());
-
- InputEvent ie;
- ie.type=InputEvent::JOYSTICK_MOTION;
- ie.device=params[0].to_int();
- ie.joy_motion.axis=params[1].to_int();
-
- return ie;
- }
- if (str.begins_with("img")) {
- Vector<String> params = _decode_params(p_string);
- if (params.size()==0) {
- return Image();
- }
-
- ERR_FAIL_COND_V(params.size()!=5,Image());
-
- String format=params[0].strip_edges();
-
- Image::Format imgformat;
-
- if (format=="grayscale") {
- imgformat=Image::FORMAT_GRAYSCALE;
- } else if (format=="intensity") {
- imgformat=Image::FORMAT_INTENSITY;
- } else if (format=="grayscale_alpha") {
- imgformat=Image::FORMAT_GRAYSCALE_ALPHA;
- } else if (format=="rgb") {
- imgformat=Image::FORMAT_RGB;
- } else if (format=="rgba") {
- imgformat=Image::FORMAT_RGBA;
- } else if (format=="indexed") {
- imgformat=Image::FORMAT_INDEXED;
- } else if (format=="indexed_alpha") {
- imgformat=Image::FORMAT_INDEXED_ALPHA;
- } else if (format=="bc1") {
- imgformat=Image::FORMAT_BC1;
- } else if (format=="bc2") {
- imgformat=Image::FORMAT_BC2;
- } else if (format=="bc3") {
- imgformat=Image::FORMAT_BC3;
- } else if (format=="bc4") {
- imgformat=Image::FORMAT_BC4;
- } else if (format=="bc5") {
- imgformat=Image::FORMAT_BC5;
- } else if (format=="custom") {
- imgformat=Image::FORMAT_CUSTOM;
- } else {
-
- ERR_FAIL_V( Image() );
- }
-
- int mipmaps=params[1].to_int();
- int w=params[2].to_int();
- int h=params[3].to_int();
-
- if (w == 0 && h == 0) {
- //r_v = Image(w, h, imgformat);
- return Image();
- };
-
-
- String data=params[4];
- int datasize=data.length()/2;
- DVector<uint8_t> pixels;
- pixels.resize(datasize);
- DVector<uint8_t>::Write wb = pixels.write();
- const CharType *cptr=data.c_str();
-
- int idx=0;
- uint8_t byte;
- while( idx<datasize*2) {
-
- CharType c=*(cptr++);
-
- ERR_FAIL_COND_V(c=='<',ERR_FILE_CORRUPT);
-
- if ( (c>='0' && c<='9') || (c>='A' && c<='F') || (c>='a' && c<='f') ) {
-
- if (idx&1) {
-
- byte|=HEX2CHR(c);
- wb[idx>>1]=byte;
- } else {
-
- byte=HEX2CHR(c)<<4;
- }
-
- idx++;
- }
-
- }
-
- wb = DVector<uint8_t>::Write();
-
- return Image(w,h,mipmaps,imgformat,pixels);
- }
-
- if (str.find(",")!=-1) { //vector2 or vector3
- Vector<float> farr = str.split_floats(",",true);
- if (farr.size()==2) {
- return Point2(farr[0],farr[1]);
- }
- if (farr.size()==3) {
- return Vector3(farr[0],farr[1],farr[2]);
- }
- ERR_FAIL_V(Variant());
- }
-
-
- return Variant();
-}
Error ConfigFile::load(const String& p_path) {
Error err;
FileAccess *f= FileAccess::open(p_path,FileAccess::READ,&err);
- if (err!=OK) {
-
- return err;
- }
-
-
- String line;
- String section;
- String subpath;
-
- int line_count = 0;
-
- while(!f->eof_reached()) {
-
- String line = f->get_line().strip_edges();
- line_count++;
-
- if (line=="")
- continue;
-
- // find comments
-
- {
+ if (!f)
+ return ERR_CANT_OPEN;
- int pos=0;
- while (true) {
- int ret = line.find(";",pos);
- if (ret==-1)
- break;
+ VariantParser::StreamFile stream;
+ stream.f=f;
- int qc=0;
- for(int i=0;i<ret;i++) {
+ String assign;
+ Variant value;
+ VariantParser::Tag next_tag;
- if (line[i]=='"')
- qc++;
- }
+ int lines=0;
+ String error_text;
- if ( !(qc&1) ) {
- //not inside string, real comment
- line=line.substr(0,ret);
- break;
-
- }
-
- pos=ret+1;
+ String section;
+ while(true) {
- }
+ err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL);
+ if (err==ERR_FILE_EOF)
+ return OK;
+ else if (err!=OK) {
+ ERR_PRINTS("ConfgFile::load - "+p_path+":"+itos(lines)+" error: "+error_text);
+ memdelete(f);
+ return err;
}
- if (line.begins_with("[")) {
-
- int end = line.find_last("]");
- ERR_CONTINUE(end!=line.length()-1);
-
- section=line.substr(1,line.length()-2);
-
- } else if (line.find("=")!=-1) {
-
-
- int eqpos = line.find("=");
- String var=line.substr(0,eqpos).strip_edges();
- String value=line.substr(eqpos+1,line.length()).strip_edges();
-
- Variant val = _decode_variant(value);
-
- set_value(section,var,val);
-
- } else {
-
- if (line.length() > 0) {
- ERR_PRINT(String("Syntax error on line "+itos(line_count)+" of file "+p_path).ascii().get_data());
- };
- };
+ if (assign!=String()) {
+ set_value(section,assign,value);
+ } else if (next_tag.name!=String()) {
+ section=next_tag.name;
+ }
}
memdelete(f);
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 239b129388..82ab8ab690 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -336,6 +336,42 @@ Error VariantParser::get_token(Stream *p_stream, Token& r_token, int &line, Stri
return ERR_PARSE_ERROR;
}
+Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, int &line, String &r_err_str) {
+
+ Token token;
+ get_token(p_stream,token,line,r_err_str);
+ if (token.type!=TK_PARENTHESIS_OPEN) {
+ r_err_str="Expected '(' in old-style engine.cfg construct";
+ return ERR_PARSE_ERROR;
+ }
+
+
+ String accum;
+
+ while(true) {
+
+ CharType c=p_stream->get_char();
+
+ if (p_stream->is_eof()) {
+ r_err_str="Unexpected EOF while parsing old-style engine.cfg construct";
+ return ERR_PARSE_ERROR;
+ }
+
+ if (c==',') {
+ strings.push_back(accum.strip_edges());
+ accum=String();
+ } else if (c==')') {
+ strings.push_back(accum.strip_edges());
+ return OK;
+ } else if (c=='\n') {
+ line++;
+ }
+
+ }
+
+ return OK;
+}
+
template<class T>
Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,int &line,String &r_err_str) {
@@ -1174,6 +1210,88 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value=arr;
return OK;
+ } else if (id=="key") { // compatibility with engine.cfg
+
+ Vector<String> params;
+ Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
+ if (err)
+ return err;
+ ERR_FAIL_COND_V(params.size()!=1 && params.size()!=2,ERR_PARSE_ERROR);
+
+ int scode=0;
+
+ if (params[0].is_numeric()) {
+ scode=params[0].to_int();
+ if (scode < 10) {
+ scode=KEY_0+scode;
+ }
+ } else
+ scode=find_keycode(params[0]);
+
+ InputEvent ie;
+ ie.type=InputEvent::KEY;
+ ie.key.scancode=scode;
+
+ if (params.size()==2) {
+ String mods=params[1];
+ if (mods.findn("C")!=-1)
+ ie.key.mod.control=true;
+ if (mods.findn("A")!=-1)
+ ie.key.mod.alt=true;
+ if (mods.findn("S")!=-1)
+ ie.key.mod.shift=true;
+ if (mods.findn("M")!=-1)
+ ie.key.mod.meta=true;
+ }
+ value=ie;
+ return OK;
+
+ } else if (id=="mbutton") { // compatibility with engine.cfg
+
+ Vector<String> params;
+ Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
+ if (err)
+ return err;
+ ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
+
+ InputEvent ie;
+ ie.type=InputEvent::MOUSE_BUTTON;
+ ie.device=params[0].to_int();
+ ie.mouse_button.button_index=params[1].to_int();
+
+ value=ie;
+ return OK;
+ } else if (id=="jbutton") { // compatibility with engine.cfg
+
+ Vector<String> params;
+ Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
+ if (err)
+ return err;
+ ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
+ InputEvent ie;
+ ie.type=InputEvent::JOYSTICK_BUTTON;
+ ie.device=params[0].to_int();
+ ie.joy_button.button_index=params[1].to_int();
+
+ value=ie;
+
+ return OK;
+ } else if (id=="jaxis") { // compatibility with engine.cfg
+
+ Vector<String> params;
+ Error err = _parse_enginecfg(p_stream,params,line,r_err_str);
+ if (err)
+ return err;
+ ERR_FAIL_COND_V(params.size()!=2,ERR_PARSE_ERROR);
+
+ InputEvent ie;
+ ie.type=InputEvent::JOYSTICK_MOTION;
+ ie.device=params[0].to_int();
+ ie.joy_motion.axis=params[1].to_int();
+
+ value= ie;
+
+ return OK;
} else {
r_err_str="Unexpected identifier: '"+id+"'.";
@@ -1506,3 +1624,428 @@ Error VariantParser::parse(Stream *p_stream, Variant& r_ret, String &r_err_str,
}
+
+//////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+
+Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud,EncodeResourceFunc p_encode_res_func,void* p_encode_res_ud) {
+
+ switch( p_variant.get_type() ) {
+
+ case Variant::NIL: {
+ p_store_string_func(p_store_string_ud,"null");
+ } break;
+ case Variant::BOOL: {
+
+ p_store_string_func(p_store_string_ud,p_variant.operator bool() ? "true":"false" );
+ } break;
+ case Variant::INT: {
+
+ p_store_string_func(p_store_string_ud, itos(p_variant.operator int()) );
+ } break;
+ case Variant::REAL: {
+
+ p_store_string_func(p_store_string_ud, rtoss(p_variant.operator real_t()) );
+ } break;
+ case Variant::STRING: {
+
+ String str=p_variant;
+
+ str="\""+str.c_escape()+"\"";
+ p_store_string_func(p_store_string_ud, str );
+ } break;
+ case Variant::VECTOR2: {
+
+ Vector2 v = p_variant;
+ p_store_string_func(p_store_string_ud,"Vector2( "+rtoss(v.x) +", "+rtoss(v.y)+" )" );
+ } break;
+ case Variant::RECT2: {
+
+ Rect2 aabb = p_variant;
+ p_store_string_func(p_store_string_ud,"Rect2( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y)+" )" );
+
+ } break;
+ case Variant::VECTOR3: {
+
+ Vector3 v = p_variant;
+ p_store_string_func(p_store_string_ud,"Vector3( "+rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z)+" )");
+ } break;
+ case Variant::PLANE: {
+
+ Plane p = p_variant;
+ p_store_string_func(p_store_string_ud,"Plane( "+rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d)+" )" );
+
+ } break;
+ case Variant::_AABB: {
+
+ AABB aabb = p_variant;
+ p_store_string_func(p_store_string_ud,"AABB( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z)+" )" );
+
+ } break;
+ case Variant::QUAT: {
+
+ Quat quat = p_variant;
+ p_store_string_func(p_store_string_ud,"Quat( "+rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+" )");
+
+ } break;
+ case Variant::MATRIX32: {
+
+ String s="Matrix32( ";
+ Matrix32 m3 = p_variant;
+ for (int i=0;i<3;i++) {
+ for (int j=0;j<2;j++) {
+
+ if (i!=0 || j!=0)
+ s+=", ";
+ s+=rtoss( m3.elements[i][j] );
+ }
+ }
+
+ p_store_string_func(p_store_string_ud,s+" )");
+
+ } break;
+ case Variant::MATRIX3: {
+
+ String s="Matrix3( ";
+ Matrix3 m3 = p_variant;
+ for (int i=0;i<3;i++) {
+ for (int j=0;j<3;j++) {
+
+ if (i!=0 || j!=0)
+ s+=", ";
+ s+=rtoss( m3.elements[i][j] );
+ }
+ }
+
+ p_store_string_func(p_store_string_ud,s+" )");
+
+ } break;
+ case Variant::TRANSFORM: {
+
+ String s="Transform( ";
+ Transform t = p_variant;
+ Matrix3 &m3 = t.basis;
+ for (int i=0;i<3;i++) {
+ for (int j=0;j<3;j++) {
+
+ if (i!=0 || j!=0)
+ s+=", ";
+ s+=rtoss( m3.elements[i][j] );
+ }
+ }
+
+ s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z);
+
+ p_store_string_func(p_store_string_ud,s+" )");
+ } break;
+
+ // misc types
+ case Variant::COLOR: {
+
+ Color c = p_variant;
+ p_store_string_func(p_store_string_ud,"Color( "+rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a)+" )");
+
+ } break;
+ case Variant::IMAGE: {
+
+
+ Image img=p_variant;
+
+ if (img.empty()) {
+ p_store_string_func(p_store_string_ud,"Image()");
+ break;
+ }
+
+ String imgstr="Image( ";
+ imgstr+=itos(img.get_width());
+ imgstr+=", "+itos(img.get_height());
+ imgstr+=", "+itos(img.get_mipmaps());
+ imgstr+=", ";
+
+ switch(img.get_format()) {
+
+ case Image::FORMAT_GRAYSCALE: imgstr+="GRAYSCALE"; break;
+ case Image::FORMAT_INTENSITY: imgstr+="INTENSITY"; break;
+ case Image::FORMAT_GRAYSCALE_ALPHA: imgstr+="GRAYSCALE_ALPHA"; break;
+ case Image::FORMAT_RGB: imgstr+="RGB"; break;
+ case Image::FORMAT_RGBA: imgstr+="RGBA"; break;
+ case Image::FORMAT_INDEXED : imgstr+="INDEXED"; break;
+ case Image::FORMAT_INDEXED_ALPHA: imgstr+="INDEXED_ALPHA"; break;
+ case Image::FORMAT_BC1: imgstr+="BC1"; break;
+ case Image::FORMAT_BC2: imgstr+="BC2"; break;
+ case Image::FORMAT_BC3: imgstr+="BC3"; break;
+ case Image::FORMAT_BC4: imgstr+="BC4"; break;
+ case Image::FORMAT_BC5: imgstr+="BC5"; break;
+ case Image::FORMAT_PVRTC2: imgstr+="PVRTC2"; break;
+ case Image::FORMAT_PVRTC2_ALPHA: imgstr+="PVRTC2_ALPHA"; break;
+ case Image::FORMAT_PVRTC4: imgstr+="PVRTC4"; break;
+ case Image::FORMAT_PVRTC4_ALPHA: imgstr+="PVRTC4_ALPHA"; break;
+ case Image::FORMAT_ETC: imgstr+="ETC"; break;
+ case Image::FORMAT_ATC: imgstr+="ATC"; break;
+ case Image::FORMAT_ATC_ALPHA_EXPLICIT: imgstr+="ATC_ALPHA_EXPLICIT"; break;
+ case Image::FORMAT_ATC_ALPHA_INTERPOLATED: imgstr+="ATC_ALPHA_INTERPOLATED"; break;
+ case Image::FORMAT_CUSTOM: imgstr+="CUSTOM"; break;
+ default: {}
+ }
+
+
+ String s;
+
+ DVector<uint8_t> data = img.get_data();
+ int len = data.size();
+ DVector<uint8_t>::Read r = data.read();
+ const uint8_t *ptr=r.ptr();;
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ s+=", ";
+ s+=itos(ptr[i]);
+ }
+
+ imgstr+=", ";
+ p_store_string_func(p_store_string_ud,imgstr);
+ p_store_string_func(p_store_string_ud,s);
+ p_store_string_func(p_store_string_ud," )");
+ } break;
+ case Variant::NODE_PATH: {
+
+ String str=p_variant;
+
+ str="NodePath(\""+str.c_escape()+"\")";
+ p_store_string_func(p_store_string_ud,str);
+
+ } break;
+
+ case Variant::OBJECT: {
+
+ RES res = p_variant;
+ if (res.is_null()) {
+ p_store_string_func(p_store_string_ud,"null");
+ break; // don't save it
+ }
+
+ String res_text;
+
+ if (p_encode_res_func) {
+
+ res_text=p_encode_res_func(p_encode_res_ud,res);
+ }
+
+ if (res_text==String() && res->get_path().is_resource_file()) {
+
+ //external resource
+ String path=res->get_path();
+ res_text="Resource( \""+path+"\")";
+ }
+
+ if (res_text==String())
+ res_text="null";
+
+ p_store_string_func(p_store_string_ud,res_text);
+
+ } break;
+ case Variant::INPUT_EVENT: {
+
+ p_store_string_func(p_store_string_ud,"InputEvent()"); //will be added later
+ } break;
+ case Variant::DICTIONARY: {
+
+ Dictionary dict = p_variant;
+
+ List<Variant> keys;
+ dict.get_key_list(&keys);
+ keys.sort();
+
+ p_store_string_func(p_store_string_ud,"{ ");
+ for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
+
+ //if (!_check_type(dict[E->get()]))
+ // continue;
+ write(E->get(),p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
+ p_store_string_func(p_store_string_ud,":");
+ write(dict[E->get()],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
+ if (E->next())
+ p_store_string_func(p_store_string_ud,", ");
+ }
+
+
+ p_store_string_func(p_store_string_ud," }");
+
+
+ } break;
+ case Variant::ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"[ ");
+ Array array = p_variant;
+ int len=array.size();
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+ write(array[i],p_store_string_func,p_store_string_ud,p_encode_res_func,p_encode_res_ud);
+
+ }
+ p_store_string_func(p_store_string_ud," ]");
+
+ } break;
+
+ case Variant::RAW_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"ByteArray( ");
+ String s;
+ DVector<uint8_t> data = p_variant;
+ int len = data.size();
+ DVector<uint8_t>::Read r = data.read();
+ const uint8_t *ptr=r.ptr();;
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+
+ p_store_string_func(p_store_string_ud,itos(ptr[i]));
+
+ }
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::INT_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"IntArray( ");
+ DVector<int> data = p_variant;
+ int len = data.size();
+ DVector<int>::Read r = data.read();
+ const int *ptr=r.ptr();;
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+
+ p_store_string_func(p_store_string_ud,itos(ptr[i]));
+ }
+
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::REAL_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"FloatArray( ");
+ DVector<real_t> data = p_variant;
+ int len = data.size();
+ DVector<real_t>::Read r = data.read();
+ const real_t *ptr=r.ptr();;
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+ p_store_string_func(p_store_string_ud,rtoss(ptr[i]));
+ }
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::STRING_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"StringArray( ");
+ DVector<String> data = p_variant;
+ int len = data.size();
+ DVector<String>::Read r = data.read();
+ const String *ptr=r.ptr();;
+ String s;
+ //write_string("\n");
+
+
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+ String str=ptr[i];
+ p_store_string_func(p_store_string_ud,""+str.c_escape()+"\"");
+ }
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::VECTOR2_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"Vector2Array( ");
+ DVector<Vector2> data = p_variant;
+ int len = data.size();
+ DVector<Vector2>::Read r = data.read();
+ const Vector2 *ptr=r.ptr();;
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+ p_store_string_func(p_store_string_ud,rtoss(ptr[i].x)+", "+rtoss(ptr[i].y) );
+ }
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::VECTOR3_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"Vector3Array( ");
+ DVector<Vector3> data = p_variant;
+ int len = data.size();
+ DVector<Vector3>::Read r = data.read();
+ const Vector3 *ptr=r.ptr();;
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+ p_store_string_func(p_store_string_ud,rtoss(ptr[i].x)+", "+rtoss(ptr[i].y)+", "+rtoss(ptr[i].z) );
+ }
+
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ case Variant::COLOR_ARRAY: {
+
+ p_store_string_func(p_store_string_ud,"ColorArray( ");
+
+ DVector<Color> data = p_variant;
+ int len = data.size();
+ DVector<Color>::Read r = data.read();
+ const Color *ptr=r.ptr();;
+
+ for (int i=0;i<len;i++) {
+
+ if (i>0)
+ p_store_string_func(p_store_string_ud,", ");
+
+ p_store_string_func(p_store_string_ud,rtoss(ptr[i].r)+", "+rtoss(ptr[i].g)+", "+rtoss(ptr[i].b)+", "+rtoss(ptr[i].a) );
+
+ }
+ p_store_string_func(p_store_string_ud," )");
+
+ } break;
+ default: {}
+
+ }
+
+ return OK;
+}
+
+static Error _write_to_str(void *ud,const String& p_string) {
+
+ String *str=(String*)ud;
+ (*str)+=p_string;
+ return OK;
+}
+
+Error VariantWriter::write_to_string(const Variant& p_variant, String& r_string, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) {
+
+ r_string=String();
+
+ return write(p_variant,_write_to_str,&r_string,p_encode_res_func,p_encode_res_ud);
+
+}
diff --git a/core/variant_parser.h b/core/variant_parser.h
index e1d25f7512..2bfb244fc8 100644
--- a/core/variant_parser.h
+++ b/core/variant_parser.h
@@ -86,6 +86,7 @@ private:
template<class T>
static Error _parse_construct(Stream *p_stream, Vector<T>& r_construct, int &line, String &r_err_str);
+ static Error _parse_enginecfg(Stream *p_stream, Vector<String>& strings, int &line, String &r_err_str);
static Error _parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL);
static Error _parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL);
static Error _parse_tag(Token& token,Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL);
@@ -100,4 +101,24 @@ public:
static Error parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line,ResourceParser *p_res_parser=NULL);
};
+
+
+
+class VariantWriter {
+public:
+
+ typedef Error (*StoreStringFunc)(void *ud,const String& p_string);
+ typedef String (*EncodeResourceFunc)(void *ud,const RES& p_resource);
+
+ static Error write(const Variant& p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud,EncodeResourceFunc p_encode_res_func,void* p_encode_res_ud);
+ static Error write_to_string(const Variant& p_variant, String& r_string, EncodeResourceFunc p_encode_res_func=NULL,void* p_encode_res_ud=NULL);
+
+
+};
+
+
+
+
+
+
#endif // VARIANT_PARSER_H
diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp
index b7d51730a0..e2a4de5fac 100644
--- a/scene/2d/navigation2d.cpp
+++ b/scene/2d/navigation2d.cpp
@@ -494,7 +494,26 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
open_list.erase(least_cost_poly);
}
-
+ {
+ Polygon *p=end_poly;
+ int idx=0;
+
+ while(true) {
+ int prev = p->prev_edge;
+ int prev_n = (p->prev_edge+1)%p->edges.size();
+ Vector2 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point))*0.5;
+ String points;
+ for(int i=0;i<p->edges.size();i++) {
+ if (i>0)
+ points+=", ";
+ points+=_get_vertex(p->edges[i].point);
+ }
+ print_line("poly "+itos(idx++)+" - "+points);
+ p = p->edges[prev].C;
+ if (p==begin_poly)
+ break;
+ }
+ }
if (found_route) {
Vector<Vector2> path;
@@ -538,22 +557,27 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
bool skip=false;
- /* print_line("-----\nAPEX: "+(apex_point-end_point));
+ print_line("-----\nAPEX: "+(apex_point-end_point));
print_line("LEFT:");
print_line("\tPortal: "+(portal_left-end_point));
print_line("\tPoint: "+(left-end_point));
- print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_left,left) >= 0));
+ print_line("\tLeft Tangent: "+rtos(CLOCK_TANGENT(apex_point,portal_left,left)));
+ print_line("\tLeft Distance: "+rtos(portal_left.distance_squared_to(apex_point)));
+ print_line("\tLeft Test: "+rtos(CLOCK_TANGENT(apex_point,left,portal_right)));
print_line("RIGHT:");
print_line("\tPortal: "+(portal_right-end_point));
print_line("\tPoint: "+(right-end_point));
- print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_right,right) <= 0));
-*/
+ print_line("\tRight Tangent: "+rtos(CLOCK_TANGENT(apex_point,portal_right,right)));
+ print_line("\tRight Distance: "+rtos(portal_right.distance_squared_to(apex_point)));
+ print_line("\tRight Test: "+rtos(CLOCK_TANGENT(apex_point,right,portal_left)));
+
if (CLOCK_TANGENT(apex_point,portal_left,left) >= 0){
//process
if (portal_left.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,left,portal_right) > 0) {
left_poly=p;
portal_left=left;
+ print_line("***ADVANCE LEFT");
} else {
//_clip_path(path,apex_poly,portal_right,right_poly);
@@ -568,6 +592,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
path.push_back(apex_point);
skip=true;
//print_line("addpoint left");
+ print_line("***CLIP LEFT");
}
}
@@ -576,6 +601,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
if (portal_right.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,right,portal_left) < 0) {
right_poly=p;
portal_right=right;
+ print_line("***ADVANCE RIGHT");
} else {
//_clip_path(path,apex_poly,portal_left,left_poly);
@@ -589,6 +615,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON)
path.push_back(apex_point);
//print_line("addpoint right");
+ print_line("***CLIP RIGHT");
}
}
diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp
index 851083aecf..aef11433dc 100644
--- a/scene/resources/scene_format_text.cpp
+++ b/scene/resources/scene_format_text.cpp
@@ -12,12 +12,6 @@
#define _printerr() ERR_PRINT(String(res_path+":"+itos(lines)+" - Parse Error: "+error_text).utf8().get_data());
-Error ResourceInteractiveLoaderText::parse_property(Variant& r_v, String &r_name) {
-
- return OK;
-}
-
-
///
@@ -1026,431 +1020,37 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path,const M
/*****************************************************************************************************/
-void ResourceFormatSaverTextInstance::write_property(const String& p_name,const Variant& p_property,bool *r_ok) {
-
- if (r_ok)
- *r_ok=false;
-
- if (p_name!=String()) {
- f->store_string(p_name+" = ");
- }
-
- switch( p_property.get_type() ) {
-
- case Variant::NIL: {
- f->store_string("null");
- } break;
- case Variant::BOOL: {
-
- f->store_string(p_property.operator bool() ? "true":"false" );
- } break;
- case Variant::INT: {
-
- f->store_string( itos(p_property.operator int()) );
- } break;
- case Variant::REAL: {
-
- f->store_string( rtoss(p_property.operator real_t()) );
- } break;
- case Variant::STRING: {
-
- String str=p_property;
-
- str="\""+str.c_escape()+"\"";
- f->store_string( str );
- } break;
- case Variant::VECTOR2: {
-
- Vector2 v = p_property;
- f->store_string("Vector2( "+rtoss(v.x) +", "+rtoss(v.y)+" )" );
- } break;
- case Variant::RECT2: {
-
- Rect2 aabb = p_property;
- f->store_string("Rect2( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y)+" )" );
-
- } break;
- case Variant::VECTOR3: {
-
- Vector3 v = p_property;
- f->store_string("Vector3( "+rtoss(v.x) +", "+rtoss(v.y)+", "+rtoss(v.z)+" )");
- } break;
- case Variant::PLANE: {
-
- Plane p = p_property;
- f->store_string("Plane( "+rtoss(p.normal.x) +", "+rtoss(p.normal.y)+", "+rtoss(p.normal.z)+", "+rtoss(p.d)+" )" );
-
- } break;
- case Variant::_AABB: {
-
- AABB aabb = p_property;
- f->store_string("AABB( "+rtoss(aabb.pos.x) +", "+rtoss(aabb.pos.y) +", "+rtoss(aabb.pos.z) +", "+rtoss(aabb.size.x) +", "+rtoss(aabb.size.y) +", "+rtoss(aabb.size.z)+" )" );
-
- } break;
- case Variant::QUAT: {
-
- Quat quat = p_property;
- f->store_string("Quat( "+rtoss(quat.x)+", "+rtoss(quat.y)+", "+rtoss(quat.z)+", "+rtoss(quat.w)+" )");
-
- } break;
- case Variant::MATRIX32: {
-
- String s="Matrix32( ";
- Matrix32 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<2;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- f->store_string(s+" )");
-
- } break;
- case Variant::MATRIX3: {
-
- String s="Matrix3( ";
- Matrix3 m3 = p_property;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- f->store_string(s+" )");
-
- } break;
- case Variant::TRANSFORM: {
-
- String s="Transform( ";
- Transform t = p_property;
- Matrix3 &m3 = t.basis;
- for (int i=0;i<3;i++) {
- for (int j=0;j<3;j++) {
-
- if (i!=0 || j!=0)
- s+=", ";
- s+=rtoss( m3.elements[i][j] );
- }
- }
-
- s=s+", "+rtoss(t.origin.x) +", "+rtoss(t.origin.y)+", "+rtoss(t.origin.z);
-
- f->store_string(s+" )");
- } break;
-
- // misc types
- case Variant::COLOR: {
-
- Color c = p_property;
- f->store_string("Color( "+rtoss(c.r) +", "+rtoss(c.g)+", "+rtoss(c.b)+", "+rtoss(c.a)+" )");
-
- } break;
- case Variant::IMAGE: {
-
-
- Image img=p_property;
-
- if (img.empty()) {
- f->store_string("Image()");
- break;
- }
-
- String imgstr="Image( ";
- imgstr+=itos(img.get_width());
- imgstr+=", "+itos(img.get_height());
- imgstr+=", "+itos(img.get_mipmaps());
- imgstr+=", ";
-
- switch(img.get_format()) {
-
- case Image::FORMAT_GRAYSCALE: imgstr+="GRAYSCALE"; break;
- case Image::FORMAT_INTENSITY: imgstr+="INTENSITY"; break;
- case Image::FORMAT_GRAYSCALE_ALPHA: imgstr+="GRAYSCALE_ALPHA"; break;
- case Image::FORMAT_RGB: imgstr+="RGB"; break;
- case Image::FORMAT_RGBA: imgstr+="RGBA"; break;
- case Image::FORMAT_INDEXED : imgstr+="INDEXED"; break;
- case Image::FORMAT_INDEXED_ALPHA: imgstr+="INDEXED_ALPHA"; break;
- case Image::FORMAT_BC1: imgstr+="BC1"; break;
- case Image::FORMAT_BC2: imgstr+="BC2"; break;
- case Image::FORMAT_BC3: imgstr+="BC3"; break;
- case Image::FORMAT_BC4: imgstr+="BC4"; break;
- case Image::FORMAT_BC5: imgstr+="BC5"; break;
- case Image::FORMAT_PVRTC2: imgstr+="PVRTC2"; break;
- case Image::FORMAT_PVRTC2_ALPHA: imgstr+="PVRTC2_ALPHA"; break;
- case Image::FORMAT_PVRTC4: imgstr+="PVRTC4"; break;
- case Image::FORMAT_PVRTC4_ALPHA: imgstr+="PVRTC4_ALPHA"; break;
- case Image::FORMAT_ETC: imgstr+="ETC"; break;
- case Image::FORMAT_ATC: imgstr+="ATC"; break;
- case Image::FORMAT_ATC_ALPHA_EXPLICIT: imgstr+="ATC_ALPHA_EXPLICIT"; break;
- case Image::FORMAT_ATC_ALPHA_INTERPOLATED: imgstr+="ATC_ALPHA_INTERPOLATED"; break;
- case Image::FORMAT_CUSTOM: imgstr+="CUSTOM"; break;
- default: {}
- }
-
-
- String s;
-
- DVector<uint8_t> data = img.get_data();
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- if (i>0)
- s+=", ";
- s+=itos(ptr[i]);
- }
-
- imgstr+=", ";
- f->store_string(imgstr);
- f->store_string(s);
- f->store_string(" )");
- } break;
- case Variant::NODE_PATH: {
-
- String str=p_property;
-
- str="NodePath(\""+str.c_escape()+"\")";
- f->store_string(str);
-
- } break;
-
- case Variant::OBJECT: {
-
- RES res = p_property;
- if (res.is_null()) {
- f->store_string("null");
- if (r_ok)
- *r_ok=true;
-
- break; // don't save it
- }
-
- if (external_resources.has(res)) {
-
- f->store_string("ExtResource( "+itos(external_resources[res]+1)+" )");
- } else {
-
- if (internal_resources.has(res)) {
- f->store_string("SubResource( "+itos(internal_resources[res])+" )");
- } else if (res->get_path().length() && res->get_path().find("::")==-1) {
-
- //external resource
- String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
- f->store_string("Resource( \""+path+"\" )");
- } else {
- f->store_string("null");
- ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
- ERR_BREAK(true);
- //internal resource
- }
- }
-
- } break;
- case Variant::INPUT_EVENT: {
-
- f->store_string("InputEvent()"); //will be added later
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary dict = p_property;
-
- List<Variant> keys;
- dict.get_key_list(&keys);
- keys.sort();
-
- f->store_string("{ ");
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
- //if (!_check_type(dict[E->get()]))
- // continue;
- bool ok;
- write_property("",E->get(),&ok);
- ERR_CONTINUE(!ok);
-
- f->store_string(":");
- write_property("",dict[E->get()],&ok);
- if (!ok)
- write_property("",Variant()); //at least make the file consistent..
- if (E->next())
- f->store_string(", ");
- }
-
-
- f->store_string(" }");
-
-
- } break;
- case Variant::ARRAY: {
-
- f->store_string("[ ");
- Array array = p_property;
- int len=array.size();
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
- write_property("",array[i]);
-
-
- }
- f->store_string(" ]");
-
- } break;
-
- case Variant::RAW_ARRAY: {
-
- f->store_string("ByteArray( ");
- String s;
- DVector<uint8_t> data = p_property;
- int len = data.size();
- DVector<uint8_t>::Read r = data.read();
- const uint8_t *ptr=r.ptr();;
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
-
- f->store_string(itos(ptr[i]));
-
- }
-
- f->store_string(" )");
-
- } break;
- case Variant::INT_ARRAY: {
+String ResourceFormatSaverTextInstance::_write_resources(void *ud,const RES& p_resource) {
- f->store_string("IntArray( ");
- DVector<int> data = p_property;
- int len = data.size();
- DVector<int>::Read r = data.read();
- const int *ptr=r.ptr();;
+ ResourceFormatSaverTextInstance *rsi=(ResourceFormatSaverTextInstance*)ud;
+ return rsi->_write_resource(p_resource);
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
-
- f->store_string(itos(ptr[i]));
- }
-
-
- f->store_string(" )");
-
- } break;
- case Variant::REAL_ARRAY: {
-
- f->store_string("FloatArray( ");
- DVector<real_t> data = p_property;
- int len = data.size();
- DVector<real_t>::Read r = data.read();
- const real_t *ptr=r.ptr();;
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
- f->store_string(rtoss(ptr[i]));
- }
-
- f->store_string(" )");
-
- } break;
- case Variant::STRING_ARRAY: {
-
- f->store_string("StringArray( ");
- DVector<String> data = p_property;
- int len = data.size();
- DVector<String>::Read r = data.read();
- const String *ptr=r.ptr();;
- String s;
- //write_string("\n");
-
-
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
- String str=ptr[i];
- f->store_string(""+str.c_escape()+"\"");
- }
-
- f->store_string(" )");
-
- } break;
- case Variant::VECTOR2_ARRAY: {
-
- f->store_string("Vector2Array( ");
- DVector<Vector2> data = p_property;
- int len = data.size();
- DVector<Vector2>::Read r = data.read();
- const Vector2 *ptr=r.ptr();;
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
- f->store_string(rtoss(ptr[i].x)+", "+rtoss(ptr[i].y) );
- }
-
- f->store_string(" )");
-
- } break;
- case Variant::VECTOR3_ARRAY: {
-
- f->store_string("Vector3Array( ");
- DVector<Vector3> data = p_property;
- int len = data.size();
- DVector<Vector3>::Read r = data.read();
- const Vector3 *ptr=r.ptr();;
-
- for (int i=0;i<len;i++) {
-
- if (i>0)
- f->store_string(", ");
- f->store_string(rtoss(ptr[i].x)+", "+rtoss(ptr[i].y)+", "+rtoss(ptr[i].z) );
- }
-
- f->store_string(" )");
-
- } break;
- case Variant::COLOR_ARRAY: {
-
- f->store_string("ColorArray( ");
-
- DVector<Color> data = p_property;
- int len = data.size();
- DVector<Color>::Read r = data.read();
- const Color *ptr=r.ptr();;
-
- for (int i=0;i<len;i++) {
+}
- if (i>0)
- f->store_string(", ");
+String ResourceFormatSaverTextInstance::_write_resource(const RES& res) {
- f->store_string(rtoss(ptr[i].r)+", "+rtoss(ptr[i].g)+", "+rtoss(ptr[i].b)+", "+rtoss(ptr[i].a) );
+ if (external_resources.has(res)) {
- }
- f->store_string(" )");
+ return "ExtResource( "+itos(external_resources[res]+1)+" )";
+ } else {
- } break;
- default: {}
+ if (internal_resources.has(res)) {
+ return "SubResource( "+itos(internal_resources[res])+" )";
+ } else if (res->get_path().length() && res->get_path().find("::")==-1) {
+ //external resource
+ String path=relative_paths?local_path.path_to_file(res->get_path()):res->get_path();
+ return "Resource( \""+path+"\" )";
+ } else {
+ ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
+ ERR_FAIL_V("null");
+ //internal resource
+ }
}
- if (r_ok)
- *r_ok=true;
-
+ return "null";
}
-
void ResourceFormatSaverTextInstance::_find_resources(const Variant& p_variant,bool p_main) {
@@ -1584,11 +1184,18 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re
}
+ Vector<RES> sorted_er;
+ sorted_er.resize(external_resources.size());
+
for(Map<RES,int>::Element *E=external_resources.front();E;E=E->next()) {
- String p = E->key()->get_path();
+ sorted_er[E->get()]=E->key();
+ }
- f->store_string("[ext_resource path=\""+p+"\" type=\""+E->key()->get_save_type()+"\" id="+itos(E->get()+1)+"]\n"); //bundled
+ for(int i=0;i<sorted_er.size();i++) {
+ String p = sorted_er[i]->get_path();
+
+ f->store_string("[ext_resource path=\""+p+"\" type=\""+sorted_er[i]->get_save_type()+"\" id="+itos(i+1)+"]\n"); //bundled
}
if (external_resources.size())
@@ -1667,8 +1274,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re
if (PE->get().type==Variant::OBJECT && value.is_zero())
continue;
- write_property(name,value);
- f->store_string("\n");
+ String vars;
+ VariantWriter::write_to_string(value,vars,_write_resources,this);
+ f->store_string(name+" = "+vars+"\n");
}
@@ -1719,17 +1327,22 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re
f->store_string(header);
if (instance.is_valid()) {
+
+ String vars;
f->store_string(" instance=");
- write_property("",instance);
+ VariantWriter::write_to_string(instance,vars,_write_resources,this);
+ f->store_string(vars);
+
}
f->store_line("]\n");
for(int j=0;j<state->get_node_property_count(i);j++) {
- write_property(state->get_node_property_name(i,j),state->get_node_property_value(i,j));
- f->store_line(String());
+ String vars;
+ VariantWriter::write_to_string(state->get_node_property_value(i,j),vars,_write_resources,this);
+ f->store_string(String(state->get_node_property_name(i,j))+" = "+vars+"\n");
}
if (state->get_node_property_count(i)) {
@@ -1753,9 +1366,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re
Array binds=state->get_connection_binds(i);
f->store_string(connstr);
- if (binds.size()) {
- f->store_string(" binds=");
- write_property("",binds);
+ if (binds.size()) {
+ String vars;
+ VariantWriter::write_to_string(binds,vars,_write_resources,this);
+ f->store_string("binds= "+vars);
+
}
f->store_line("]\n");
diff --git a/scene/resources/scene_format_text.h b/scene/resources/scene_format_text.h
index 4f18af2b62..0e844c9165 100644
--- a/scene/resources/scene_format_text.h
+++ b/scene/resources/scene_format_text.h
@@ -60,7 +60,6 @@ class ResourceInteractiveLoaderText : public ResourceInteractiveLoader {
friend class ResourceFormatLoaderText;
List<RES> resource_cache;
- Error parse_property(Variant& r_v, String &r_name);
Error error;
RES resource;
@@ -117,7 +116,10 @@ class ResourceFormatSaverTextInstance {
Map<RES,int> internal_resources;
void _find_resources(const Variant& p_variant,bool p_main=false);
- void write_property(const String& p_name,const Variant& p_property,bool *r_ok=NULL);
+
+ static String _write_resources(void *ud,const RES& p_resource);
+ String _write_resource(const RES& res);
+
public:
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index b30c875866..4438123dff 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -584,59 +584,66 @@ void EditorNode::_dialog_display_file_error(String p_file,Error p_error) {
}
-void EditorNode::_get_scene_metadata() {
+void EditorNode::_get_scene_metadata(const String& p_file) {
Node *scene = editor_data.get_edited_scene_root();
if (!scene)
return;
+ String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file()+"-editstate-"+p_file.md5_text()+".cfg");
- if (scene->has_meta("__editor_plugin_states__")) {
+ Ref<ConfigFile> cf;
+ cf.instance();
- Dictionary md = scene->get_meta("__editor_plugin_states__");
- editor_data.set_editor_states(md);
+ Error err = cf->load(path);
+ if (err!=OK)
+ return; //must not exist
- }
+ List<String> esl;
+ cf->get_section_keys("editor_states",&esl);
- if (scene->has_meta("__editor_run_settings__")) {
+ Dictionary md;
+ for (List<String>::Element *E=esl.front();E;E=E->next()) {
- Dictionary md = scene->get_meta("__editor_run_settings__");
- if (md.has("run_mode"))
- run_settings_dialog->set_run_mode(md["run_mode"]);
- if (md.has("custom_args"))
- run_settings_dialog->set_custom_arguments(md["custom_args"]);
+ Variant st=cf->get_value("editor_states",E->get());
+ if (st.get_type()) {
+ md[E->get()]=st;
+ }
}
+
+ editor_data.set_editor_states(md);
+
}
-void EditorNode::_set_scene_metadata() {
+void EditorNode::_set_scene_metadata(const String& p_file) {
Node *scene = editor_data.get_edited_scene_root();
if (!scene)
return;
- { /* Editor States */
- Dictionary md = editor_data.get_editor_states();
+ scene->set_meta("__editor_run_settings__",Variant()); //clear it (no point in keeping it)
+ scene->set_meta("__editor_plugin_states__",Variant());
- if (!md.empty()) {
- scene->set_meta("__editor_plugin_states__",md);
- }
- }
+ String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file()+"-editstate-"+p_file.md5_text()+".cfg");
- { /* Run Settings */
+ Ref<ConfigFile> cf;
+ cf.instance();
+ Dictionary md = editor_data.get_editor_states();
+ List<Variant> keys;
+ md.get_key_list(&keys);
- Dictionary md;
- md["run_mode"]=run_settings_dialog->get_run_mode();
- md["custom_args"]=run_settings_dialog->get_custom_arguments();
- scene->set_meta("__editor_run_settings__",md);
- }
-
+ for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
+ cf->set_value("editor_states",E->get(),md[E->get()]);
+ }
+ Error err = cf->save(path);
+ ERR_FAIL_COND(err!=OK);
}
@@ -954,7 +961,7 @@ void EditorNode::_save_scene(String p_file) {
}
- _set_scene_metadata();
+ _set_scene_metadata(p_file);
Ref<PackedScene> sdata;
@@ -3652,7 +3659,7 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo
new_scene->set_scene_instance_state(Ref<SceneState>());
set_edited_scene(new_scene);
- _get_scene_metadata();
+ _get_scene_metadata(p_scene);
/*
editor_data.set_edited_scene_root(new_scene);
diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h
index 0a087eb1ed..36f23490d8 100644
--- a/tools/editor/editor_node.h
+++ b/tools/editor/editor_node.h
@@ -420,8 +420,8 @@ class EditorNode : public Node {
void _node_renamed();
void _editor_select(int p_which);
- void _set_scene_metadata();
- void _get_scene_metadata();
+ void _set_scene_metadata(const String &p_file);
+ void _get_scene_metadata(const String& p_file);
void _update_title();
void _update_scene_tabs();
void _close_messages();