2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* resource_format_xml.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-02 10:27:24 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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 "resource_format_xml.h"
|
|
|
|
#include "globals.h"
|
2015-08-23 23:15:56 +00:00
|
|
|
#include "os/dir_access.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "version.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceInteractiveLoaderXML::Tag *ResourceInteractiveLoaderXML::parse_tag(bool *r_exit, bool p_printerr, List<String> *r_order) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (get_char() != '<' && !f->eof_reached()) {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
if (f->eof_reached()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Tag tag;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool exit = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (r_exit)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_exit = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool complete = false;
|
|
|
|
while (!f->eof_reached()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
|
|
|
if (c < 33 && tag.name.length() && !exit) {
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (c == '>') {
|
|
|
|
complete = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (c == '/') {
|
|
|
|
exit = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
tag.name += c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f->eof_reached()) {
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exit) {
|
|
|
|
if (!tag_stack.size()) {
|
|
|
|
if (!p_printerr)
|
|
|
|
return NULL;
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Unmatched exit tag </" + tag.name + ">");
|
|
|
|
ERR_FAIL_COND_V(!tag_stack.size(), NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tag_stack.back()->get().name != tag.name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!p_printerr)
|
|
|
|
return NULL;
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Mismatched exit tag. Got </" + tag.name + ">, expected </" + tag_stack.back()->get().name + ">");
|
|
|
|
ERR_FAIL_COND_V(tag_stack.back()->get().name != tag.name, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!complete) {
|
2017-03-18 23:36:26 +00:00
|
|
|
while (get_char() != '>' && !f->eof_reached()) {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
if (f->eof_reached())
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_exit)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_exit = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
tag_stack.pop_back();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!complete) {
|
|
|
|
String name;
|
2014-02-18 20:37:58 +00:00
|
|
|
CharString r_value;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool reading_value = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (!f->eof_reached()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
|
|
|
if (c == '>') {
|
2014-02-18 20:37:58 +00:00
|
|
|
if (r_value.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-18 20:37:58 +00:00
|
|
|
r_value.push_back(0);
|
2015-08-23 23:15:56 +00:00
|
|
|
String str;
|
|
|
|
str.parse_utf8(r_value.get_data());
|
2017-03-18 23:36:26 +00:00
|
|
|
tag.args[name] = str;
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_order)
|
|
|
|
r_order->push_back(name);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (((!reading_value && (c < 33)) || c == '=' || c == '"' || c == '\'') && tag.name.length()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!reading_value && name.length()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
reading_value = true;
|
2014-02-18 20:37:58 +00:00
|
|
|
} else if (reading_value && r_value.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-02-18 20:37:58 +00:00
|
|
|
r_value.push_back(0);
|
2015-08-23 23:15:56 +00:00
|
|
|
String str;
|
|
|
|
str.parse_utf8(r_value.get_data());
|
2017-03-18 23:36:26 +00:00
|
|
|
tag.args[name] = str;
|
2015-08-23 23:15:56 +00:00
|
|
|
if (r_order)
|
|
|
|
r_order->push_back(name);
|
2017-03-18 23:36:26 +00:00
|
|
|
name = "";
|
2014-02-18 20:37:58 +00:00
|
|
|
r_value.clear();
|
2017-03-18 23:36:26 +00:00
|
|
|
reading_value = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (reading_value) {
|
|
|
|
|
2014-02-18 20:37:58 +00:00
|
|
|
r_value.push_back(c);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
name += c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f->eof_reached())
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag_stack.push_back(tag);
|
|
|
|
|
|
|
|
return &tag_stack.back()->get();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceInteractiveLoaderXML::close_tag(const String &p_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int level = 0;
|
|
|
|
bool inside_tag = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (f->eof_reached()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": EOF found while attempting to find </" + p_name + ">");
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t c = get_char();
|
|
|
|
|
|
|
|
if (c == '<') {
|
|
|
|
|
|
|
|
if (inside_tag) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Malformed XML. Already inside Tag.");
|
|
|
|
ERR_FAIL_COND_V(inside_tag, ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
inside_tag = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
c = get_char();
|
|
|
|
if (c == '/') {
|
|
|
|
|
|
|
|
--level;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
++level;
|
|
|
|
};
|
|
|
|
} else if (c == '>') {
|
|
|
|
|
|
|
|
if (!inside_tag) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Malformed XML. Already outside Tag");
|
|
|
|
ERR_FAIL_COND_V(!inside_tag, ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
inside_tag = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (level == -1) {
|
|
|
|
tag_stack.pop_back();
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceInteractiveLoaderXML::unquote(String &p_str) {
|
2014-12-07 14:33:57 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_str = p_str.strip_edges().replace("\"", "").xml_unescape();
|
2014-06-11 13:41:03 +00:00
|
|
|
|
|
|
|
/*p_str=p_str.strip_edges();
|
2014-02-10 01:10:30 +00:00
|
|
|
p_str=p_str.replace("\"","");
|
|
|
|
p_str=p_str.replace(">","<");
|
|
|
|
p_str=p_str.replace("<",">");
|
|
|
|
p_str=p_str.replace("'","'");
|
|
|
|
p_str=p_str.replace(""","\"");
|
|
|
|
for (int i=1;i<32;i++) {
|
|
|
|
|
|
|
|
char chr[2]={i,0};
|
|
|
|
p_str=p_str.replace("&#"+String::num(i)+";",chr);
|
|
|
|
}
|
|
|
|
p_str=p_str.replace("&","&");
|
2014-06-11 13:41:03 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
//p_str.parse_utf8( p_str.ascii(true).get_data() );
|
|
|
|
}
|
|
|
|
|
|
|
|
Error ResourceInteractiveLoaderXML::goto_end_of_tag() {
|
|
|
|
|
|
|
|
uint8_t c;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
c = get_char();
|
|
|
|
if (c == '>') //closetag
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
if (f->eof_reached()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": EOF found while attempting to find close tag.");
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tag_stack.pop_back();
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error ResourceInteractiveLoaderXML::parse_property_data(String &r_data) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_data = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
CharString cs;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
|
|
|
if (c == '<')
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
cs.push_back(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
cs.push_back(0);
|
|
|
|
|
|
|
|
r_data.parse_utf8(cs.get_data());
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (get_char() != '>' && !f->eof_reached()) {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
if (f->eof_reached()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Malformed XML.");
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_data = r_data.strip_edges();
|
2014-02-10 01:10:30 +00:00
|
|
|
tag_stack.pop_back();
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceInteractiveLoaderXML::_parse_array_element(Vector<char> &buff, bool p_number_only, FileAccess *f, bool *end) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (buff.empty())
|
|
|
|
buff.resize(32); // optimi
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int buff_max = buff.size();
|
|
|
|
int buff_size = 0;
|
|
|
|
*end = false;
|
|
|
|
char *buffptr = &buff[0];
|
|
|
|
bool found = false;
|
|
|
|
bool quoted = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
char c = get_char();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c == 0) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": File corrupt (zero found).");
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (c == '"') {
|
|
|
|
quoted = !quoted;
|
|
|
|
} else if ((!quoted && ((p_number_only && c < 33) || c == ',')) || c == '<') {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c == '<') {
|
|
|
|
*end = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c < 32 && f->eof_reached()) {
|
|
|
|
*end = true;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": File corrupt (unexpected EOF).");
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
found = true;
|
|
|
|
if (buff_size >= buff_max) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
buff_max++;
|
|
|
|
buff.resize(buff_max);
|
2017-03-18 23:36:26 +00:00
|
|
|
buffptr = buff.ptr();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buffptr[buff_size] = c;
|
2014-02-10 01:10:30 +00:00
|
|
|
buff_size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (buff_size >= buff_max) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
buff_max++;
|
|
|
|
buff.resize(buff_max);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
buff[buff_size] = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
buff_size++;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceInteractiveLoaderXML::parse_property(Variant &r_v, String &r_name, bool p_for_export_data) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool exit;
|
|
|
|
Tag *tag = parse_tag(&exit);
|
|
|
|
|
|
|
|
if (!tag) {
|
|
|
|
if (exit) // shouldn't have exited
|
|
|
|
return ERR_FILE_EOF;
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": File corrupt (No Property Tag).");
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Variant();
|
|
|
|
r_name = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//ERR_FAIL_COND_V(tag->name!="property",ERR_FILE_CORRUPT);
|
|
|
|
//ERR_FAIL_COND_V(!tag->args.has("name"),ERR_FILE_CORRUPT);
|
2017-03-18 23:36:26 +00:00
|
|
|
// ERR_FAIL_COND_V(!tag->args.has("type"),ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//String name=tag->args["name"];
|
|
|
|
//ERR_FAIL_COND_V(name=="",ERR_FILE_CORRUPT);
|
2017-03-18 23:36:26 +00:00
|
|
|
String type = tag->name;
|
|
|
|
String name = tag->args["name"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (type == "") {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": 'type' field is empty.");
|
|
|
|
ERR_FAIL_COND_V(type == "", ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (type == "dictionary") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Dictionary d(tag->args.has("shared") && (String(tag->args["shared"]) == "true" || String(tag->args["shared"]) == "1"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Error err;
|
|
|
|
String tagname;
|
|
|
|
Variant key;
|
|
|
|
|
|
|
|
int dictline = get_current_line();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = parse_property(key, tagname, p_for_export_data);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err && err != ERR_FILE_EOF) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error parsing dictionary: " + name + " (from line " + itos(dictline) + ")");
|
|
|
|
ERR_FAIL_COND_V(err && err != ERR_FILE_EOF, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
//ERR_FAIL_COND_V(tagname!="key",ERR_FILE_CORRUPT);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
Variant value;
|
2017-03-18 23:36:26 +00:00
|
|
|
err = parse_property(value, tagname, p_for_export_data);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (err) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error parsing dictionary: " + name + " (from line " + itos(dictline) + ")");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
//ERR_FAIL_COND_V(tagname!="value",ERR_FILE_CORRUPT);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
d[key] = value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//err=parse_property_data(name); // skip the rest
|
|
|
|
//ERR_FAIL_COND_V(err,err);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
|
|
|
r_v = d;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
|
|
|
bool shared = tag->args.has("shared") && (String(tag->args["shared"]) == "true" || String(tag->args["shared"]) == "1");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Array array(shared);
|
|
|
|
array.resize(len);
|
|
|
|
|
|
|
|
Error err;
|
|
|
|
Variant v;
|
|
|
|
String tagname;
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
|
|
|
while ((err = parse_property(v, tagname, p_for_export_data)) == OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(idx < 0 || idx >= len);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
array.set(idx, v);
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx != len) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error loading array (size mismatch): " + name);
|
|
|
|
ERR_FAIL_COND_V(idx != len, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != ERR_FILE_EOF) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error loading array: " + name);
|
|
|
|
ERR_FAIL_COND_V(err != ERR_FILE_EOF, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//err=parse_property_data(name); // skip the rest
|
|
|
|
//ERR_FAIL_COND_V(err,err);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
|
|
|
r_v = array;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "resource") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (tag->args.has("path")) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = tag->args["path"];
|
2014-02-10 01:10:30 +00:00
|
|
|
String hint;
|
|
|
|
if (tag->args.has("resource_type"))
|
2017-03-18 23:36:26 +00:00
|
|
|
hint = tag->args["resource_type"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-13 01:52:02 +00:00
|
|
|
if (p_for_export_data) {
|
|
|
|
|
|
|
|
String prop;
|
|
|
|
|
|
|
|
if (path.begins_with("local://")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
prop = "@RESLOCAL:" + itos(path.replace("local://", "").to_int());
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = prop;
|
2017-02-13 01:52:02 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (path.begins_with("local://"))
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
path = path.replace("local://", local_path + "::");
|
|
|
|
else if (path.find("://") == -1 && path.is_rel_path()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// path is relative to file being loaded, so convert to a resource path
|
2017-03-18 23:36:26 +00:00
|
|
|
path = Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (remaps.has(path)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
path = remaps[path];
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
//take advantage of the resource loader cache. The resource is cached on it, even if
|
2017-03-18 23:36:26 +00:00
|
|
|
RES res = ResourceLoader::load(path, hint);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (res.is_null()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
WARN_PRINT(String("Couldn't load resource: " + path).ascii().get_data());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = res.get_ref_ptr();
|
2015-08-23 23:15:56 +00:00
|
|
|
} else if (tag->args.has("external")) {
|
|
|
|
|
|
|
|
int index = tag->args["external"].to_int();
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
if (p_for_export_data) {
|
|
|
|
|
|
|
|
String prop;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
prop = "@RESEXTERNAL:" + itos(index);
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = prop;
|
2017-02-13 01:52:02 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (ext_resources.has(index)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = ext_resources[index].path;
|
|
|
|
String type = ext_resources[index].type;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
//take advantage of the resource loader cache. The resource is cached on it, even if
|
2017-03-18 23:36:26 +00:00
|
|
|
RES res = ResourceLoader::load(path, type);
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
if (res.is_null()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
WARN_PRINT(String("Couldn't load externalresource: " + path).ascii().get_data());
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = res.get_ref_ptr();
|
2015-08-23 23:15:56 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
WARN_PRINT(String("Invalid external resource index: " + itos(index)).ascii().get_data());
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = goto_end_of_tag();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (err) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error closing <resource> tag.");
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "image") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("encoding")) {
|
|
|
|
//empty image
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Image();
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Image missing 'encoding' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("encoding"), ERR_FILE_CORRUPT);
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Image missing 'width' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("width"), ERR_FILE_CORRUPT);
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Image missing 'height' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("height"), ERR_FILE_CORRUPT);
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Image missing 'format' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("format"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String encoding = tag->args["encoding"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (encoding == "raw") {
|
|
|
|
String width = tag->args["width"];
|
|
|
|
String height = tag->args["height"];
|
|
|
|
String format = tag->args["format"];
|
|
|
|
int mipmaps = tag->args.has("mipmaps") ? int(tag->args["mipmaps"].to_int()) : int(0);
|
|
|
|
int custom_size = tag->args.has("custom_size") ? int(tag->args["custom_size"].to_int()) : int(0);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Image::Format imgformat;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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 == "pvrtc2") {
|
|
|
|
imgformat = Image::FORMAT_PVRTC2;
|
|
|
|
} else if (format == "pvrtc2a") {
|
|
|
|
imgformat = Image::FORMAT_PVRTC2_ALPHA;
|
|
|
|
} else if (format == "pvrtc4") {
|
|
|
|
imgformat = Image::FORMAT_PVRTC4;
|
|
|
|
} else if (format == "pvrtc4a") {
|
|
|
|
imgformat = Image::FORMAT_PVRTC4_ALPHA;
|
|
|
|
} else if (format == "etc") {
|
|
|
|
imgformat = Image::FORMAT_ETC;
|
|
|
|
} else if (format == "atc") {
|
|
|
|
imgformat = Image::FORMAT_ATC;
|
|
|
|
} else if (format == "atcai") {
|
|
|
|
imgformat = Image::FORMAT_ATC_ALPHA_INTERPOLATED;
|
|
|
|
} else if (format == "atcae") {
|
|
|
|
imgformat = Image::FORMAT_ATC_ALPHA_EXPLICIT;
|
|
|
|
} else if (format == "custom") {
|
|
|
|
imgformat = Image::FORMAT_CUSTOM;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int datasize;
|
2017-03-18 23:36:26 +00:00
|
|
|
int w = width.to_int();
|
|
|
|
int h = height.to_int();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-07 05:26:41 +00:00
|
|
|
if (w == 0 && h == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//r_v = Image(w, h, imgformat);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Image();
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (imgformat == Image::FORMAT_CUSTOM) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
datasize = custom_size;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
datasize = Image::get_image_data_size(h, w, imgformat, mipmaps);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (datasize == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//r_v = Image(w, h, imgformat);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Image();
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
|
|
|
|
DVector<uint8_t> pixels;
|
|
|
|
pixels.resize(datasize);
|
|
|
|
DVector<uint8_t>::Write wb = pixels.write();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
uint8_t byte;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < datasize * 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(c == '<', ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx & 1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
byte |= HEX2CHR(c);
|
|
|
|
wb[idx >> 1] = byte;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
byte = HEX2CHR(c) << 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
wb = DVector<uint8_t>::Write();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Image(w, h, mipmaps, imgformat, pixels);
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "raw_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": RawArray missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<uint8_t> bytes;
|
|
|
|
bytes.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<uint8_t>::Write w = bytes.write();
|
|
|
|
uint8_t *bytesptr = w.ptr();
|
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
uint8_t byte;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len * 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
|
|
|
if (c <= 32)
|
2014-06-11 13:41:03 +00:00
|
|
|
continue;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx & 1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
byte |= HEX2CHR(c);
|
|
|
|
bytesptr[idx >> 1] = byte;
|
2014-06-11 13:41:03 +00:00
|
|
|
//printf("%x\n",int(byte));
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
byte = HEX2CHR(c) << 4;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<uint8_t>::Write();
|
|
|
|
r_v = bytes;
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "int_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<int> ints;
|
|
|
|
ints.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<int>::Write w = ints.write();
|
|
|
|
int *intsptr = w.ptr();
|
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
String str;
|
|
|
|
#if 0
|
|
|
|
while( idx<len ) {
|
|
|
|
|
|
|
|
|
|
|
|
CharType c=get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
|
|
|
|
if (c<33 || c==',' || c=='<') {
|
|
|
|
|
|
|
|
if (str.length()) {
|
|
|
|
|
|
|
|
intsptr[idx]=str.to_int();
|
|
|
|
str="";
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c=='<') {
|
|
|
|
|
|
|
|
while(get_char()!='>' && !f->eof_reached()) {}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
str+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
Vector<char> tmpdata;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool end = false;
|
|
|
|
Error err = _parse_array_element(tmpdata, true, f, &end);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
intsptr[idx] = String::to_int(&tmpdata[0]);
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
|
|
|
if (end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<int>::Write();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = ints;
|
|
|
|
Error err = goto_end_of_tag();
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "real_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<real_t> reals;
|
|
|
|
reals.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<real_t>::Write w = reals.write();
|
|
|
|
real_t *realsptr = w.ptr();
|
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
String str;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
while( idx<len ) {
|
|
|
|
|
|
|
|
|
|
|
|
CharType c=get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
|
|
|
|
|
|
|
|
if (c<33 || c==',' || c=='<') {
|
|
|
|
|
|
|
|
if (str.length()) {
|
|
|
|
|
|
|
|
realsptr[idx]=str.to_double();
|
|
|
|
str="";
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c=='<') {
|
|
|
|
|
|
|
|
while(get_char()!='>' && !f->eof_reached()) {}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
str+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
Vector<char> tmpdata;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool end = false;
|
|
|
|
Error err = _parse_array_element(tmpdata, true, f, &end);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
realsptr[idx] = String::to_double(&tmpdata[0]);
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<real_t>::Write();
|
|
|
|
r_v = reals;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = goto_end_of_tag();
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "string_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
#if 0
|
|
|
|
if (!tag->args.has("len")) {
|
|
|
|
ERR_EXPLAIN(local_path+":"+itos(get_current_line())+": Array missing 'len' field: "+name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"),ERR_FILE_CORRUPT);
|
|
|
|
}
|
|
|
|
int len=tag->args["len"].to_int();
|
|
|
|
|
|
|
|
DVector<String> strings;
|
|
|
|
strings.resize(len);
|
|
|
|
DVector<String>::Write w=strings.write();
|
|
|
|
String *stringsptr=w.ptr();
|
|
|
|
int idx=0;
|
|
|
|
String str;
|
|
|
|
|
|
|
|
bool inside_str=false;
|
|
|
|
CharString cs;
|
|
|
|
while( idx<len ) {
|
|
|
|
|
|
|
|
|
|
|
|
CharType c=get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
|
|
|
|
|
|
|
|
if (c=='"') {
|
|
|
|
if (inside_str) {
|
|
|
|
|
|
|
|
cs.push_back(0);
|
|
|
|
String str;
|
|
|
|
str.parse_utf8(cs.get_data());
|
|
|
|
unquote(str);
|
|
|
|
stringsptr[idx]=str;
|
|
|
|
cs.clear();
|
|
|
|
idx++;
|
|
|
|
inside_str=false;
|
|
|
|
} else {
|
|
|
|
inside_str=true;
|
|
|
|
}
|
|
|
|
} else if (c=='<') {
|
|
|
|
|
|
|
|
while(get_char()!='>' && !f->eof_reached()) {}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
} else if (inside_str){
|
|
|
|
|
|
|
|
cs.push_back(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w=DVector<String>::Write();
|
|
|
|
r_v=strings;
|
|
|
|
String sdfsdfg;
|
|
|
|
Error err=parse_property_data(sdfsdfg);
|
|
|
|
ERR_FAIL_COND_V(err,err);
|
|
|
|
|
|
|
|
r_name=name;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
#endif
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": String Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
StringArray array;
|
|
|
|
array.resize(len);
|
|
|
|
DVector<String>::Write w = array.write();
|
|
|
|
|
|
|
|
Error err;
|
|
|
|
Variant v;
|
|
|
|
String tagname;
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while ((err = parse_property(v, tagname)) == OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_CONTINUE(idx < 0 || idx >= len);
|
2014-02-10 01:10:30 +00:00
|
|
|
String str = v; //convert back to string
|
2017-03-18 23:36:26 +00:00
|
|
|
w[idx] = str;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx != len) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error loading array (size mismatch): " + name);
|
|
|
|
ERR_FAIL_COND_V(idx != len, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != ERR_FILE_EOF) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Error loading array: " + name);
|
|
|
|
ERR_FAIL_COND_V(err != ERR_FILE_EOF, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//err=parse_property_data(name); // skip the rest
|
|
|
|
//ERR_FAIL_COND_V(err,err);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
|
|
|
r_v = array;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "vector3_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<Vector3> vectors;
|
|
|
|
vectors.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<Vector3>::Write w = vectors.write();
|
|
|
|
Vector3 *vectorsptr = w.ptr();
|
|
|
|
int idx = 0;
|
|
|
|
int subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector3 auxvec;
|
|
|
|
String str;
|
|
|
|
|
|
|
|
// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
|
|
|
|
#if 0
|
|
|
|
while( idx<len ) {
|
|
|
|
|
|
|
|
|
|
|
|
CharType c=get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
|
|
|
|
|
|
|
|
if (c<33 || c==',' || c=='<') {
|
|
|
|
|
|
|
|
if (str.length()) {
|
|
|
|
|
|
|
|
auxvec[subidx]=str.to_double();
|
|
|
|
subidx++;
|
|
|
|
str="";
|
|
|
|
if (subidx==3) {
|
|
|
|
vectorsptr[idx]=auxvec;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
subidx=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c=='<') {
|
|
|
|
|
|
|
|
while(get_char()!='>' && !f->eof_reached()) {}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
str+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
Vector<char> tmpdata;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool end = false;
|
|
|
|
Error err = _parse_array_element(tmpdata, true, f, &end);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
auxvec[subidx] = String::to_double(&tmpdata[0]);
|
2014-02-10 01:10:30 +00:00
|
|
|
subidx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (subidx == 3) {
|
|
|
|
vectorsptr[idx] = auxvec;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Premature end of vector3 array");
|
|
|
|
ERR_FAIL_COND_V(idx < len, ERR_FILE_CORRUPT);
|
|
|
|
// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<Vector3>::Write();
|
|
|
|
r_v = vectors;
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = goto_end_of_tag();
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "vector2_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<Vector2> vectors;
|
|
|
|
vectors.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<Vector2>::Write w = vectors.write();
|
|
|
|
Vector2 *vectorsptr = w.ptr();
|
|
|
|
int idx = 0;
|
|
|
|
int subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 auxvec;
|
|
|
|
String str;
|
|
|
|
|
|
|
|
// uint64_t tbegin = OS::get_singleton()->get_ticks_usec();
|
|
|
|
#if 0
|
|
|
|
while( idx<len ) {
|
|
|
|
|
|
|
|
|
|
|
|
CharType c=get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
|
|
|
|
|
|
|
|
if (c<22 || c==',' || c=='<') {
|
|
|
|
|
|
|
|
if (str.length()) {
|
|
|
|
|
|
|
|
auxvec[subidx]=str.to_double();
|
|
|
|
subidx++;
|
|
|
|
str="";
|
|
|
|
if (subidx==2) {
|
|
|
|
vectorsptr[idx]=auxvec;
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
subidx=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c=='<') {
|
|
|
|
|
|
|
|
while(get_char()!='>' && !f->eof_reached()) {}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(),ERR_FILE_CORRUPT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
str+=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
Vector<char> tmpdata;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool end = false;
|
|
|
|
Error err = _parse_array_element(tmpdata, true, f, &end);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
auxvec[subidx] = String::to_double(&tmpdata[0]);
|
2014-02-10 01:10:30 +00:00
|
|
|
subidx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (subidx == 2) {
|
|
|
|
vectorsptr[idx] = auxvec;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (end)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Premature end of vector2 array");
|
|
|
|
ERR_FAIL_COND_V(idx < len, ERR_FILE_CORRUPT);
|
|
|
|
// double time_taken = (OS::get_singleton()->get_ticks_usec() - tbegin)/1000000.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<Vector2>::Write();
|
|
|
|
r_v = vectors;
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = goto_end_of_tag();
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "color_array") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("len")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Array missing 'len' field: " + name);
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("len"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = tag->args["len"].to_int();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DVector<Color> colors;
|
|
|
|
colors.resize(len);
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<Color>::Write w = colors.write();
|
|
|
|
Color *colorsptr = w.ptr();
|
|
|
|
int idx = 0;
|
|
|
|
int subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
Color auxcol;
|
|
|
|
String str;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (idx < len) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType c = get_char();
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c < 33 || c == ',' || c == '<') {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (str.length()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
auxcol[subidx] = str.to_double();
|
2014-02-10 01:10:30 +00:00
|
|
|
subidx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
str = "";
|
|
|
|
if (subidx == 4) {
|
|
|
|
colorsptr[idx] = auxcol;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
subidx = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c == '<') {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (get_char() != '>' && !f->eof_reached()) {
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
str += c;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
w = DVector<Color>::Write();
|
|
|
|
r_v = colors;
|
2014-02-10 01:10:30 +00:00
|
|
|
String sdfsdfg;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = parse_property_data(sdfsdfg);
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
String data;
|
|
|
|
Error err = parse_property_data(data);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err != OK, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (type == "nil") {
|
2014-02-10 01:10:30 +00:00
|
|
|
// uh do nothing
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "bool") {
|
2014-02-10 01:10:30 +00:00
|
|
|
// uh do nothing
|
2017-03-18 23:36:26 +00:00
|
|
|
if (data.nocasecmp_to("true") == 0 || data.to_int() != 0)
|
|
|
|
r_v = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = false;
|
|
|
|
} else if (type == "int") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = data.to_int();
|
|
|
|
} else if (type == "real") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = data.to_double();
|
|
|
|
} else if (type == "string") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = data;
|
2014-02-10 01:10:30 +00:00
|
|
|
unquote(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = str;
|
|
|
|
} else if (type == "vector3") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Vector3(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double(),
|
|
|
|
data.get_slicec(',', 2).to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "vector2") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Vector2(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "plane") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Plane(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double(),
|
|
|
|
data.get_slicec(',', 2).to_double(),
|
|
|
|
data.get_slicec(',', 3).to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "quaternion") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Quat(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double(),
|
|
|
|
data.get_slicec(',', 2).to_double(),
|
|
|
|
data.get_slicec(',', 3).to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "rect2") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Rect2(
|
|
|
|
Vector2(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double()),
|
|
|
|
Vector2(
|
|
|
|
data.get_slicec(',', 2).to_double(),
|
|
|
|
data.get_slicec(',', 3).to_double()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "aabb") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = AABB(
|
|
|
|
Vector3(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double(),
|
|
|
|
data.get_slicec(',', 2).to_double()),
|
|
|
|
Vector3(
|
|
|
|
data.get_slicec(',', 3).to_double(),
|
|
|
|
data.get_slicec(',', 4).to_double(),
|
|
|
|
data.get_slicec(',', 5).to_double()));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "matrix32") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Matrix32 m3;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
|
|
|
m3.elements[i][j] = data.get_slicec(',', i * 2 + j).to_double();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = m3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "matrix3") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Matrix3 m3;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
m3.elements[i][j] = data.get_slicec(',', i * 3 + j).to_double();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = m3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "transform") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Transform tr;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
tr.basis.elements[i][j] = data.get_slicec(',', i * 3 + j).to_double();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
tr.origin = Vector3(
|
|
|
|
data.get_slicec(',', 9).to_double(),
|
|
|
|
data.get_slicec(',', 10).to_double(),
|
|
|
|
data.get_slicec(',', 11).to_double());
|
|
|
|
r_v = tr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "color") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = Color(
|
|
|
|
data.get_slicec(',', 0).to_double(),
|
|
|
|
data.get_slicec(',', 1).to_double(),
|
|
|
|
data.get_slicec(',', 2).to_double(),
|
|
|
|
data.get_slicec(',', 3).to_double());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (type == "node_path") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = data;
|
2014-02-10 01:10:30 +00:00
|
|
|
unquote(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
r_v = NodePath(str);
|
|
|
|
} else if (type == "input_event") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// ?
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Unrecognized tag in file: " + type);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(ERR_FILE_CORRUPT);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_name = name;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResourceInteractiveLoaderXML::get_current_line() const {
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t ResourceInteractiveLoaderXML::get_char() const {
|
|
|
|
|
|
|
|
uint8_t c = f->get_8();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c == '\n')
|
2014-02-10 01:10:30 +00:00
|
|
|
lines++;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceInteractiveLoaderXML::set_local_path(const String &p_local_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res_path = p_local_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Resource> ResourceInteractiveLoaderXML::get_resource() {
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
Error ResourceInteractiveLoaderXML::poll() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (error != OK)
|
2014-02-10 01:10:30 +00:00
|
|
|
return error;
|
|
|
|
|
|
|
|
bool exit;
|
|
|
|
Tag *tag = parse_tag(&exit);
|
|
|
|
|
|
|
|
if (!tag) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!exit) // shouldn't have exited
|
|
|
|
ERR_FAIL_V(error);
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_EOF;
|
2014-02-10 01:10:30 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
RES res;
|
|
|
|
//Object *obj=NULL;
|
|
|
|
|
|
|
|
bool main;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tag->name == "ext_resource") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> missing 'path' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("path"), ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String type = "Resource";
|
2014-02-10 01:10:30 +00:00
|
|
|
if (tag->args.has("type"))
|
2017-03-18 23:36:26 +00:00
|
|
|
type = tag->args["type"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String path = tag->args["path"];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> can't use a local path, this is a bug?.");
|
|
|
|
ERR_FAIL_COND_V(path.begins_with("local://"), ERR_FILE_CORRUPT);
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (path.find("://") == -1 && path.is_rel_path()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// path is relative to file being loaded, so convert to a resource path
|
2017-03-18 23:36:26 +00:00
|
|
|
path = Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (remaps.has(path)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
path = remaps[path];
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
RES res = ResourceLoader::load(path, type);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (res.is_null()) {
|
|
|
|
|
|
|
|
if (ResourceLoader::get_abort_on_missing_resources()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> referenced nonexistent resource at: " + path);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(error);
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::notify_dependency_error(local_path, path, type);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resource_cache.push_back(res);
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (tag->args.has("index")) {
|
|
|
|
ExtResource er;
|
2017-03-18 23:36:26 +00:00
|
|
|
er.path = path;
|
|
|
|
er.type = type;
|
|
|
|
ext_resources[tag->args["index"].to_int()] = er;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Error err = close_tag("ext_resource");
|
|
|
|
if (err)
|
|
|
|
return error;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
resource_current++;
|
|
|
|
return error;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (tag->name == "resource") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
main = false;
|
|
|
|
} else if (tag->name == "main_resource") {
|
|
|
|
main = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": unexpected main tag: " + tag->name);
|
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_V(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
String type;
|
|
|
|
String path;
|
2017-03-18 23:36:26 +00:00
|
|
|
int subres = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!main) {
|
|
|
|
//loading resource
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <resource> missing 'len' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("path"), ERR_FILE_CORRUPT);
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <resource> missing 'type' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("type"), ERR_FILE_CORRUPT);
|
|
|
|
path = tag->args["path"];
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (path.begins_with("local://")) {
|
|
|
|
//built-in resource (but really external)
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
path = path.replace("local://", "");
|
|
|
|
subres = path.to_int();
|
|
|
|
path = local_path + "::" + path;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ResourceCache::has(path)) {
|
|
|
|
Error err = close_tag(tag->name);
|
|
|
|
if (err) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Unable to close <resource> tag.");
|
|
|
|
ERR_FAIL_COND_V(err, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
resource_current++;
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = tag->args["type"];
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
type = resource_type;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *obj = ObjectTypeDB::instance(type);
|
|
|
|
if (!obj) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Object of unrecognized type in file: " + type);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!obj, ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Resource *r = obj->cast_to<Resource>();
|
|
|
|
if (!r) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(obj); //bye
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": Object type in resource field not a resource, type is: " + obj->get_type());
|
|
|
|
ERR_FAIL_COND_V(!r, ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res = RES(r);
|
|
|
|
if (path != "")
|
2014-02-10 01:10:30 +00:00
|
|
|
r->set_path(path);
|
2015-06-22 03:03:19 +00:00
|
|
|
r->set_subindex(subres);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//load properties
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String name;
|
|
|
|
Variant v;
|
|
|
|
Error err;
|
2017-03-18 23:36:26 +00:00
|
|
|
err = parse_property(v, name);
|
|
|
|
if (err == ERR_FILE_EOF) //tag closed
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": XML Parsing aborted.");
|
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_FILE_CORRUPT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
obj->set(name, v);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
res->set_edited(false);
|
|
|
|
#endif
|
|
|
|
resource_cache.push_back(res); //keep it in mem until finished loading
|
|
|
|
resource_current++;
|
|
|
|
if (main) {
|
|
|
|
f->close();
|
2017-03-18 23:36:26 +00:00
|
|
|
resource = res;
|
2016-01-14 14:06:20 +00:00
|
|
|
if (!ResourceCache::has(res_path)) {
|
|
|
|
resource->set_path(res_path);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_EOF;
|
2014-02-10 01:10:30 +00:00
|
|
|
return error;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResourceInteractiveLoaderXML::get_stage() const {
|
|
|
|
|
|
|
|
return resource_current;
|
|
|
|
}
|
|
|
|
int ResourceInteractiveLoaderXML::get_stage_count() const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return resources_total; //+ext_resources;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceInteractiveLoaderXML::~ResourceInteractiveLoaderXML() {
|
|
|
|
|
|
|
|
memdelete(f);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceInteractiveLoaderXML::get_dependencies(FileAccess *f, List<String> *p_dependencies, bool p_add_types) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
open(f);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND(error != OK);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2014-02-10 01:10:30 +00:00
|
|
|
bool exit;
|
|
|
|
Tag *tag = parse_tag(&exit);
|
|
|
|
|
|
|
|
if (!tag) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!exit);
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_EOF;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tag->name != "ext_resource") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> missing 'path' field.");
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!tag->args.has("path"));
|
|
|
|
|
|
|
|
String path = tag->args["path"];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> can't use a local path, this is a bug?.");
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(path.begins_with("local://"));
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (path.find("://") == -1 && path.is_rel_path()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// path is relative to file being loaded, so convert to a resource path
|
2017-03-18 23:36:26 +00:00
|
|
|
path = Globals::get_singleton()->localize_path(local_path.get_base_dir().plus_file(path));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 01:57:24 +00:00
|
|
|
if (path.ends_with("*")) {
|
|
|
|
ERR_FAIL_COND(!tag->args.has("type"));
|
|
|
|
String type = tag->args["type"];
|
2017-03-18 23:36:26 +00:00
|
|
|
path = ResourceLoader::guess_full_filename(path, type);
|
2014-03-14 01:57:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (p_add_types && tag->args.has("type")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
path += "::" + tag->args["type"];
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
p_dependencies->push_back(path);
|
|
|
|
|
|
|
|
Error err = close_tag("ext_resource");
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceInteractiveLoaderXML::get_export_data(FileAccess *p_f, ExportData &r_export_data) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
open(p_f);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(error != OK, error);
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
bool exit;
|
|
|
|
Tag *tag = parse_tag(&exit);
|
|
|
|
|
|
|
|
if (!tag) {
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2017-02-13 01:52:02 +00:00
|
|
|
if (!exit) // shouldn't have exited
|
|
|
|
ERR_FAIL_V(error);
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_EOF;
|
2017-02-13 01:52:02 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool main;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tag->name == "ext_resource") {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
ExportData::Dependency dep;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": <ext_resource> missing 'path' field.");
|
|
|
|
ERR_FAIL_COND_V(!tag->args.has("path"), ERR_FILE_CORRUPT);
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String type = "Resource";
|
2017-02-13 01:52:02 +00:00
|
|
|
if (tag->args.has("type"))
|
2017-03-18 23:36:26 +00:00
|
|
|
type = tag->args["type"];
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
String path = tag->args["path"];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
dep.path = path;
|
|
|
|
dep.type = type;
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
if (tag->args.has("index")) {
|
|
|
|
ExtResource er;
|
2017-03-18 23:36:26 +00:00
|
|
|
er.path = path;
|
|
|
|
er.type = type;
|
|
|
|
r_export_data.dependencies[tag->args["index"].to_int()] = dep;
|
2017-02-13 01:52:02 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
int index = r_export_data.dependencies.size();
|
2017-03-18 23:36:26 +00:00
|
|
|
r_export_data.dependencies[index] = dep;
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Error err = close_tag("ext_resource");
|
|
|
|
if (err)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (tag->name == "resource") {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
main = false;
|
|
|
|
} else if (tag->name == "main_resource") {
|
|
|
|
main = true;
|
2017-02-13 01:52:02 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": unexpected main tag: " + tag->name);
|
|
|
|
error = ERR_FILE_CORRUPT;
|
2017-02-13 01:52:02 +00:00
|
|
|
ERR_FAIL_V(error);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_export_data.resources.resize(r_export_data.resources.size() + 1);
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ExportData::ResourceData &res_data = r_export_data.resources[r_export_data.resources.size() - 1];
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res_data.index = -1;
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
if (!main) {
|
|
|
|
//loading resource
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = tag->args["path"];
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
if (path.begins_with("local://")) {
|
|
|
|
//built-in resource (but really external)
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
path = path.replace("local://", "");
|
|
|
|
res_data.index = path.to_int();
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res_data.type = tag->args["type"];
|
2017-02-13 01:52:02 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
res_data.type = resource_type;
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
//load properties
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
|
|
|
String name;
|
|
|
|
Variant v;
|
|
|
|
Error err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = parse_property(v, name);
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err == ERR_FILE_EOF) //tag closed
|
2017-02-13 01:52:02 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK) {
|
|
|
|
ERR_EXPLAIN(local_path + ":" + itos(get_current_line()) + ": XML Parsing aborted.");
|
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_FILE_CORRUPT);
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExportData::PropertyData prop;
|
2017-03-18 23:36:26 +00:00
|
|
|
prop.name = name;
|
|
|
|
prop.value = v;
|
2017-02-13 01:52:02 +00:00
|
|
|
res_data.properties.push_back(prop);
|
|
|
|
}
|
|
|
|
if (main) {
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const String &p_path, const Map<String, String> &p_map) {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
open(p_f);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(error != OK, error);
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
//FileAccess
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool old_format = false;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
FileAccess *fw = NULL;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String base_path = local_path.get_base_dir();
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
2015-08-23 23:15:56 +00:00
|
|
|
bool exit;
|
|
|
|
List<String> order;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Tag *tag = parse_tag(&exit, true, &order);
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool done = false;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
if (!tag) {
|
|
|
|
if (fw) {
|
|
|
|
memdelete(fw);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_FAIL_COND_V(!exit, error);
|
|
|
|
error = ERR_FILE_EOF;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tag->name == "ext_resource") {
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
if (!tag->args.has("index") || !tag->args.has("path") || !tag->args.has("type")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
old_format = true;
|
2015-08-23 23:15:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fw) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fw = FileAccess::open(p_path + ".depren", FileAccess::WRITE);
|
2015-08-23 23:15:56 +00:00
|
|
|
fw->store_line("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //no escape
|
2017-03-18 23:36:26 +00:00
|
|
|
fw->store_line("<resource_file type=\"" + resource_type + "\" subresource_count=\"" + itos(resources_total) + "\" version=\"" + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "\" version_name=\"" + VERSION_FULL_NAME + "\">");
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String path = tag->args["path"];
|
|
|
|
String index = tag->args["index"];
|
|
|
|
String type = tag->args["type"];
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool relative = false;
|
2015-08-23 23:15:56 +00:00
|
|
|
if (!path.begins_with("res://")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
path = base_path.plus_file(path).simplify_path();
|
|
|
|
relative = true;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_map.has(path)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
String np = p_map[path];
|
|
|
|
path = np;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (relative) {
|
|
|
|
//restore relative
|
2017-03-18 23:36:26 +00:00
|
|
|
path = base_path.path_to_file(path);
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tag->args["path"] = path;
|
|
|
|
tag->args["index"] = index;
|
|
|
|
tag->args["type"] = type;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
done = true;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String tagt = "\t<";
|
2015-08-23 23:15:56 +00:00
|
|
|
if (exit)
|
2017-03-18 23:36:26 +00:00
|
|
|
tagt += "/";
|
|
|
|
tagt += tag->name;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = order.front(); E; E = E->next()) {
|
|
|
|
tagt += " " + E->get() + "=\"" + tag->args[E->get()] + "\"";
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
tagt += ">";
|
2015-08-23 23:15:56 +00:00
|
|
|
fw->store_line(tagt);
|
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
close_tag("ext_resource");
|
|
|
|
fw->store_line("\t</ext_resource>");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_format) {
|
|
|
|
if (fw)
|
|
|
|
memdelete(fw);
|
|
|
|
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2017-03-18 23:36:26 +00:00
|
|
|
da->remove(p_path + ".depren");
|
2015-08-23 23:15:56 +00:00
|
|
|
memdelete(da);
|
|
|
|
//fuck it, use the old approach;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
WARN_PRINT(("This file is old, so it can't refactor dependencies, opening and resaving: " + p_path).utf8().get_data());
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
Error err;
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f2 = FileAccess::open(p_path, FileAccess::READ, &err);
|
|
|
|
if (err != OK) {
|
|
|
|
ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN);
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
|
|
|
ria->remaps = p_map;
|
|
|
|
// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
2015-08-23 23:15:56 +00:00
|
|
|
ria->open(f2);
|
|
|
|
|
|
|
|
err = ria->poll();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (err == OK) {
|
|
|
|
err = ria->poll();
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err != ERR_FILE_EOF, ERR_FILE_CORRUPT);
|
2015-08-23 23:15:56 +00:00
|
|
|
RES res = ria->get_resource();
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!res.is_valid(), ERR_FILE_CORRUPT);
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return ResourceFormatSaverXML::singleton->save(p_path, res);
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!fw) {
|
|
|
|
|
|
|
|
return OK; //nothing to rename, do nothing
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
uint8_t c = f->get_8();
|
|
|
|
while (!f->eof_reached()) {
|
2015-08-23 23:15:56 +00:00
|
|
|
fw->store_8(c);
|
2017-03-18 23:36:26 +00:00
|
|
|
c = f->get_8();
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2016-02-21 21:51:19 +00:00
|
|
|
f->close();
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool all_ok = fw->get_error() == OK;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
|
|
|
memdelete(fw);
|
|
|
|
|
|
|
|
if (!all_ok) {
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
da->remove(p_path);
|
2017-03-18 23:36:26 +00:00
|
|
|
da->rename(p_path + ".depren", p_path);
|
2015-08-23 23:15:56 +00:00
|
|
|
memdelete(da);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ResourceInteractiveLoaderXML::open(FileAccess *p_f) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
lines = 1;
|
|
|
|
f = p_f;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!tag || tag->name != "?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"] != "UTF-8") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
2014-02-10 01:10:30 +00:00
|
|
|
ResourceLoader::notify_load_error("XML is invalid (missing header tags)");
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_EXPLAIN("Not a XML:UTF-8 File: " + local_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
tag_stack.clear();
|
|
|
|
|
|
|
|
tag = parse_tag();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!tag || tag->name != "resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::notify_load_error(local_path + ": XML is not a valid resource file.");
|
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ERR_EXPLAIN("Unrecognized XML File: " + local_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag->args.has("subresource_count"))
|
2017-03-18 23:36:26 +00:00
|
|
|
resources_total = tag->args["subresource_count"].to_int();
|
|
|
|
resource_current = 0;
|
|
|
|
resource_type = tag->args["type"];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String version = tag->args["version"];
|
2017-03-18 23:36:26 +00:00
|
|
|
if (version.get_slice_count(".") != 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_CORRUPT;
|
|
|
|
ResourceLoader::notify_load_error(local_path + ":XML version string is invalid: " + version);
|
|
|
|
ERR_EXPLAIN("Invalid Version String '" + version + "'' in file: " + local_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int major = version.get_slicec('.', 0).to_int();
|
|
|
|
if (major > VERSION_MAJOR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = ERR_FILE_UNRECOGNIZED;
|
|
|
|
ResourceLoader::notify_load_error(local_path + ": File Format '" + version + "' is too new. Please upgrade to a newer engine version.");
|
|
|
|
ERR_EXPLAIN("File Format '" + version + "' is too new! Please upgrade to a a new engine version: " + local_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
/*
|
2014-03-14 01:57:24 +00:00
|
|
|
String preload_depts = "deps/"+local_path.md5_text();
|
|
|
|
if (Globals::get_singleton()->has(preload_depts)) {
|
|
|
|
ext_resources.clear();
|
|
|
|
//ignore external resources and use these
|
|
|
|
NodePath depts=Globals::get_singleton()->get(preload_depts);
|
|
|
|
|
|
|
|
for(int i=0;i<depts.get_name_count();i++) {
|
|
|
|
ext_resources.push_back(depts.get_name(i));
|
|
|
|
}
|
|
|
|
print_line(local_path+" - EXTERNAL RESOURCES: "+itos(ext_resources.size()));
|
|
|
|
}
|
2015-08-23 23:15:56 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String ResourceInteractiveLoaderXML::recognize(FileAccess *p_f) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
error = OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
lines = 1;
|
|
|
|
f = p_f;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ResourceInteractiveLoaderXML::Tag *tag = parse_tag();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!tag || tag->name != "?xml" || !tag->args.has("version") || !tag->args.has("encoding") || tag->args["encoding"] != "UTF-8") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return ""; //unrecognized
|
|
|
|
}
|
|
|
|
|
|
|
|
tag_stack.clear();
|
|
|
|
|
|
|
|
tag = parse_tag();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!tag || tag->name != "resource_file" || !tag->args.has("type") || !tag->args.has("version")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return ""; //unrecognized
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag->args["type"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
Ref<ResourceInteractiveLoader> ResourceFormatLoaderXML::load_interactive(const String &p_path, Error *r_error) {
|
|
|
|
|
|
|
|
if (r_error)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_error = ERR_CANT_OPEN;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Error err;
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err != OK, Ref<ResourceInteractiveLoader>());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
|
|
|
// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
2014-02-10 01:10:30 +00:00
|
|
|
ria->open(f);
|
|
|
|
|
|
|
|
return ria;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatLoaderXML::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_type == "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
get_recognized_extensions(p_extensions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> extensions;
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::get_extensions_for_type(p_type, &extensions);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
extensions.sort();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
String ext = E->get().to_lower();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ext == "res")
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
p_extensions->push_back("x" + ext);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_extensions->push_back("xml");
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatLoaderXML::get_recognized_extensions(List<String> *p_extensions) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<String> extensions;
|
|
|
|
ObjectTypeDB::get_resource_base_extensions(&extensions);
|
|
|
|
extensions.sort();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
String ext = E->get().to_lower();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ext == "res")
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
p_extensions->push_back("x" + ext);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_extensions->push_back("xml");
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool ResourceFormatLoaderXML::handles_type(const String &p_type) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
String ResourceFormatLoaderXML::get_resource_type(const String &p_path) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String ext = p_path.extension().to_lower();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!ext.begins_with("x")) //a lie but..
|
|
|
|
return "";
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!f) {
|
|
|
|
|
|
|
|
return ""; //could not rwead
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
|
|
|
// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
2014-02-10 01:10:30 +00:00
|
|
|
String r = ria->recognize(f);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatLoaderXML::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!f) {
|
|
|
|
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
|
|
|
// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
|
|
|
ria->get_dependencies(f, p_dependencies, p_add_types);
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceFormatLoaderXML::get_export_data(const String &p_path, ExportData &r_export_data) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
2017-02-13 01:52:02 +00:00
|
|
|
if (!f) {
|
|
|
|
|
|
|
|
ERR_FAIL_V(ERR_CANT_OPEN);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return ria->get_export_data(f, r_export_data);
|
2017-02-13 01:52:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceFormatLoaderXML::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
|
2017-02-13 01:52:02 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
2015-08-23 23:15:56 +00:00
|
|
|
if (!f) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
ERR_FAIL_V(ERR_CANT_OPEN);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<ResourceInteractiveLoaderXML> ria = memnew(ResourceInteractiveLoaderXML);
|
|
|
|
ria->local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
ria->res_path = ria->local_path;
|
|
|
|
// ria->set_local_path( Globals::get_singleton()->localize_path(p_path) );
|
|
|
|
return ria->rename_dependencies(f, p_path, p_map);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceFormatLoaderXML *ResourceFormatLoaderXML::singleton = NULL;
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
/****************************************************************************************/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::escape(String &p_str) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_str = p_str.replace("&", "&");
|
|
|
|
p_str = p_str.replace("<", "<");
|
|
|
|
p_str = p_str.replace(">", ">");
|
|
|
|
p_str = p_str.replace("'", "'");
|
|
|
|
p_str = p_str.replace("\"", """);
|
|
|
|
for (char i = 1; i < 32; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
char chr[2] = { i, 0 };
|
|
|
|
const char hexn[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
|
|
|
const char hex[8] = { '&', '#', '0', '0', hexn[i >> 4], hexn[i & 0xf], ';', 0 };
|
2014-12-07 14:33:57 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_str = p_str.replace(chr, hex);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void ResourceFormatSaverXMLInstance::write_tabs(int p_diff) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < depth + p_diff; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
f->store_8('\t');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::write_string(String p_str, bool p_escape) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/* write an UTF8 string */
|
|
|
|
if (p_escape)
|
|
|
|
escape(p_str);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
f->store_string(p_str);
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
/*
|
|
|
|
CharString cs=p_str.utf8();
|
|
|
|
const char *data=cs.get_data();
|
|
|
|
|
|
|
|
while (*data) {
|
|
|
|
f->store_8(*data);
|
|
|
|
data++;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::enter_tag(const char *p_tag, const String &p_args) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
f->store_8('<');
|
|
|
|
int cc = 0;
|
2017-03-18 23:36:26 +00:00
|
|
|
const char *c = p_tag;
|
|
|
|
while (*c) {
|
2014-02-10 01:10:30 +00:00
|
|
|
cc++;
|
|
|
|
c++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
f->store_buffer((const uint8_t *)p_tag, cc);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (p_args.length()) {
|
|
|
|
f->store_8(' ');
|
|
|
|
f->store_string(p_args);
|
|
|
|
}
|
|
|
|
f->store_8('>');
|
|
|
|
depth++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::exit_tag(const char *p_tag) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
depth--;
|
|
|
|
f->store_8('<');
|
|
|
|
f->store_8('/');
|
|
|
|
int cc = 0;
|
2017-03-18 23:36:26 +00:00
|
|
|
const char *c = p_tag;
|
|
|
|
while (*c) {
|
2014-02-10 01:10:30 +00:00
|
|
|
cc++;
|
|
|
|
c++;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
f->store_buffer((const uint8_t *)p_tag, cc);
|
2014-02-10 01:10:30 +00:00
|
|
|
f->store_8('>');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
static bool _check_type(const Variant& p_property) {
|
|
|
|
|
|
|
|
if (p_property.get_type()==Variant::_RID)
|
|
|
|
return false;
|
|
|
|
if (p_property.get_type()==Variant::OBJECT) {
|
|
|
|
RES res = p_property;
|
|
|
|
if (res.is_null())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}*/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::write_property(const String &p_name, const Variant &p_property, bool *r_ok) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_ok)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_ok = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const char *type;
|
2014-02-10 01:10:30 +00:00
|
|
|
String params;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool oneliner = true;
|
|
|
|
|
|
|
|
switch (p_property.get_type()) {
|
|
|
|
|
|
|
|
case Variant::NIL: type = "nil"; break;
|
|
|
|
case Variant::BOOL: type = "bool"; break;
|
|
|
|
case Variant::INT: type = "int"; break;
|
|
|
|
case Variant::REAL: type = "real"; break;
|
|
|
|
case Variant::STRING: type = "string"; break;
|
|
|
|
case Variant::VECTOR2: type = "vector2"; break;
|
|
|
|
case Variant::RECT2: type = "rect2"; break;
|
|
|
|
case Variant::VECTOR3: type = "vector3"; break;
|
|
|
|
case Variant::PLANE: type = "plane"; break;
|
|
|
|
case Variant::_AABB: type = "aabb"; break;
|
|
|
|
case Variant::QUAT: type = "quaternion"; break;
|
|
|
|
case Variant::MATRIX32: type = "matrix32"; break;
|
|
|
|
case Variant::MATRIX3: type = "matrix3"; break;
|
|
|
|
case Variant::TRANSFORM: type = "transform"; break;
|
|
|
|
case Variant::COLOR: type = "color"; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::IMAGE: {
|
2017-03-18 23:36:26 +00:00
|
|
|
type = "image";
|
|
|
|
Image img = p_property;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (img.empty()) {
|
|
|
|
write_tabs();
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, "name=\"" + p_name + "\"");
|
2014-02-10 01:10:30 +00:00
|
|
|
exit_tag(type);
|
|
|
|
if (r_ok)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_ok = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
params += "encoding=\"raw\"";
|
|
|
|
params += " width=\"" + itos(img.get_width()) + "\"";
|
|
|
|
params += " height=\"" + itos(img.get_height()) + "\"";
|
|
|
|
params += " mipmaps=\"" + itos(img.get_mipmaps()) + "\"";
|
|
|
|
|
|
|
|
switch (img.get_format()) {
|
|
|
|
|
|
|
|
case Image::FORMAT_GRAYSCALE: params += " format=\"grayscale\""; break;
|
|
|
|
case Image::FORMAT_INTENSITY: params += " format=\"intensity\""; break;
|
|
|
|
case Image::FORMAT_GRAYSCALE_ALPHA: params += " format=\"grayscale_alpha\""; break;
|
|
|
|
case Image::FORMAT_RGB: params += " format=\"rgb\""; break;
|
|
|
|
case Image::FORMAT_RGBA: params += " format=\"rgba\""; break;
|
|
|
|
case Image::FORMAT_INDEXED: params += " format=\"indexed\""; break;
|
|
|
|
case Image::FORMAT_INDEXED_ALPHA: params += " format=\"indexed_alpha\""; break;
|
|
|
|
case Image::FORMAT_BC1: params += " format=\"bc1\""; break;
|
|
|
|
case Image::FORMAT_BC2: params += " format=\"bc2\""; break;
|
|
|
|
case Image::FORMAT_BC3: params += " format=\"bc3\""; break;
|
|
|
|
case Image::FORMAT_BC4: params += " format=\"bc4\""; break;
|
|
|
|
case Image::FORMAT_BC5: params += " format=\"bc5\""; break;
|
|
|
|
case Image::FORMAT_PVRTC2: params += " format=\"pvrtc2\""; break;
|
|
|
|
case Image::FORMAT_PVRTC2_ALPHA: params += " format=\"pvrtc2a\""; break;
|
|
|
|
case Image::FORMAT_PVRTC4: params += " format=\"pvrtc4\""; break;
|
|
|
|
case Image::FORMAT_PVRTC4_ALPHA: params += " format=\"pvrtc4a\""; break;
|
|
|
|
case Image::FORMAT_ETC: params += " format=\"etc\""; break;
|
|
|
|
case Image::FORMAT_ATC: params += " format=\"atc\""; break;
|
|
|
|
case Image::FORMAT_ATC_ALPHA_EXPLICIT: params += " format=\"atcae\""; break;
|
|
|
|
case Image::FORMAT_ATC_ALPHA_INTERPOLATED: params += " format=\"atcai\""; break;
|
|
|
|
case Image::FORMAT_CUSTOM: params += " format=\"custom\" custom_size=\"" + itos(img.get_data().size()) + "\""; break;
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case Variant::NODE_PATH: type = "node_path"; break;
|
|
|
|
case Variant::OBJECT: {
|
|
|
|
type = "resource";
|
2014-02-10 01:10:30 +00:00
|
|
|
RES res = p_property;
|
|
|
|
if (res.is_null()) {
|
|
|
|
write_tabs();
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, "name=\"" + p_name + "\"");
|
2014-02-10 01:10:30 +00:00
|
|
|
exit_tag(type);
|
|
|
|
if (r_ok)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_ok = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return; // don't save it
|
|
|
|
}
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (external_resources.has(res)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
params = "external=\"" + itos(external_resources[res]) + "\"";
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
params = "resource_type=\"" + res->get_save_type() + "\"";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (res->get_path().length() && res->get_path().find("::") == -1) {
|
2015-08-23 23:15:56 +00:00
|
|
|
//external resource
|
2017-03-18 23:36:26 +00:00
|
|
|
String path = relative_paths ? local_path.path_to_file(res->get_path()) : res->get_path();
|
2015-08-23 23:15:56 +00:00
|
|
|
escape(path);
|
2017-03-18 23:36:26 +00:00
|
|
|
params += " path=\"" + path + "\"";
|
2015-08-23 23:15:56 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
//internal resource
|
|
|
|
ERR_EXPLAIN("Resource was not pre cached for the resource section, bug?");
|
|
|
|
ERR_FAIL_COND(!resource_set.has(res));
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
params += " path=\"local://" + itos(res->get_subindex()) + "\"";
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case Variant::INPUT_EVENT: type = "input_event"; break;
|
|
|
|
case Variant::DICTIONARY:
|
|
|
|
type = "dictionary";
|
|
|
|
params = "shared=\"" + String(p_property.is_shared() ? "true" : "false") + "\"";
|
|
|
|
oneliner = false;
|
|
|
|
break;
|
|
|
|
case Variant::ARRAY:
|
|
|
|
type = "array";
|
|
|
|
params = "len=\"" + itos(p_property.operator Array().size()) + "\" shared=\"" + String(p_property.is_shared() ? "true" : "false") + "\"";
|
|
|
|
oneliner = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Variant::RAW_ARRAY:
|
|
|
|
type = "raw_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<uint8_t>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::INT_ARRAY:
|
|
|
|
type = "int_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<int>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::REAL_ARRAY:
|
|
|
|
type = "real_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<real_t>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::STRING_ARRAY:
|
|
|
|
oneliner = false;
|
|
|
|
type = "string_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<String>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::VECTOR2_ARRAY:
|
|
|
|
type = "vector2_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<Vector2>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::VECTOR3_ARRAY:
|
|
|
|
type = "vector3_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<Vector3>().size()) + "\"";
|
|
|
|
break;
|
|
|
|
case Variant::COLOR_ARRAY:
|
|
|
|
type = "color_array";
|
|
|
|
params = "len=\"" + itos(p_property.operator DVector<Color>().size()) + "\"";
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {
|
|
|
|
|
|
|
|
ERR_PRINT("Unknown Variant type.");
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write_tabs();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_name != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (params.length())
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, "name=\"" + p_name + "\" " + params);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, "name=\"" + p_name + "\"");
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
if (params.length())
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, " " + params);
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag(type, String());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!oneliner)
|
|
|
|
f->store_8('\n');
|
|
|
|
else
|
|
|
|
f->store_8(' ');
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_property.get_type()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case Variant::NIL: {
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::BOOL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(p_property.operator bool() ? "True" : "False");
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::INT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(itos(p_property.operator int()));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::REAL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtos(p_property.operator real_t()));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = p_property;
|
2014-02-10 01:10:30 +00:00
|
|
|
escape(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
str = "\"" + str + "\"";
|
|
|
|
write_string(str, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2: {
|
|
|
|
|
|
|
|
Vector2 v = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(v.x) + ", " + rtoss(v.y));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::RECT2: {
|
|
|
|
|
|
|
|
Rect2 aabb = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(aabb.pos.x) + ", " + rtoss(aabb.pos.y) + ", " + rtoss(aabb.size.x) + ", " + rtoss(aabb.size.y));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3: {
|
|
|
|
|
|
|
|
Vector3 v = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(v.x) + ", " + rtoss(v.y) + ", " + rtoss(v.z));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::PLANE: {
|
|
|
|
|
|
|
|
Plane p = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(p.normal.x) + ", " + rtoss(p.normal.y) + ", " + rtoss(p.normal.z) + ", " + rtoss(p.d));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::_AABB: {
|
|
|
|
|
|
|
|
AABB aabb = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(aabb.pos.x) + ", " + rtoss(aabb.pos.y) + ", " + rtoss(aabb.pos.z) + ", " + rtoss(aabb.size.x) + ", " + rtoss(aabb.size.y) + ", " + rtoss(aabb.size.z));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::QUAT: {
|
|
|
|
|
|
|
|
Quat quat = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(quat.x) + ", " + rtoss(quat.y) + ", " + rtoss(quat.z) + ", " + rtoss(quat.w) + ", ");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::MATRIX32: {
|
|
|
|
|
|
|
|
String s;
|
|
|
|
Matrix32 m3 = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 2; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i != 0 || j != 0)
|
|
|
|
s += ", ";
|
|
|
|
s += rtoss(m3.elements[i][j]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write_string(s);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::MATRIX3: {
|
|
|
|
|
|
|
|
String s;
|
|
|
|
Matrix3 m3 = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i != 0 || j != 0)
|
|
|
|
s += ", ";
|
|
|
|
s += rtoss(m3.elements[i][j]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write_string(s);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::TRANSFORM: {
|
|
|
|
|
|
|
|
String s;
|
|
|
|
Transform t = p_property;
|
|
|
|
Matrix3 &m3 = t.basis;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i != 0 || j != 0)
|
|
|
|
s += ", ";
|
|
|
|
s += rtoss(m3.elements[i][j]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
s = s + ", " + rtoss(t.origin.x) + ", " + rtoss(t.origin.y) + ", " + rtoss(t.origin.z);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
write_string(s);
|
|
|
|
} break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
// misc types
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::COLOR: {
|
|
|
|
|
|
|
|
Color c = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(c.r) + ", " + rtoss(c.g) + ", " + rtoss(c.b) + ", " + rtoss(c.a));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::IMAGE: {
|
|
|
|
|
|
|
|
String s;
|
|
|
|
Image img = p_property;
|
|
|
|
DVector<uint8_t> data = img.get_data();
|
|
|
|
int len = data.size();
|
|
|
|
DVector<uint8_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const uint8_t *ptr = r.ptr();
|
|
|
|
;
|
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint8_t byte = ptr[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
|
|
|
char str[3] = { hex[byte >> 4], hex[byte & 0xF], 0 };
|
|
|
|
s += str;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
write_string(s);
|
|
|
|
} break;
|
|
|
|
case Variant::NODE_PATH: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = p_property;
|
2014-02-10 01:10:30 +00:00
|
|
|
escape(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
str = "\"" + str + "\"";
|
|
|
|
write_string(str, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::OBJECT: {
|
|
|
|
/* this saver does not save resources in here
|
|
|
|
RES res = p_property;
|
|
|
|
|
|
|
|
if (!res.is_null()) {
|
|
|
|
|
|
|
|
String path=res->get_path();
|
|
|
|
if (!res->is_shared() || !path.length()) {
|
|
|
|
// if no path, or path is from inside a scene
|
|
|
|
write_object( *res );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INPUT_EVENT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(p_property.operator String());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
|
|
|
Dictionary dict = p_property;
|
|
|
|
|
|
|
|
List<Variant> keys;
|
|
|
|
dict.get_key_list(&keys);
|
2015-05-01 00:53:41 +00:00
|
|
|
keys.sort();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//if (!_check_type(dict[E->get()]))
|
|
|
|
// continue;
|
|
|
|
bool ok;
|
2017-03-18 23:36:26 +00:00
|
|
|
write_property("", E->get(), &ok);
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_CONTINUE(!ok);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_property("", dict[E->get()], &ok);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!ok)
|
2017-03-18 23:36:26 +00:00
|
|
|
write_property("", Variant()); //at least make the file consistent..
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
|
|
|
Array array = p_property;
|
2017-03-18 23:36:26 +00:00
|
|
|
int len = array.size();
|
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_property("", array[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Variant::RAW_ARRAY: {
|
|
|
|
|
|
|
|
String s;
|
|
|
|
DVector<uint8_t> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<uint8_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const uint8_t *ptr = r.ptr();
|
|
|
|
;
|
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
uint8_t byte = ptr[i];
|
2017-03-18 23:36:26 +00:00
|
|
|
const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
|
|
|
char str[3] = { hex[byte >> 4], hex[byte & 0xF], 0 };
|
|
|
|
s += str;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(s, false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::INT_ARRAY: {
|
|
|
|
|
|
|
|
DVector<int> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<int>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const int *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
write_string(", ", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(itos(ptr[i]), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::REAL_ARRAY: {
|
|
|
|
|
|
|
|
DVector<real_t> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<real_t>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const real_t *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs();
|
2017-03-18 23:36:26 +00:00
|
|
|
String cm = ", ";
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
write_string(cm, false);
|
|
|
|
write_string(rtoss(ptr[i]), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::STRING_ARRAY: {
|
|
|
|
|
|
|
|
DVector<String> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<String>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
String s;
|
|
|
|
//write_string("\n");
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
write_tabs(0);
|
2017-03-18 23:36:26 +00:00
|
|
|
String str = ptr[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
escape(str);
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("<string> \"" + str + "\" </string>\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR2_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Vector2> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<Vector2>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const Vector2 *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
write_string(", ", false);
|
|
|
|
write_string(rtoss(ptr[i].x), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].y), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::VECTOR3_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Vector3> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<Vector3>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const Vector3 *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
write_string(", ", false);
|
|
|
|
write_string(rtoss(ptr[i].x), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].y), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].z), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::COLOR_ARRAY: {
|
|
|
|
|
|
|
|
DVector<Color> data = p_property;
|
|
|
|
int len = data.size();
|
|
|
|
DVector<Color>::Read r = data.read();
|
2017-03-18 23:36:26 +00:00
|
|
|
const Color *ptr = r.ptr();
|
|
|
|
;
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i > 0)
|
|
|
|
write_string(", ", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string(rtoss(ptr[i].r), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].g), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].b), false);
|
|
|
|
write_string(", " + rtoss(ptr[i].a), false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
if (oneliner)
|
|
|
|
f->store_8(' ');
|
|
|
|
else
|
|
|
|
write_tabs(-1);
|
|
|
|
exit_tag(type);
|
|
|
|
|
|
|
|
f->store_8('\n');
|
|
|
|
|
|
|
|
if (r_ok)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_ok = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXMLInstance::_find_resources(const Variant &p_variant, bool p_main) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_variant.get_type()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case Variant::OBJECT: {
|
|
|
|
|
|
|
|
RES res = p_variant.operator RefPtr();
|
|
|
|
|
2015-08-23 23:15:56 +00:00
|
|
|
if (res.is_null() || external_resources.has(res))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
|
2015-08-23 23:15:56 +00:00
|
|
|
int index = external_resources.size();
|
2017-03-18 23:36:26 +00:00
|
|
|
external_resources[res] = index;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
if (resource_set.has(res))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
List<PropertyInfo> property_list;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res->get_property_list(&property_list);
|
2015-05-01 00:53:41 +00:00
|
|
|
property_list.sort();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<PropertyInfo>::Element *I = property_list.front();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (I) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
PropertyInfo pi = I->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (pi.usage & PROPERTY_USAGE_STORAGE || (bundle_resources && pi.usage & PROPERTY_USAGE_BUNDLE)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant v = res->get(I->get().name);
|
2014-02-10 01:10:30 +00:00
|
|
|
_find_resources(v);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
I = I->next();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
resource_set.insert(res); //saved after, so the childs it needs are available when loaded
|
2014-02-10 01:10:30 +00:00
|
|
|
saved_resources.push_back(res);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Array varray = p_variant;
|
|
|
|
int len = varray.size();
|
|
|
|
for (int i = 0; i < len; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant v = varray.get(i);
|
2014-02-10 01:10:30 +00:00
|
|
|
_find_resources(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case Variant::DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Dictionary d = p_variant;
|
2014-02-10 01:10:30 +00:00
|
|
|
List<Variant> keys;
|
|
|
|
d.get_key_list(&keys);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Variant v = d[E->get()];
|
|
|
|
_find_resources(v);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceFormatSaverXMLInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Error err;
|
2017-03-18 23:36:26 +00:00
|
|
|
f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
|
|
|
ERR_FAIL_COND_V(err, ERR_CANT_OPEN);
|
2014-02-10 01:10:30 +00:00
|
|
|
FileAccessRef _fref(f);
|
|
|
|
|
|
|
|
local_path = Globals::get_singleton()->localize_path(p_path);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
relative_paths = p_flags & ResourceSaver::FLAG_RELATIVE_PATHS;
|
|
|
|
skip_editor = p_flags & ResourceSaver::FLAG_OMIT_EDITOR_PROPERTIES;
|
|
|
|
bundle_resources = p_flags & ResourceSaver::FLAG_BUNDLE_RESOURCES;
|
|
|
|
takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
|
2014-06-28 02:21:45 +00:00
|
|
|
if (!p_path.begins_with("res://")) {
|
2017-03-18 23:36:26 +00:00
|
|
|
takeover_paths = false;
|
2014-06-28 02:21:45 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
depth = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
// save resources
|
2017-03-18 23:36:26 +00:00
|
|
|
_find_resources(p_resource, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(err != OK, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", false); //no escape
|
|
|
|
write_string("\n", false);
|
|
|
|
enter_tag("resource_file", "type=\"" + p_resource->get_type() + "\" subresource_count=\"" + itos(saved_resources.size() + external_resources.size()) + "\" version=\"" + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "\" version_name=\"" + VERSION_FULL_NAME + "\"");
|
|
|
|
write_string("\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
write_tabs();
|
2015-08-23 23:15:56 +00:00
|
|
|
String p = E->key()->get_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag("ext_resource", "path=\"" + p + "\" type=\"" + E->key()->get_save_type() + "\" index=\"" + itos(E->get()) + "\""); //bundled
|
2014-02-10 01:10:30 +00:00
|
|
|
exit_tag("ext_resource"); //bundled
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 03:03:19 +00:00
|
|
|
Set<int> used_indices;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
2015-06-22 03:03:19 +00:00
|
|
|
|
|
|
|
RES res = E->get();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->next() && (res->get_path() == "" || res->get_path().find("::") != -1)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (res->get_subindex() != 0) {
|
2015-06-22 03:03:19 +00:00
|
|
|
if (used_indices.has(res->get_subindex())) {
|
|
|
|
res->set_subindex(0); //repeated
|
|
|
|
} else {
|
|
|
|
used_indices.insert(res->get_subindex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
RES res = E->get();
|
2015-06-22 03:03:19 +00:00
|
|
|
ERR_CONTINUE(!resource_set.has(res));
|
2017-03-18 23:36:26 +00:00
|
|
|
bool main = (E->next() == NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
write_tabs();
|
|
|
|
|
|
|
|
if (main)
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag("main_resource", ""); //bundled
|
|
|
|
else if (res->get_path().length() && res->get_path().find("::") == -1)
|
|
|
|
enter_tag("resource", "type=\"" + res->get_type() + "\" path=\"" + res->get_path() + "\""); //bundled
|
2014-06-28 02:21:45 +00:00
|
|
|
else {
|
2015-06-22 03:03:19 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (res->get_subindex() == 0) {
|
|
|
|
int new_subindex = 1;
|
2015-06-22 03:03:19 +00:00
|
|
|
if (used_indices.size()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
new_subindex = used_indices.back()->get() + 1;
|
2015-06-22 03:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res->set_subindex(new_subindex);
|
|
|
|
used_indices.insert(new_subindex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int idx = res->get_subindex();
|
2017-03-18 23:36:26 +00:00
|
|
|
enter_tag("resource", "type=\"" + res->get_type() + "\" path=\"local://" + itos(idx) + "\"");
|
2014-06-28 02:21:45 +00:00
|
|
|
if (takeover_paths) {
|
2017-03-18 23:36:26 +00:00
|
|
|
res->set_path(p_path + "::" + itos(idx), true);
|
2014-06-28 02:21:45 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> property_list;
|
|
|
|
res->get_property_list(&property_list);
|
2017-03-18 23:36:26 +00:00
|
|
|
// property_list.sort();
|
|
|
|
for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (skip_editor && PE->get().name.begins_with("__editor"))
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (PE->get().usage & PROPERTY_USAGE_STORAGE || (bundle_resources && PE->get().usage & PROPERTY_USAGE_BUNDLE)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String name = PE->get().name;
|
|
|
|
Variant value = res->get(name);
|
2015-06-29 03:29:49 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((PE->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) || (PE->get().usage & PROPERTY_USAGE_STORE_IF_NONONE && value.is_one()))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_property(name, value);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
write_tabs(-1);
|
|
|
|
if (main)
|
|
|
|
exit_tag("main_resource");
|
|
|
|
else
|
|
|
|
exit_tag("resource");
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
write_string("\n", false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit_tag("resource_file");
|
2017-03-18 23:36:26 +00:00
|
|
|
if (f->get_error() != OK && f->get_error() != ERR_FILE_EOF) {
|
2015-03-02 03:54:10 +00:00
|
|
|
f->close();
|
|
|
|
return ERR_CANT_CREATE;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
f->close();
|
|
|
|
//memdelete(f);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error ResourceFormatSaverXML::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ResourceFormatSaverXMLInstance saver;
|
2017-03-18 23:36:26 +00:00
|
|
|
return saver.save(p_path, p_resource, p_flags);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool ResourceFormatSaverXML::recognize(const RES &p_resource) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return true; // all recognized!
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
void ResourceFormatSaverXML::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//here comes the sun, lalalala
|
|
|
|
String base = p_resource->get_base_extension().to_lower();
|
|
|
|
p_extensions->push_back("xml");
|
2017-03-18 23:36:26 +00:00
|
|
|
if (base != "res") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_extensions->push_back("x" + base);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-23 23:15:56 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceFormatSaverXML *ResourceFormatSaverXML::singleton = NULL;
|
2015-08-23 23:15:56 +00:00
|
|
|
ResourceFormatSaverXML::ResourceFormatSaverXML() {
|
2017-03-18 23:36:26 +00:00
|
|
|
singleton = this;
|
2015-08-23 23:15:56 +00:00
|
|
|
}
|