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;
|
ret = o;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
template <class T> static inline String to_string(const T &v)
|
||||||
|
{
|
||||||
|
String tmp;
|
||||||
|
VariantWriter::write_to_string(v, tmp);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -22,6 +22,7 @@ struct road_line {
|
|||||||
int lanes;
|
int lanes;
|
||||||
int pattern;
|
int pattern;
|
||||||
int flags;
|
int flags;
|
||||||
|
Dictionary metadata;
|
||||||
};
|
};
|
||||||
static HashMap<String, struct road_line> lines;
|
static HashMap<String, struct road_line> lines;
|
||||||
static ImmediateGeometry *line_im = nullptr;
|
static ImmediateGeometry *line_im = nullptr;
|
||||||
@@ -281,13 +282,14 @@ protected:
|
|||||||
/* TODO: delete line */
|
/* TODO: delete line */
|
||||||
break;
|
break;
|
||||||
case 51:
|
case 51:
|
||||||
/* TODO: point to cursor */
|
|
||||||
editor->set_point_to_cursor();
|
editor->set_point_to_cursor();
|
||||||
break;
|
break;
|
||||||
case 52:
|
case 52:
|
||||||
/* TODO: cursor to point */
|
|
||||||
editor->move_cursor_to_point();
|
editor->move_cursor_to_point();
|
||||||
break;
|
break;
|
||||||
|
case 101:
|
||||||
|
editor->save_data();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print_line("menu option pressed: " + itos(id));
|
print_line("menu option pressed: " + itos(id));
|
||||||
}
|
}
|
||||||
@@ -772,9 +774,8 @@ void RoadLinesEditor::load_data()
|
|||||||
struct road_line rline;
|
struct road_line rline;
|
||||||
Dictionary entry = json.get(key, Dictionary());
|
Dictionary entry = json.get(key, Dictionary());
|
||||||
Array points = entry.get("points", Array());
|
Array points = entry.get("points", Array());
|
||||||
Array indices;
|
Array indices = entry.get("indices", Array());
|
||||||
if (entry.has("indices"))
|
rline.metadata = entry.get("metadata", Dictionary());
|
||||||
indices = entry.get("indices", Array());
|
|
||||||
int lanes = entry.get("lanes", -1);
|
int lanes = entry.get("lanes", -1);
|
||||||
int pattern = entry.get("pattern", -1);
|
int pattern = entry.get("pattern", -1);
|
||||||
rline.pattern = pattern;
|
rline.pattern = pattern;
|
||||||
@@ -794,6 +795,46 @@ void RoadLinesEditor::load_data()
|
|||||||
e = e->next();
|
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)
|
template <class T> T *RoadLinesEditor::get_as_node(const String &path)
|
||||||
{
|
{
|
||||||
Node *node = scene()->get_node(NodePath(path));
|
Node *node = scene()->get_node(NodePath(path));
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
void set_line_index(int index);
|
void set_line_index(int index);
|
||||||
void line_list_filter_changed(const String &text);
|
void line_list_filter_changed(const String &text);
|
||||||
template <class T> T *get_as_node(const String &path);
|
template <class T> T *get_as_node(const String &path);
|
||||||
|
void save_data();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void activate();
|
void activate();
|
||||||
|
|||||||
Reference in New Issue
Block a user