diff --git a/src/modules/stream/road_lines_editor.cpp b/src/modules/stream/road_lines_editor.cpp index ab3d4ac..95bfb39 100644 --- a/src/modules/stream/road_lines_editor.cpp +++ b/src/modules/stream/road_lines_editor.cpp @@ -324,6 +324,9 @@ protected: ->show(); update_metadata_editor(); break; + case 30: + editor->remove_generated_stuff(); + break; case 51: editor->set_point_to_cursor(); break; @@ -988,6 +991,11 @@ String RoadLinesEditor::get_current_line_metadata() const assert(lines.has(current_line)); return JSON::print(lines[current_line].metadata, "\t", true); } +void RoadLinesEditor::remove_generated_stuff() +{ + Array args; + editor->editor_command("remove_generated_stuff", args); +} template T *RoadLinesEditor::get_as_node(const String &path) { Node *node = scene()->get_node(NodePath(path)); diff --git a/src/modules/stream/road_lines_editor.h b/src/modules/stream/road_lines_editor.h index bfa71d8..25ac4ef 100644 --- a/src/modules/stream/road_lines_editor.h +++ b/src/modules/stream/road_lines_editor.h @@ -42,6 +42,7 @@ public: void save_data(); void update_current_line_metadata(const String &text); String get_current_line_metadata() const; + void remove_generated_stuff(); protected: void activate(); diff --git a/src/modules/stream/stream.cpp b/src/modules/stream/stream.cpp index 5726432..0805436 100644 --- a/src/modules/stream/stream.cpp +++ b/src/modules/stream/stream.cpp @@ -385,6 +385,27 @@ void StreamWorld::remove_generated_stuff() ERR_FAIL_COND_MSG(result != OK, "Failed to load config"); Array gen_prefixes = config.get_value("lines", "gen_prefixes"); // TODO: implement + std::vector erased_indices; + erased_indices.reserve(buildings.size()); + int i, j; + for (i = 0; i < (int)buildings.size(); i++) { + for (j = 0; j < (int)gen_prefixes.size(); j++) { + String prefix = gen_prefixes[j]; + if (buildings[i].id.begins_with(prefix)) { + erased_indices.push_back(i); + break; + } + } + } + for (i = erased_indices.size() - 1; i >= 0; i--) { + int index = erased_indices[i]; + unload_building(index); + buildings.erase(buildings.begin() + index); + for (j = index; j < (int)buildings.size(); j++) + item_nodes[j] = item_nodes[j + 1]; + item_nodes.erase(buildings.size()); + } + update_items(); } void StreamWorld::remove_building(int index) diff --git a/src/modules/stream/world_editor.cpp b/src/modules/stream/world_editor.cpp index 0efe2cf..f12356a 100644 --- a/src/modules/stream/world_editor.cpp +++ b/src/modules/stream/world_editor.cpp @@ -239,6 +239,8 @@ void WorldEditor::editor_command(const String &command, const Array &args) } } else if (command == "select_building") { select_building(args[0], args[1], args[2]); + } else if (command == "remove_generated_stuff") { + stream_world->run_command(command, args); } else if (road_lines_editor) { road_lines_editor->editor_command(command, args); }