worked on lines saving
This commit is contained in:
@@ -18,4 +18,10 @@ template <class T> static inline T from_string(const String &s)
|
||||
ret = o;
|
||||
return ret;
|
||||
}
|
||||
template <class T> static inline String to_string(const T &v)
|
||||
{
|
||||
String tmp;
|
||||
VariantWriter::write_to_string(v, tmp);
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
@@ -22,6 +22,7 @@ struct road_line {
|
||||
int lanes;
|
||||
int pattern;
|
||||
int flags;
|
||||
Dictionary metadata;
|
||||
};
|
||||
static HashMap<String, struct road_line> lines;
|
||||
static ImmediateGeometry *line_im = nullptr;
|
||||
@@ -281,13 +282,14 @@ protected:
|
||||
/* TODO: delete line */
|
||||
break;
|
||||
case 51:
|
||||
/* TODO: point to cursor */
|
||||
editor->set_point_to_cursor();
|
||||
break;
|
||||
case 52:
|
||||
/* TODO: cursor to point */
|
||||
editor->move_cursor_to_point();
|
||||
break;
|
||||
case 101:
|
||||
editor->save_data();
|
||||
break;
|
||||
default:
|
||||
print_line("menu option pressed: " + itos(id));
|
||||
}
|
||||
@@ -772,9 +774,8 @@ void RoadLinesEditor::load_data()
|
||||
struct road_line rline;
|
||||
Dictionary entry = json.get(key, Dictionary());
|
||||
Array points = entry.get("points", Array());
|
||||
Array indices;
|
||||
if (entry.has("indices"))
|
||||
indices = entry.get("indices", Array());
|
||||
Array indices = entry.get("indices", Array());
|
||||
rline.metadata = entry.get("metadata", Dictionary());
|
||||
int lanes = entry.get("lanes", -1);
|
||||
int pattern = entry.get("pattern", -1);
|
||||
rline.pattern = pattern;
|
||||
@@ -794,6 +795,46 @@ void RoadLinesEditor::load_data()
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void RoadLinesEditor::save_data()
|
||||
{
|
||||
// TODO: implement
|
||||
int i;
|
||||
ConfigFile config;
|
||||
Error result = config.load("res://config/stream.conf");
|
||||
ERR_FAIL_COND_MSG(result != OK, "Failed to load config");
|
||||
String road_lines_path = config.get_value("road", "road_lines_path");
|
||||
String road_lines_json =
|
||||
FileAccess::get_file_as_string(road_lines_path);
|
||||
Dictionary output;
|
||||
List<String> keys;
|
||||
lines.get_key_list(&keys);
|
||||
List<String>::Element *e = keys.front();
|
||||
while (e) {
|
||||
Dictionary pvalues;
|
||||
Array points, indices;
|
||||
points.resize(lines[e->get()].points.size());
|
||||
for (i = 0; i < (int)lines[e->get()].points.size(); i++)
|
||||
points[i] = to_string(lines[e->get()].points[i]);
|
||||
indices.resize(lines[e->get()].indices.size());
|
||||
for (i = 0; i < (int)lines[e->get()].indices.size(); i++)
|
||||
indices[i] = lines[e->get()].indices[i];
|
||||
pvalues["points"] = points;
|
||||
pvalues["indices"] = indices;
|
||||
pvalues["metadata"] = lines[e->get()].metadata;
|
||||
pvalues["lanes"] = lines[e->get()].lanes;
|
||||
pvalues["pattern"] = lines[e->get()].pattern;
|
||||
output[e->get()] = pvalues;
|
||||
e = e->next();
|
||||
}
|
||||
print_line(JSON::print(output, "\t", false));
|
||||
Error err;
|
||||
FileAccess *fd = FileAccess::open(road_lines_path + ".n",
|
||||
FileAccess::WRITE, &err);
|
||||
if (err == OK) {
|
||||
fd->store_string(JSON::print(output, "\t", false));
|
||||
fd->close();
|
||||
}
|
||||
}
|
||||
template <class T> T *RoadLinesEditor::get_as_node(const String &path)
|
||||
{
|
||||
Node *node = scene()->get_node(NodePath(path));
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
void set_line_index(int index);
|
||||
void line_list_filter_changed(const String &text);
|
||||
template <class T> T *get_as_node(const String &path);
|
||||
void save_data();
|
||||
|
||||
protected:
|
||||
void activate();
|
||||
|
||||
Reference in New Issue
Block a user