Started mesh merging implementation
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -330,23 +330,42 @@ columns = 2
|
||||
unique_name_in_owner = true
|
||||
margin_top = 719.0
|
||||
margin_right = 314.0
|
||||
margin_bottom = 999.0
|
||||
margin_bottom = 1055.0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/layout_editor"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 307.0
|
||||
margin_bottom = 273.0
|
||||
margin_bottom = 329.0
|
||||
|
||||
[node name="grid_elements" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
[node name="GridContainer" type="GridContainer" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
margin_right = 300.0
|
||||
margin_bottom = 44.0
|
||||
columns = 2
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"]
|
||||
margin_top = 3.0
|
||||
margin_right = 54.0
|
||||
margin_bottom = 17.0
|
||||
text = "element"
|
||||
|
||||
[node name="grid_elements" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 58.0
|
||||
margin_right = 95.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
[node name="select_rotation" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
[node name="Label2" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"]
|
||||
margin_top = 27.0
|
||||
margin_right = 54.0
|
||||
margin_bottom = 41.0
|
||||
text = "rotation"
|
||||
|
||||
[node name="select_rotation" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 58.0
|
||||
margin_top = 24.0
|
||||
margin_right = 300.0
|
||||
margin_right = 95.0
|
||||
margin_bottom = 44.0
|
||||
text = "0"
|
||||
items = [ "0", null, false, 0, null, "90", null, false, 1, null, "180", null, false, 2, null, "270", null, false, 3, null ]
|
||||
@@ -359,60 +378,129 @@ margin_right = 300.0
|
||||
margin_bottom = 68.0
|
||||
text = "Clear cell"
|
||||
|
||||
[node name="grow_cell_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
[node name="growth" type="HBoxContainer" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
margin_top = 72.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 92.0
|
||||
|
||||
[node name="grow_cell_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer/growth"]
|
||||
unique_name_in_owner = true
|
||||
margin_right = 45.0
|
||||
margin_bottom = 20.0
|
||||
text = "Grow"
|
||||
|
||||
[node name="grow_cell_style" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/growth"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 49.0
|
||||
margin_right = 123.0
|
||||
margin_bottom = 20.0
|
||||
text = "normal"
|
||||
items = [ "normal", null, false, 0, null, "side", null, false, 1, null ]
|
||||
selected = 0
|
||||
|
||||
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
margin_top = 96.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 100.0
|
||||
|
||||
[node name="grid_elements_corner" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
[node name="make_room" type="GridContainer" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
margin_top = 104.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 124.0
|
||||
margin_bottom = 252.0
|
||||
columns = 2
|
||||
|
||||
[node name="grid_elements_side" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
[node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
margin_top = 3.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 17.0
|
||||
text = "corner"
|
||||
|
||||
[node name="grid_elements_corner" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 91.0
|
||||
margin_right = 165.0
|
||||
margin_bottom = 20.0
|
||||
|
||||
[node name="Label2" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
margin_top = 27.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 41.0
|
||||
text = "side"
|
||||
|
||||
[node name="grid_elements_side" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 91.0
|
||||
margin_top = 24.0
|
||||
margin_right = 165.0
|
||||
margin_bottom = 44.0
|
||||
|
||||
[node name="Label3" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
margin_top = 51.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 65.0
|
||||
text = "floor"
|
||||
|
||||
[node name="grid_elements_floor" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 91.0
|
||||
margin_top = 48.0
|
||||
margin_right = 165.0
|
||||
margin_bottom = 68.0
|
||||
|
||||
[node name="Label4" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
margin_top = 77.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 91.0
|
||||
text = "width"
|
||||
|
||||
[node name="make_room_width" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 91.0
|
||||
margin_top = 72.0
|
||||
margin_right = 165.0
|
||||
margin_bottom = 96.0
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
|
||||
[node name="Label5" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
margin_top = 105.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 119.0
|
||||
text = "depth"
|
||||
|
||||
[node name="make_room_depth" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_left = 91.0
|
||||
margin_top = 100.0
|
||||
margin_right = 165.0
|
||||
margin_bottom = 124.0
|
||||
min_value = 1.0
|
||||
value = 1.0
|
||||
|
||||
[node name="make_room_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 128.0
|
||||
margin_right = 300.0
|
||||
margin_right = 87.0
|
||||
margin_bottom = 148.0
|
||||
|
||||
[node name="grid_elements_floor" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 152.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 172.0
|
||||
|
||||
[node name="make_room_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 176.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 196.0
|
||||
text = "Make Room"
|
||||
|
||||
[node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
margin_top = 200.0
|
||||
margin_top = 256.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 214.0
|
||||
margin_bottom = 270.0
|
||||
text = "Level"
|
||||
|
||||
[node name="level_value" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 218.0
|
||||
margin_top = 274.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 242.0
|
||||
margin_bottom = 298.0
|
||||
|
||||
[node name="layout_selector" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
margin_top = 246.0
|
||||
margin_top = 302.0
|
||||
margin_right = 300.0
|
||||
margin_bottom = 266.0
|
||||
margin_bottom = 322.0
|
||||
|
||||
[node name="BuildingLayoutEditor" type="BuildingLayoutEditor" parent="."]
|
||||
source = ExtResource( 2 )
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <main/main.h>
|
||||
#include <core/engine.h>
|
||||
#include <scene/resources/packed_scene.h>
|
||||
#include <scene/resources/surface_tool.h>
|
||||
#include <scene/3d/mesh_instance.h>
|
||||
#include <scene/main/viewport.h>
|
||||
#include <scene/3d/camera.h>
|
||||
@@ -71,34 +72,7 @@ public:
|
||||
->get_child(i)
|
||||
->queue_delete();
|
||||
}
|
||||
List<String> layout_keys;
|
||||
int grid_size =
|
||||
ElementData::get_singleton()->get_grid_size();
|
||||
assert(grid_size > 0);
|
||||
int fl;
|
||||
for (fl = -7; fl < 7; fl++) {
|
||||
if (!ElementData::get_singleton()->has_floor(
|
||||
current_layout, is_exterior, fl))
|
||||
continue;
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
Spatial *node =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_node(
|
||||
current_layout,
|
||||
is_exterior, fl,
|
||||
i);
|
||||
String element =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_element(
|
||||
current_layout,
|
||||
is_exterior, fl,
|
||||
i);
|
||||
editor->visualize_element_at(element,
|
||||
node);
|
||||
|
||||
print_line("element: " + element);
|
||||
}
|
||||
}
|
||||
visualize_whole(current_layout, is_exterior);
|
||||
}
|
||||
editor->get_viewport()->get_camera()->set_global_translation(
|
||||
Vector3(-14, 23, 32));
|
||||
@@ -123,7 +97,8 @@ public:
|
||||
EditorEvent::get_singleton()->event.remove_listener(
|
||||
this, &LayoutEditor::event_signal_handler);
|
||||
}
|
||||
void event_signal_handler(const String &event, const Array &args)
|
||||
void event_signal_handler(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
print_line("event: " + event);
|
||||
if (event == "mouse_press") {
|
||||
@@ -214,6 +189,8 @@ public:
|
||||
->set_global_transform(base);
|
||||
ElementData::get_singleton()->ensure_floor(
|
||||
current_layout, is_exterior, current_floor);
|
||||
print_line("visualize: " + itos(current_floor));
|
||||
visualize_below_and_current(current_layout, is_exterior);
|
||||
}
|
||||
void select_grid_element(int index)
|
||||
{
|
||||
@@ -248,7 +225,9 @@ public:
|
||||
void grow_cell()
|
||||
{
|
||||
int i;
|
||||
ElementData::get_singleton()->grow_cell(current_layout,
|
||||
int type = get_as_node<OptionButton>("%grow_cell_style")
|
||||
->get_selected();
|
||||
ElementData::get_singleton()->grow_cell(type, current_layout,
|
||||
is_exterior,
|
||||
current_floor,
|
||||
current_cell);
|
||||
@@ -278,6 +257,91 @@ public:
|
||||
ClassDB::bind_method(D_METHOD("grow_cell"),
|
||||
&LayoutEditor::grow_cell);
|
||||
}
|
||||
void clear_vis(const String &key, bool exterior)
|
||||
{
|
||||
int i, j;
|
||||
int grid_size = ElementData::get_singleton()->get_grid_size();
|
||||
assert(grid_size > 0);
|
||||
int fl;
|
||||
for (fl = -7; fl < 7; fl++) {
|
||||
if (!ElementData::get_singleton()->has_floor(
|
||||
key, exterior, fl))
|
||||
continue;
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
Spatial *node =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_node(key, exterior,
|
||||
fl, i);
|
||||
for (j = 0; j < node->get_child_count(); j++)
|
||||
node->get_child(j)->queue_delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
void clear_all_vis()
|
||||
{
|
||||
List<String> layouts;
|
||||
List<String>::Element *e;
|
||||
ElementData::get_singleton()->get_grid_layouts_key_list(
|
||||
&layouts);
|
||||
e = layouts.front();
|
||||
while (e) {
|
||||
clear_vis(e->get(), false);
|
||||
clear_vis(e->get(), true);
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void visualize_whole(const String &key, bool exterior)
|
||||
{
|
||||
int i;
|
||||
int grid_size = ElementData::get_singleton()->get_grid_size();
|
||||
assert(grid_size > 0);
|
||||
int fl;
|
||||
clear_all_vis();
|
||||
for (fl = -7; fl < 7; fl++) {
|
||||
if (!ElementData::get_singleton()->has_floor(
|
||||
key, exterior, fl))
|
||||
continue;
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
Spatial *node =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_node(key, exterior,
|
||||
fl, i);
|
||||
String element =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_element(
|
||||
key, exterior, fl, i);
|
||||
editor->visualize_element_at(element, node);
|
||||
|
||||
print_line("element: " + element);
|
||||
}
|
||||
}
|
||||
}
|
||||
void visualize_below_and_current(const String &key, bool exterior)
|
||||
{
|
||||
int i;
|
||||
int grid_size = ElementData::get_singleton()->get_grid_size();
|
||||
assert(grid_size > 0);
|
||||
int fl;
|
||||
clear_all_vis();
|
||||
for (fl = -7; fl <= current_floor; fl++) {
|
||||
if (!ElementData::get_singleton()->has_floor(
|
||||
key, exterior, fl))
|
||||
continue;
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
Spatial *node =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_node(key, exterior,
|
||||
fl, i);
|
||||
String element =
|
||||
ElementData::get_singleton()
|
||||
->get_grid_element(
|
||||
key, exterior, fl, i);
|
||||
editor->visualize_element_at(element, node);
|
||||
|
||||
print_line("element: " + element);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ElementEditor : public Object {
|
||||
@@ -994,6 +1058,37 @@ void BuildingLayoutEditor::visualize_element_at(const String &element,
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Mesh> BuildingLayoutEditor::get_element_mesh(const String &element) const
|
||||
{
|
||||
Ref<ArrayMesh> ret;
|
||||
int i;
|
||||
for (i = 0; i < ELEMENT_SOCKETS; i++) {
|
||||
SurfaceTool sf;
|
||||
const String &mesh_name =
|
||||
ElementData::get_singleton()->get_element_mesh_name(
|
||||
element, i);
|
||||
const String &element_type =
|
||||
ElementData::get_singleton()->get_element_type(element);
|
||||
const Transform &xform =
|
||||
ElementData::get_singleton()->get_element_type_socket(
|
||||
element_type, i);
|
||||
Ref<ArrayMesh> mesh = meshes[mesh_name].mesh;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
void BuildingLayoutEditor::update_element_meshes()
|
||||
{
|
||||
List<String> keys;
|
||||
List<String>::Element *e;
|
||||
ElementData::get_singleton()->get_element_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
Ref<Mesh> mesh = get_element_mesh(e->get());
|
||||
ElementData::get_singleton()->set_element_mesh(e->get(), mesh);
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
|
||||
static ElementTypeEditor *etype_editor;
|
||||
static ElementEditor *element_editor;
|
||||
static LayoutEditor *layout_editor;
|
||||
@@ -1211,10 +1306,9 @@ void BuildingLayoutEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
bool input_handled = false;
|
||||
if (event->is_action_pressed("mouse1")) {
|
||||
// if (Input::get_singleton()->is_action_just_pressed("mouse1")) {
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
EditorEvent::get_singleton()->event.emit("mouse_press", args);
|
||||
EditorEvent::get_singleton()->event.emit("mouse_press",
|
||||
varray(position));
|
||||
// }
|
||||
input_handled = true;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
void visualize_element_type(const String &key,
|
||||
const String &test_element);
|
||||
void visualize_element_at(const String &element, Spatial *node);
|
||||
void visualize_below_level();
|
||||
Ref<Mesh> get_element_mesh(const String &element) const;
|
||||
|
||||
void update_element_meshes();
|
||||
|
||||
protected:
|
||||
void _notification(int which);
|
||||
|
||||
@@ -1,8 +1,66 @@
|
||||
#undef NDEBUG
|
||||
#include "element_data.h"
|
||||
ElementData *ElementData::singleton = nullptr;
|
||||
List<int> ElementData::get_grow_cells(const String &key, bool exterior, int fl,
|
||||
int cell) const
|
||||
List<int> ElementData::get_grow_cells_side(const String &key, bool exterior,
|
||||
int fl, int cell) const
|
||||
{
|
||||
List<int> grow_cells;
|
||||
int x = cell % grid_size;
|
||||
int z = cell / grid_size;
|
||||
bool grow_west = true, grow_south = true, grow_east = true,
|
||||
grow_north = true;
|
||||
int rotation = get_grid_rotation(key, exterior, fl, cell);
|
||||
if (x == 0)
|
||||
grow_west = false;
|
||||
else if (x >= grid_size - 1)
|
||||
grow_east = false;
|
||||
if (z == 0)
|
||||
grow_south = false;
|
||||
else if (z >= grid_size - 1)
|
||||
grow_north = false;
|
||||
if (rotation == 0 || rotation == 2) {
|
||||
grow_south = false;
|
||||
grow_north = false;
|
||||
} else if (rotation == 1 || rotation == 3) {
|
||||
grow_west = false;
|
||||
grow_east = false;
|
||||
}
|
||||
if (grow_west) {
|
||||
int cell_ = (x - 1) + z * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_west && grow_south) {
|
||||
int cell_ = (x - 1) + (z - 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_south) {
|
||||
int cell_ = x + (z - 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_south && grow_east) {
|
||||
int cell_ = (x + 1) + (z - 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_east) {
|
||||
int cell_ = (x + 1) + z * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_east && grow_north) {
|
||||
int cell_ = (x + 1) + (z + 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_north) {
|
||||
int cell_ = x + (z + 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
if (grow_north && grow_west) {
|
||||
int cell_ = (x - 1) + (z + 1) * grid_size;
|
||||
grow_cells.push_back(cell_);
|
||||
}
|
||||
return grow_cells;
|
||||
}
|
||||
List<int> ElementData::get_grow_cells_normal(const String &key, bool exterior,
|
||||
int fl, int cell) const
|
||||
{
|
||||
List<int> grow_cells;
|
||||
int x = cell % grid_size;
|
||||
@@ -51,7 +109,23 @@ List<int> ElementData::get_grow_cells(const String &key, bool exterior, int fl,
|
||||
}
|
||||
return grow_cells;
|
||||
}
|
||||
void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell)
|
||||
List<int> ElementData::get_grow_cells(int type, const String &key,
|
||||
bool exterior, int fl, int cell) const
|
||||
{
|
||||
switch (type) {
|
||||
case 0:
|
||||
return get_grow_cells_normal(key, exterior, fl, cell);
|
||||
break;
|
||||
case 1:
|
||||
return get_grow_cells_side(key, exterior, fl, cell);
|
||||
break;
|
||||
default:
|
||||
return List<int>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void ElementData::grow_cell(int type, const String &key, bool exterior, int fl,
|
||||
int cell)
|
||||
{
|
||||
List<int> queue;
|
||||
List<int> input_cells;
|
||||
@@ -73,7 +147,8 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell)
|
||||
// do not place original cell in inputs
|
||||
if (input_cells.find(c) == nullptr)
|
||||
input_cells.push_back(c);
|
||||
List<int> cells = get_grow_cells(key, exterior, fl, c);
|
||||
List<int> cells =
|
||||
get_grow_cells(type, key, exterior, fl, c);
|
||||
while (!cells.empty()) {
|
||||
int item = cells.front()->get();
|
||||
cells.pop_front();
|
||||
@@ -91,7 +166,8 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell)
|
||||
queue.pop_front();
|
||||
const String &el = get_grid_element(key, exterior, fl, c);
|
||||
if (el == element) {
|
||||
List<int> cells = get_grow_cells(key, exterior, fl, c);
|
||||
List<int> cells =
|
||||
get_grow_cells(type, key, exterior, fl, c);
|
||||
while (!cells.empty()) {
|
||||
int g = cells.front()->get();
|
||||
cells.pop_front();
|
||||
@@ -121,3 +197,341 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell)
|
||||
print_line("input_cells: " + itos(input_cells.size()));
|
||||
print_line("output_cells: " + itos(output_cells.size()));
|
||||
}
|
||||
void ElementData::create_new_layout(const String &key)
|
||||
{
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
flecs::entity layout = ecs.entity(key.ascii().ptr()).child_of(top);
|
||||
// one floor by default
|
||||
layout.add<struct grid_layout>();
|
||||
flecs::entity extr = ecs.entity("exterior").child_of(layout);
|
||||
extr.add<grid_layout_exterior>();
|
||||
flecs::entity intr = ecs.entity("interior").child_of(layout);
|
||||
intr.add<grid_layout_interior>();
|
||||
intr.set<grid_layout_base>({ 0 });
|
||||
extr.set<grid_layout_base>({ 0 });
|
||||
}
|
||||
void ElementData::create_new_exterior_floor(const String &key)
|
||||
{
|
||||
int i;
|
||||
flecs::entity ext = get_base(key, true);
|
||||
assert(ext.is_valid());
|
||||
struct grid_layout_base *l = ext.get_mut<grid_layout_base>();
|
||||
int floor = l->floor_count;
|
||||
flecs::entity fl =
|
||||
ecs.entity(("floor_" + itos(floor)).ascii().ptr()).child_of(ext);
|
||||
assert(fl.is_valid());
|
||||
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(fl);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
l->floor_count++;
|
||||
}
|
||||
void ElementData::create_new_interior_floor(const String &key)
|
||||
{
|
||||
int i;
|
||||
flecs::entity intr = get_base(key, false);
|
||||
assert(intr.is_valid());
|
||||
struct grid_layout_base *l = intr.get_mut<grid_layout_base>();
|
||||
int floor = l->floor_count;
|
||||
flecs::entity fl = ecs.entity(("floor_" + itos(floor)).ascii().ptr())
|
||||
.child_of(intr);
|
||||
assert(fl.is_valid());
|
||||
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(fl);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
l->floor_count++;
|
||||
}
|
||||
void ElementData::serialize_layouts(Dictionary &store)
|
||||
{
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
top.children([this, &store](flecs::entity l) {
|
||||
Dictionary layout, exterior_layout, interior_layout;
|
||||
if (l.has<struct grid_layout>()) {
|
||||
flecs::entity intr = l.lookup("interior");
|
||||
assert(intr.is_valid());
|
||||
flecs::entity extr = l.lookup("exterior");
|
||||
assert(extr.is_valid());
|
||||
intr.children([this, &interior_layout](
|
||||
flecs::entity intr_fl) {
|
||||
if (intr_fl.has<struct grid_floor>()) {
|
||||
Array items;
|
||||
intr_fl.children([&items](
|
||||
flecs::entity
|
||||
floor_item) {
|
||||
if (floor_item.has<
|
||||
struct grid_floor_item>()) {
|
||||
const struct grid_floor_item *item =
|
||||
floor_item.get<
|
||||
struct grid_floor_item>();
|
||||
Dictionary sitem;
|
||||
sitem["index"] =
|
||||
item->index;
|
||||
sitem["element"] =
|
||||
item->element;
|
||||
sitem["rotation"] =
|
||||
item->rotation;
|
||||
items.push_back(sitem);
|
||||
}
|
||||
});
|
||||
String floor_key(intr_fl.name());
|
||||
interior_layout[floor_key] = items;
|
||||
}
|
||||
});
|
||||
extr.children([this, &exterior_layout](
|
||||
flecs::entity extr_fl) {
|
||||
Array items;
|
||||
extr_fl.children([&items](flecs::entity
|
||||
floor_item) {
|
||||
if (floor_item.has<
|
||||
struct grid_floor_item>()) {
|
||||
const struct grid_floor_item
|
||||
*item = floor_item.get<
|
||||
struct grid_floor_item>();
|
||||
Dictionary sitem;
|
||||
sitem["index"] = item->index;
|
||||
sitem["element"] =
|
||||
item->element;
|
||||
sitem["rotation"] =
|
||||
item->rotation;
|
||||
items.push_back(sitem);
|
||||
}
|
||||
});
|
||||
String floor_key(extr_fl.name());
|
||||
exterior_layout[floor_key] = items;
|
||||
});
|
||||
layout["interior"] = interior_layout;
|
||||
layout["exterior"] = exterior_layout;
|
||||
}
|
||||
String layout_name(l.name());
|
||||
store[layout_name] = layout;
|
||||
});
|
||||
}
|
||||
void ElementData::unserialize_layouts(const Dictionary &store)
|
||||
{
|
||||
int i;
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
// delete all layouts
|
||||
top.children([this](flecs::entity l) { l.destruct(); });
|
||||
List<Variant> layout_keys;
|
||||
store.get_key_list(&layout_keys);
|
||||
List<Variant>::Element *e;
|
||||
e = layout_keys.front();
|
||||
while (e) {
|
||||
String layout_name = e->get();
|
||||
flecs::entity layout =
|
||||
ecs.entity(layout_name.ascii().ptr()).child_of(top);
|
||||
layout.add<grid_layout>();
|
||||
flecs::entity extr = ecs.entity("exterior").child_of(layout);
|
||||
extr.add<grid_layout_exterior>();
|
||||
extr.set<grid_layout_base>({ 0 });
|
||||
flecs::entity intr = ecs.entity("interior").child_of(layout);
|
||||
intr.add<grid_layout_interior>();
|
||||
intr.set<grid_layout_base>({ 0 });
|
||||
Dictionary store_layout = store[e->get()];
|
||||
Dictionary store_interior = store_layout["interior"];
|
||||
Dictionary store_exterior = store_layout["exterior"];
|
||||
List<Variant>::Element *ve;
|
||||
List<Variant> interior_keys;
|
||||
List<Variant> exterior_keys;
|
||||
store_interior.get_key_list(&interior_keys);
|
||||
store_exterior.get_key_list(&exterior_keys);
|
||||
for (ve = interior_keys.front(); ve; ve = ve->next()) {
|
||||
String floor_key = ve->get();
|
||||
if (floor_key.begins_with("floor_")) {
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(floor_key.ascii().ptr())
|
||||
.child_of(intr);
|
||||
assert(floor_e.is_valid());
|
||||
floor_e.add<struct grid_floor>();
|
||||
const Array &floor_interior =
|
||||
store_interior[floor_key];
|
||||
for (i = 0; i < floor_interior.size(); i++) {
|
||||
const Dictionary &item =
|
||||
floor_interior[i];
|
||||
int index = item["index"];
|
||||
String element = item["element"];
|
||||
int rotation = item["rotation"];
|
||||
String item_key = "item_" + itos(index);
|
||||
flecs::entity item_e =
|
||||
ecs.entity(item_key.ascii()
|
||||
.ptr())
|
||||
.child_of(floor_e);
|
||||
item_e.set<grid_floor_item>(
|
||||
{ index, element, rotation });
|
||||
}
|
||||
struct grid_layout_base *l =
|
||||
intr.get_mut<struct grid_layout_base>();
|
||||
l->floor_count++;
|
||||
}
|
||||
}
|
||||
for (ve = exterior_keys.front(); ve; ve = ve->next()) {
|
||||
String floor_key = ve->get();
|
||||
if (floor_key.begins_with("floor_")) {
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(floor_key.ascii().ptr())
|
||||
.child_of(extr);
|
||||
assert(floor_e.is_valid());
|
||||
floor_e.add<struct grid_floor>();
|
||||
const Array &floor_exterior =
|
||||
store_exterior[floor_key];
|
||||
for (i = 0; i < floor_exterior.size(); i++) {
|
||||
const Dictionary &item =
|
||||
floor_exterior[i];
|
||||
int index = item["index"];
|
||||
String element = item["element"];
|
||||
int rotation = item["rotation"];
|
||||
String item_key = "item_" + itos(index);
|
||||
flecs::entity item_e =
|
||||
ecs.entity(item_key.ascii()
|
||||
.ptr())
|
||||
.child_of(floor_e);
|
||||
item_e.set<grid_floor_item>(
|
||||
{ index, element, rotation });
|
||||
}
|
||||
struct grid_layout_base *l =
|
||||
extr.get_mut<struct grid_layout_base>();
|
||||
l->floor_count++;
|
||||
}
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void ElementData::ensure_floor(const String &key, bool exterior, int fl)
|
||||
{
|
||||
int i;
|
||||
if (has_floor(key, exterior, fl))
|
||||
return;
|
||||
flecs::entity base = get_base(key, exterior);
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(("floor_" + itos(fl)).ascii().ptr()).child_of(base);
|
||||
assert(floor_e.is_valid());
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(floor_e);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
assert(has_floor(key, exterior, fl));
|
||||
print_line("ensured floor: " + itos(fl));
|
||||
}
|
||||
void ElementData::load_data()
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
Dictionary conf_element_types;
|
||||
Dictionary conf_elements;
|
||||
Dictionary conf_grid_layouts;
|
||||
List<Variant> keys;
|
||||
List<Variant>::Element *e;
|
||||
elements.clear();
|
||||
element_type.clear();
|
||||
config.load("res://astream/blayout.conf");
|
||||
conf_element_types = config.get_value("buildings_layout",
|
||||
"element_types", Dictionary());
|
||||
conf_elements =
|
||||
config.get_value("buildings_layout", "elements", Dictionary());
|
||||
conf_grid_layouts = config.get_value("buildings_layout", "grid_layouts",
|
||||
Dictionary());
|
||||
conf_element_types.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
String key = e->get();
|
||||
Dictionary item = conf_element_types[key];
|
||||
assert(item.has("sockets"));
|
||||
create_element_type(key);
|
||||
Array sockets = item["sockets"];
|
||||
for (i = 0; i < sockets.size(); i++)
|
||||
set_element_type_socket(key, i, sockets[i]);
|
||||
e = e->next();
|
||||
}
|
||||
keys.clear();
|
||||
conf_elements.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
String key = e->get();
|
||||
Dictionary item = conf_elements[key];
|
||||
assert(item.has("type"));
|
||||
assert(item.has("mesh_names"));
|
||||
String type = item["type"];
|
||||
print_line("loading element: " + key + " type: " + type);
|
||||
if (key == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
create_element(key, type);
|
||||
Array mesh_names = item["mesh_names"];
|
||||
for (i = 0; i < mesh_names.size(); i++)
|
||||
set_element_mesh_name(key, i, mesh_names[i]);
|
||||
e = e->next();
|
||||
}
|
||||
unserialize_layouts(conf_grid_layouts);
|
||||
}
|
||||
void ElementData::save_data()
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
Dictionary conf_element_types;
|
||||
Dictionary conf_elements;
|
||||
Dictionary conf_exterior_grid;
|
||||
List<String> keys;
|
||||
List<String>::Element *e;
|
||||
element_type.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
Dictionary item;
|
||||
const struct grid_element_type &g = element_type[e->get()];
|
||||
if (e->get() == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
item["name"] = e->get();
|
||||
Array sockets;
|
||||
sockets.resize(ELEMENT_SOCKETS);
|
||||
for (i = 0; i < ELEMENT_SOCKETS; i++)
|
||||
sockets[i] = g.sockets[i];
|
||||
item["sockets"] = sockets;
|
||||
|
||||
conf_element_types[e->get()] = item;
|
||||
e = e->next();
|
||||
}
|
||||
keys.clear();
|
||||
elements.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
Dictionary item;
|
||||
const struct grid_element &g = elements[e->get()];
|
||||
if (e->get() == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
item["name"] = e->get();
|
||||
item["type"] = g.type;
|
||||
Array mesh_names;
|
||||
mesh_names.resize(ELEMENT_SOCKETS);
|
||||
for (i = 0; i < ELEMENT_SOCKETS; i++)
|
||||
mesh_names[i] = g.mesh_names[i];
|
||||
item["mesh_names"] = mesh_names;
|
||||
|
||||
conf_elements[e->get()] = item;
|
||||
e = e->next();
|
||||
}
|
||||
// TODO: support multiple layouts;
|
||||
serialize_layouts(conf_exterior_grid);
|
||||
|
||||
config.set_value("buildings_layout", "element_types",
|
||||
conf_element_types);
|
||||
config.set_value("buildings_layout", "elements", conf_elements);
|
||||
config.set_value("buildings_layout", "grid_layouts",
|
||||
conf_exterior_grid);
|
||||
config.save("res://astream/blayout.conf");
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <core/engine.h>
|
||||
#include <editor/editor_node.h>
|
||||
#include <flecs/flecs.h>
|
||||
#include "editor_event.h"
|
||||
template <class T> T *get_as_node(const String &path)
|
||||
{
|
||||
Node *scene;
|
||||
@@ -80,6 +81,7 @@ public:
|
||||
String name;
|
||||
String type;
|
||||
String mesh_names[ELEMENT_SOCKETS];
|
||||
Ref<Mesh> element_mesh;
|
||||
};
|
||||
int grid_step{ 4 };
|
||||
int grid_size{ 9 };
|
||||
@@ -140,69 +142,22 @@ protected:
|
||||
HashMap<String, struct grid_element> elements;
|
||||
|
||||
public:
|
||||
List<int> get_grow_cells(const String &key, bool exterior, int fl,
|
||||
int cell) const;
|
||||
void grow_cell(const String &key, bool exterior, int fl, int cell);
|
||||
void create_new_layout(const String &key)
|
||||
{
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
flecs::entity layout =
|
||||
ecs.entity(key.ascii().ptr()).child_of(top);
|
||||
// one floor by default
|
||||
layout.add<struct grid_layout>();
|
||||
flecs::entity extr = ecs.entity("exterior").child_of(layout);
|
||||
extr.add<grid_layout_exterior>();
|
||||
flecs::entity intr = ecs.entity("interior").child_of(layout);
|
||||
intr.add<grid_layout_interior>();
|
||||
intr.set<grid_layout_base>({ 0 });
|
||||
extr.set<grid_layout_base>({ 0 });
|
||||
}
|
||||
void create_new_exterior_floor(const String &key)
|
||||
{
|
||||
int i;
|
||||
flecs::entity ext = get_base(key, true);
|
||||
assert(ext.is_valid());
|
||||
struct grid_layout_base *l = ext.get_mut<grid_layout_base>();
|
||||
int floor = l->floor_count;
|
||||
flecs::entity fl =
|
||||
ecs.entity(("floor_" + itos(floor)).ascii().ptr())
|
||||
.child_of(ext);
|
||||
assert(fl.is_valid());
|
||||
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(fl);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
l->floor_count++;
|
||||
}
|
||||
void create_new_interior_floor(const String &key)
|
||||
{
|
||||
int i;
|
||||
flecs::entity intr = get_base(key, false);
|
||||
assert(intr.is_valid());
|
||||
struct grid_layout_base *l = intr.get_mut<grid_layout_base>();
|
||||
int floor = l->floor_count;
|
||||
flecs::entity fl =
|
||||
ecs.entity(("floor_" + itos(floor)).ascii().ptr())
|
||||
.child_of(intr);
|
||||
assert(fl.is_valid());
|
||||
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(fl);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
l->floor_count++;
|
||||
}
|
||||
List<int> get_grow_cells_side(const String &key, bool exterior, int fl,
|
||||
int cell) const;
|
||||
List<int> get_grow_cells_normal(const String &key, bool exterior,
|
||||
int fl, int cell) const;
|
||||
List<int> get_grow_cells(int type, const String &key, bool exterior,
|
||||
int fl, int cell) const;
|
||||
void grow_cell(int type, const String &key, bool exterior, int fl,
|
||||
int cell);
|
||||
void create_new_layout(const String &key);
|
||||
void create_new_exterior_floor(const String &key);
|
||||
void create_new_interior_floor(const String &key);
|
||||
inline int constexpr get_grid_size()
|
||||
{
|
||||
return grid_size;
|
||||
}
|
||||
flecs::entity get_base(const String &key, bool exterior) const
|
||||
inline flecs::entity get_base(const String &key, bool exterior) const
|
||||
{
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
@@ -215,7 +170,8 @@ public:
|
||||
base = layout.lookup("interior");
|
||||
return base;
|
||||
}
|
||||
flecs::entity get_floor(const String &key, bool exterior, int fl) const
|
||||
inline flecs::entity get_floor(const String &key, bool exterior,
|
||||
int fl) const
|
||||
{
|
||||
flecs::entity base = get_base(key, exterior);
|
||||
assert(base.is_valid());
|
||||
@@ -223,7 +179,7 @@ public:
|
||||
flecs::entity floor_e = base.lookup(floor_key.ascii().ptr());
|
||||
return floor_e;
|
||||
}
|
||||
bool has_floor(const String &key, bool exterior, int fl) const
|
||||
inline bool has_floor(const String &key, bool exterior, int fl) const
|
||||
{
|
||||
flecs::entity floor_e = get_floor(key, exterior, fl);
|
||||
if (!floor_e.is_valid())
|
||||
@@ -231,25 +187,7 @@ public:
|
||||
flecs::entity item_e = floor_e.lookup("item_0");
|
||||
return item_e.is_valid();
|
||||
}
|
||||
void ensure_floor(const String &key, bool exterior, int fl)
|
||||
{
|
||||
int i;
|
||||
if (has_floor(key, exterior, fl))
|
||||
return;
|
||||
flecs::entity base = get_base(key, exterior);
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(("floor_" + itos(fl)).ascii().ptr())
|
||||
.child_of(base);
|
||||
assert(floor_e.is_valid());
|
||||
for (i = 0; i < grid_size * grid_size; i++) {
|
||||
flecs::entity item =
|
||||
ecs.entity(("item_" + itos(i)).ascii().ptr())
|
||||
.child_of(floor_e);
|
||||
item.set<grid_floor_item>({ i, "empty", 0 });
|
||||
}
|
||||
assert(has_floor(key, exterior, fl));
|
||||
print_line("ensured floor: " + itos(fl));
|
||||
}
|
||||
void ensure_floor(const String &key, bool exterior, int fl);
|
||||
inline flecs::entity get_grid_entity(const String &key, bool exterior,
|
||||
int fl, int i) const
|
||||
{
|
||||
@@ -352,183 +290,8 @@ public:
|
||||
keys->push_back(String(e.name()));
|
||||
});
|
||||
}
|
||||
void serialize_layouts(Dictionary &store)
|
||||
{
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
top.children([this, &store](flecs::entity l) {
|
||||
Dictionary layout, exterior_layout, interior_layout;
|
||||
if (l.has<struct grid_layout>()) {
|
||||
flecs::entity intr = l.lookup("interior");
|
||||
assert(intr.is_valid());
|
||||
flecs::entity extr = l.lookup("exterior");
|
||||
assert(extr.is_valid());
|
||||
intr.children([this, &interior_layout](
|
||||
flecs::entity intr_fl) {
|
||||
if (intr_fl.has<struct grid_floor>()) {
|
||||
Array items;
|
||||
intr_fl.children([&items](
|
||||
flecs::entity
|
||||
floor_item) {
|
||||
if (floor_item.has<
|
||||
struct grid_floor_item>()) {
|
||||
const struct grid_floor_item *item =
|
||||
floor_item
|
||||
.get<struct grid_floor_item>();
|
||||
Dictionary sitem;
|
||||
sitem["index"] =
|
||||
item->index;
|
||||
sitem["element"] =
|
||||
item->element;
|
||||
sitem["rotation"] =
|
||||
item->rotation;
|
||||
items.push_back(
|
||||
sitem);
|
||||
}
|
||||
});
|
||||
String floor_key(
|
||||
intr_fl.name());
|
||||
interior_layout[floor_key] =
|
||||
items;
|
||||
}
|
||||
});
|
||||
extr.children([this, &exterior_layout](
|
||||
flecs::entity extr_fl) {
|
||||
Array items;
|
||||
extr_fl.children([&items](
|
||||
flecs::entity
|
||||
floor_item) {
|
||||
if (floor_item.has<
|
||||
struct grid_floor_item>()) {
|
||||
const struct grid_floor_item *item =
|
||||
floor_item.get<
|
||||
struct grid_floor_item>();
|
||||
Dictionary sitem;
|
||||
sitem["index"] =
|
||||
item->index;
|
||||
sitem["element"] =
|
||||
item->element;
|
||||
sitem["rotation"] =
|
||||
item->rotation;
|
||||
items.push_back(sitem);
|
||||
}
|
||||
});
|
||||
String floor_key(extr_fl.name());
|
||||
exterior_layout[floor_key] = items;
|
||||
});
|
||||
layout["interior"] = interior_layout;
|
||||
layout["exterior"] = exterior_layout;
|
||||
}
|
||||
String layout_name(l.name());
|
||||
store[layout_name] = layout;
|
||||
});
|
||||
}
|
||||
void unserialize_layouts(const Dictionary &store)
|
||||
{
|
||||
int i;
|
||||
flecs::entity top = ecs.lookup("grid_layouts");
|
||||
assert(top.is_valid());
|
||||
// delete all layouts
|
||||
top.children([this](flecs::entity l) { l.destruct(); });
|
||||
List<Variant> layout_keys;
|
||||
store.get_key_list(&layout_keys);
|
||||
List<Variant>::Element *e;
|
||||
e = layout_keys.front();
|
||||
while (e) {
|
||||
String layout_name = e->get();
|
||||
flecs::entity layout =
|
||||
ecs.entity(layout_name.ascii().ptr())
|
||||
.child_of(top);
|
||||
layout.add<grid_layout>();
|
||||
flecs::entity extr =
|
||||
ecs.entity("exterior").child_of(layout);
|
||||
extr.add<grid_layout_exterior>();
|
||||
extr.set<grid_layout_base>({ 0 });
|
||||
flecs::entity intr =
|
||||
ecs.entity("interior").child_of(layout);
|
||||
intr.add<grid_layout_interior>();
|
||||
intr.set<grid_layout_base>({ 0 });
|
||||
Dictionary store_layout = store[e->get()];
|
||||
Dictionary store_interior = store_layout["interior"];
|
||||
Dictionary store_exterior = store_layout["exterior"];
|
||||
List<Variant>::Element *ve;
|
||||
List<Variant> interior_keys;
|
||||
List<Variant> exterior_keys;
|
||||
store_interior.get_key_list(&interior_keys);
|
||||
store_exterior.get_key_list(&exterior_keys);
|
||||
for (ve = interior_keys.front(); ve; ve = ve->next()) {
|
||||
String floor_key = ve->get();
|
||||
if (floor_key.begins_with("floor_")) {
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(floor_key.ascii()
|
||||
.ptr())
|
||||
.child_of(intr);
|
||||
assert(floor_e.is_valid());
|
||||
floor_e.add<struct grid_floor>();
|
||||
const Array &floor_interior =
|
||||
store_interior[floor_key];
|
||||
for (i = 0; i < floor_interior.size();
|
||||
i++) {
|
||||
const Dictionary &item =
|
||||
floor_interior[i];
|
||||
int index = item["index"];
|
||||
String element =
|
||||
item["element"];
|
||||
int rotation = item["rotation"];
|
||||
String item_key =
|
||||
"item_" + itos(index);
|
||||
flecs::entity item_e =
|
||||
ecs.entity(item_key.ascii()
|
||||
.ptr())
|
||||
.child_of(
|
||||
floor_e);
|
||||
item_e.set<grid_floor_item>(
|
||||
{ index, element,
|
||||
rotation });
|
||||
}
|
||||
struct grid_layout_base *l = intr.get_mut<
|
||||
struct grid_layout_base>();
|
||||
l->floor_count++;
|
||||
}
|
||||
}
|
||||
for (ve = exterior_keys.front(); ve; ve = ve->next()) {
|
||||
String floor_key = ve->get();
|
||||
if (floor_key.begins_with("floor_")) {
|
||||
flecs::entity floor_e =
|
||||
ecs.entity(floor_key.ascii()
|
||||
.ptr())
|
||||
.child_of(extr);
|
||||
assert(floor_e.is_valid());
|
||||
floor_e.add<struct grid_floor>();
|
||||
const Array &floor_exterior =
|
||||
store_exterior[floor_key];
|
||||
for (i = 0; i < floor_exterior.size();
|
||||
i++) {
|
||||
const Dictionary &item =
|
||||
floor_exterior[i];
|
||||
int index = item["index"];
|
||||
String element =
|
||||
item["element"];
|
||||
int rotation = item["rotation"];
|
||||
String item_key =
|
||||
"item_" + itos(index);
|
||||
flecs::entity item_e =
|
||||
ecs.entity(item_key.ascii()
|
||||
.ptr())
|
||||
.child_of(
|
||||
floor_e);
|
||||
item_e.set<grid_floor_item>(
|
||||
{ index, element,
|
||||
rotation });
|
||||
}
|
||||
struct grid_layout_base *l = extr.get_mut<
|
||||
struct grid_layout_base>();
|
||||
l->floor_count++;
|
||||
}
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void serialize_layouts(Dictionary &store);
|
||||
void unserialize_layouts(const Dictionary &store);
|
||||
void get_element_type_key_list(List<String> *keys)
|
||||
{
|
||||
element_type.get_key_list(keys);
|
||||
@@ -574,12 +337,16 @@ public:
|
||||
g.name = key;
|
||||
g.type = type;
|
||||
elements[key] = g;
|
||||
EditorEvent::get_singleton()->event.emit("elements_update",
|
||||
varray(key));
|
||||
}
|
||||
void set_element_type(const String &key, const String &type)
|
||||
{
|
||||
assert(elements.has(key));
|
||||
assert(element_type.has(type));
|
||||
elements[key].type = type;
|
||||
EditorEvent::get_singleton()->event.emit("elements_update",
|
||||
varray(key));
|
||||
}
|
||||
const String &get_element_type(const String &key) const
|
||||
{
|
||||
@@ -592,6 +359,8 @@ public:
|
||||
assert(elements.has(key));
|
||||
assert(socket >= 0 && socket < ELEMENT_SOCKETS);
|
||||
elements[key].mesh_names[socket] = mesh_name;
|
||||
EditorEvent::get_singleton()->event.emit("elements_update",
|
||||
varray(key));
|
||||
}
|
||||
const String &get_element_mesh_name(const String &key, int socket)
|
||||
{
|
||||
@@ -599,7 +368,7 @@ public:
|
||||
assert(socket >= 0 && socket < ELEMENT_SOCKETS);
|
||||
return elements[key].mesh_names[socket];
|
||||
}
|
||||
int get_element_size()
|
||||
inline int get_element_size() const
|
||||
{
|
||||
return elements.size();
|
||||
}
|
||||
@@ -607,123 +376,20 @@ public:
|
||||
{
|
||||
elements.get_key_list(keys);
|
||||
}
|
||||
bool has_element(const String &key)
|
||||
inline bool has_element(const String &key) const
|
||||
{
|
||||
return elements.has(key);
|
||||
}
|
||||
void save_data()
|
||||
Ref<Mesh> get_element_mesh(const String &element) const
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
Dictionary conf_element_types;
|
||||
Dictionary conf_elements;
|
||||
Dictionary conf_exterior_grid;
|
||||
List<String> keys;
|
||||
List<String>::Element *e;
|
||||
element_type.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
Dictionary item;
|
||||
const struct grid_element_type &g =
|
||||
element_type[e->get()];
|
||||
if (e->get() == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
item["name"] = e->get();
|
||||
Array sockets;
|
||||
sockets.resize(ELEMENT_SOCKETS);
|
||||
for (i = 0; i < ELEMENT_SOCKETS; i++)
|
||||
sockets[i] = g.sockets[i];
|
||||
item["sockets"] = sockets;
|
||||
|
||||
conf_element_types[e->get()] = item;
|
||||
e = e->next();
|
||||
}
|
||||
keys.clear();
|
||||
elements.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
Dictionary item;
|
||||
const struct grid_element &g = elements[e->get()];
|
||||
if (e->get() == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
item["name"] = e->get();
|
||||
item["type"] = g.type;
|
||||
Array mesh_names;
|
||||
mesh_names.resize(ELEMENT_SOCKETS);
|
||||
for (i = 0; i < ELEMENT_SOCKETS; i++)
|
||||
mesh_names[i] = g.mesh_names[i];
|
||||
item["mesh_names"] = mesh_names;
|
||||
|
||||
conf_elements[e->get()] = item;
|
||||
e = e->next();
|
||||
}
|
||||
// TODO: support multiple layouts;
|
||||
serialize_layouts(conf_exterior_grid);
|
||||
|
||||
config.set_value("buildings_layout", "element_types",
|
||||
conf_element_types);
|
||||
config.set_value("buildings_layout", "elements", conf_elements);
|
||||
config.set_value("buildings_layout", "grid_layouts",
|
||||
conf_exterior_grid);
|
||||
config.save("res://astream/blayout.conf");
|
||||
return elements[element].element_mesh;
|
||||
}
|
||||
void load_data()
|
||||
void set_element_mesh(const String &element, const Ref<Mesh> &mesh)
|
||||
{
|
||||
int i;
|
||||
ConfigFile config;
|
||||
Dictionary conf_element_types;
|
||||
Dictionary conf_elements;
|
||||
Dictionary conf_grid_layouts;
|
||||
List<Variant> keys;
|
||||
List<Variant>::Element *e;
|
||||
elements.clear();
|
||||
element_type.clear();
|
||||
config.load("res://astream/blayout.conf");
|
||||
conf_element_types = config.get_value(
|
||||
"buildings_layout", "element_types", Dictionary());
|
||||
conf_elements = config.get_value("buildings_layout", "elements",
|
||||
Dictionary());
|
||||
conf_grid_layouts = config.get_value(
|
||||
"buildings_layout", "grid_layouts", Dictionary());
|
||||
conf_element_types.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
String key = e->get();
|
||||
Dictionary item = conf_element_types[key];
|
||||
assert(item.has("sockets"));
|
||||
create_element_type(key);
|
||||
Array sockets = item["sockets"];
|
||||
for (i = 0; i < sockets.size(); i++)
|
||||
set_element_type_socket(key, i, sockets[i]);
|
||||
e = e->next();
|
||||
}
|
||||
keys.clear();
|
||||
conf_elements.get_key_list(&keys);
|
||||
e = keys.front();
|
||||
while (e) {
|
||||
String key = e->get();
|
||||
Dictionary item = conf_elements[key];
|
||||
assert(item.has("type"));
|
||||
assert(item.has("mesh_names"));
|
||||
String type = item["type"];
|
||||
print_line("loading element: " + key +
|
||||
" type: " + type);
|
||||
if (key == "empty") {
|
||||
e = e->next();
|
||||
continue;
|
||||
}
|
||||
create_element(key, type);
|
||||
Array mesh_names = item["mesh_names"];
|
||||
for (i = 0; i < mesh_names.size(); i++)
|
||||
set_element_mesh_name(key, i, mesh_names[i]);
|
||||
e = e->next();
|
||||
}
|
||||
unserialize_layouts(conf_grid_layouts);
|
||||
elements[element].element_mesh = mesh;
|
||||
}
|
||||
void save_data();
|
||||
void load_data();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -74,7 +74,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
void handle_event(const String &event, const Array &args)
|
||||
void handle_event(const String &event, const Vector<Variant> &args)
|
||||
{
|
||||
if (event == "buildings_building_cursor_moved") {
|
||||
Vector3 position = args[0];
|
||||
@@ -143,13 +143,11 @@ private:
|
||||
xform.origin.y = position_y->get_text().to_float();
|
||||
xform.origin.z = position_z->get_text().to_float();
|
||||
String key = editor->get_selected_building();
|
||||
Array args;
|
||||
args.push_back(key);
|
||||
args.push_back(xform);
|
||||
int mode = editor->get_buildings_editor_mode();
|
||||
if (mode == 1 || mode == 2)
|
||||
editor->set_cursor_position(xform.origin);
|
||||
editor->emit("run_update_building_transform", args);
|
||||
editor->emit("run_update_building_transform",
|
||||
varray(key, xform));
|
||||
}
|
||||
void handle_update()
|
||||
{
|
||||
@@ -269,7 +267,7 @@ class HandleButton : public Object {
|
||||
BuildingsEditor *editor;
|
||||
String button_path;
|
||||
String event_string;
|
||||
Array event_args;
|
||||
Vector<Variant> event_args;
|
||||
Button *get_button()
|
||||
{
|
||||
Button *button = editor->get_as_node<Button>(button_path);
|
||||
@@ -284,7 +282,7 @@ class HandleButton : public Object {
|
||||
public:
|
||||
HandleButton(BuildingsEditor *editor, const String &button_path,
|
||||
const String &event_string,
|
||||
const Array &event_args = Array())
|
||||
const Vector<Variant> &event_args = varray())
|
||||
: Object()
|
||||
, editor(editor)
|
||||
, button_path(button_path)
|
||||
@@ -370,9 +368,9 @@ void BuildingsEditor::activate()
|
||||
Error result = config.load("res://config/stream.conf");
|
||||
ERR_FAIL_COND_MSG(result != OK, "Failed to load config");
|
||||
print_line("BuildingsEditor ACTIVE");
|
||||
Array args;
|
||||
ui_handlers.push_back(memnew(HandleButton(
|
||||
this, "%buildings_create_building", "create_building", args)));
|
||||
ui_handlers.push_back(
|
||||
memnew(HandleButton(this, "%buildings_create_building",
|
||||
"create_building", varray())));
|
||||
ui_handlers.push_back(memnew(HandleChangeBuildingType(this)));
|
||||
ui_handlers.push_back(memnew(HandleDeleteButton(this)));
|
||||
ui_handlers.push_back(memnew(HandlePositionSetting(this)));
|
||||
@@ -412,7 +410,8 @@ void BuildingsEditor::deactivate()
|
||||
active = false;
|
||||
}
|
||||
|
||||
void BuildingsEditor::event_handler(const String &event, const Array &args)
|
||||
void BuildingsEditor::event_handler(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
assert(active);
|
||||
print_line("E::" + event);
|
||||
@@ -453,7 +452,6 @@ void BuildingsEditor::handle_create_building()
|
||||
int index = building_type->get_selected();
|
||||
if (index >= 0) {
|
||||
const String &item = building_type->get_item_text(index);
|
||||
Array args;
|
||||
Transform xform;
|
||||
xform.origin = get_cursor_position();
|
||||
Dictionary building_data;
|
||||
@@ -466,8 +464,8 @@ void BuildingsEditor::handle_create_building()
|
||||
.hash64(),
|
||||
16);
|
||||
building_data["xform"] = building_xform;
|
||||
args.push_back(building_data);
|
||||
editor->editor_command("create_building", args);
|
||||
editor->editor_command("create_building",
|
||||
varray(building_data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,16 +537,15 @@ void BuildingsEditor::mouse_drag(const Vector2 &position)
|
||||
->get_generator();
|
||||
float h = gen->get_height_full(newpos);
|
||||
newpos.y = h;
|
||||
Array args;
|
||||
args.push_back(selected_building);
|
||||
args.push_back(Transform(selected_building_xform.basis,
|
||||
newpos));
|
||||
editor->editor_command("update_building_transform",
|
||||
args);
|
||||
editor->editor_command(
|
||||
"update_building_transform",
|
||||
varray(selected_building,
|
||||
Transform(selected_building_xform.basis,
|
||||
newpos)));
|
||||
set_cursor_position(newpos);
|
||||
selected_building_xform = Transform(
|
||||
selected_building_xform.basis, newpos);
|
||||
emit("buildings_building_moved", Array());
|
||||
emit("buildings_building_moved", varray());
|
||||
} break;
|
||||
case 2: {
|
||||
/* rotate */
|
||||
@@ -557,15 +554,13 @@ void BuildingsEditor::mouse_drag(const Vector2 &position)
|
||||
m.y = selected_building_xform.origin.y;
|
||||
Transform xform = selected_building_xform.looking_at(
|
||||
m, Vector3(0.0f, 1.0f, 0.0f));
|
||||
Array args;
|
||||
args.push_back(selected_building);
|
||||
args.push_back(xform);
|
||||
editor->editor_command("update_building_transform",
|
||||
args);
|
||||
varray(selected_building,
|
||||
xform));
|
||||
selected_building_xform = xform;
|
||||
get_as_node<Spatial>("%building_rot_cursor")
|
||||
->set_global_transform(xform);
|
||||
emit("buildings_building_rotated", Array());
|
||||
emit("buildings_building_rotated", varray());
|
||||
} break;
|
||||
case 3: { /* create */
|
||||
print_verbose("create: " + (proj.operator String()));
|
||||
@@ -606,33 +601,30 @@ void BuildingsEditor::mouse_press(const Vector2 &position)
|
||||
switch (mode) {
|
||||
case 0: {
|
||||
/* select */
|
||||
Array args;
|
||||
Transform xform(Basis(), proj);
|
||||
args.push_back(xform);
|
||||
editor->editor_command("get_closest_building", args);
|
||||
editor->editor_command("get_closest_building",
|
||||
varray(xform));
|
||||
} break;
|
||||
case 1: {
|
||||
/* move */
|
||||
editor->editor_command("checkpoint", Array());
|
||||
editor->editor_command("checkpoint", varray());
|
||||
} break;
|
||||
case 2: {
|
||||
/* TODO: deduplicate */
|
||||
/* rotate */
|
||||
editor->editor_command("checkpoint", Array());
|
||||
editor->editor_command("checkpoint", varray());
|
||||
print_verbose("rotate: " + (proj.operator String()));
|
||||
Vector3 m = proj;
|
||||
m.y = selected_building_xform.origin.y;
|
||||
Transform xform = selected_building_xform.looking_at(
|
||||
m, Vector3(0.0f, 1.0f, 0.0f));
|
||||
Array args;
|
||||
args.push_back(selected_building);
|
||||
args.push_back(xform);
|
||||
editor->editor_command("update_building_transform",
|
||||
args);
|
||||
varray(selected_building,
|
||||
xform));
|
||||
selected_building_xform = xform;
|
||||
get_as_node<Spatial>("%building_rot_cursor")
|
||||
->set_global_transform(xform);
|
||||
emit("buildings_building_rotated", Array());
|
||||
emit("buildings_building_rotated", varray());
|
||||
} break;
|
||||
/* TODO: deduplicate */
|
||||
case 3: { /* create */
|
||||
@@ -659,9 +651,7 @@ void BuildingsEditor::set_cursor_position(const Vector3 &position)
|
||||
if (!xform.origin.is_equal_approx(position)) {
|
||||
xform.origin = position;
|
||||
cursor->set_global_transform(xform);
|
||||
Array args;
|
||||
args.push_back(position);
|
||||
emit("buildings_building_cursor_moved", args);
|
||||
emit("buildings_building_cursor_moved", varray(position));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,34 +688,29 @@ Transform BuildingsEditor::get_selected_building_xform() const
|
||||
|
||||
void BuildingsEditor::delete_building_handler()
|
||||
{
|
||||
Array args, args2;
|
||||
args.push_back(selected_building);
|
||||
editor->editor_command("remove_building", args);
|
||||
args2.push_back(selected_building_xform);
|
||||
editor->editor_command("get_closest_building", args2);
|
||||
editor->editor_command("remove_building", varray(selected_building));
|
||||
editor->editor_command("get_closest_building",
|
||||
varray(selected_building_xform));
|
||||
}
|
||||
|
||||
void BuildingsEditor::change_building_type(const String &type_name)
|
||||
{
|
||||
Array args;
|
||||
int bmode = get_buildings_editor_mode();
|
||||
assert(bmode == 0 || bmode == 1 ||
|
||||
bmode == 2); /* select, move, rotate */
|
||||
args.push_back(selected_building);
|
||||
args.push_back(type_name);
|
||||
editor->editor_command("change_building_type", args);
|
||||
editor->editor_command("change_building_type",
|
||||
varray(selected_building, type_name));
|
||||
}
|
||||
|
||||
void BuildingsEditor::emit(const String &event_string, const Array &event_args)
|
||||
void BuildingsEditor::emit(const String &event_string,
|
||||
const Vector<Variant> &event_args)
|
||||
{
|
||||
EditorEvent::get_singleton()->event.emit(event_string, event_args);
|
||||
}
|
||||
|
||||
void BuildingsEditor::remove_buildings_by_prefix(const String &prefix)
|
||||
{
|
||||
Array args;
|
||||
args.push_back(prefix);
|
||||
editor->editor_command("remove_buildings_by_prefix", args);
|
||||
editor->editor_command("remove_buildings_by_prefix", varray(prefix));
|
||||
}
|
||||
|
||||
void BuildingsEditor::select_building(const Transform &xform, const String &key,
|
||||
@@ -751,12 +736,13 @@ void BuildingsEditor::select_building(const Transform &xform, const String &key,
|
||||
Button *delete_button =
|
||||
get_as_node<Button>("%buildings_delete_building");
|
||||
delete_button->show();
|
||||
emit("buildings_building_selected", Array());
|
||||
emit("buildings_building_selected", varray());
|
||||
}
|
||||
set_cursor_position(xform.origin);
|
||||
}
|
||||
|
||||
void BuildingsEditor::editor_command(const String &command, const Array &args)
|
||||
void BuildingsEditor::editor_command(const String &command,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
if (command == "select_building") {
|
||||
select_building(args[0], args[1], args[2]);
|
||||
|
||||
@@ -9,7 +9,7 @@ class BuildingsEditor {
|
||||
bool active;
|
||||
void activate();
|
||||
void deactivate();
|
||||
void event_handler(const String &event, const Array &args);
|
||||
void event_handler(const String &event, const Vector<Variant> &args);
|
||||
template <class T> void mode_visibility(int mode, const String &path);
|
||||
void handle_create_building();
|
||||
|
||||
@@ -28,10 +28,11 @@ public:
|
||||
void select_building(const Transform &xform, const String &key,
|
||||
const String &mid);
|
||||
void remove_buildings_by_prefix(const String &prefix);
|
||||
void editor_command(const String &command, const Array &args);
|
||||
void editor_command(const String &command, const Vector<Variant> &args);
|
||||
void delete_building_handler();
|
||||
void change_building_type(const String &type_name);
|
||||
void emit(const String &event_string, const Array &event_args);
|
||||
void emit(const String &event_string,
|
||||
const Vector<Variant> &event_args);
|
||||
template <class T> T *get_as_node(const String &path);
|
||||
template <class T> const T *get_as_node(const String &path) const;
|
||||
Node *scene();
|
||||
|
||||
@@ -20,7 +20,8 @@ EditorEvent *EditorEvent::get_singleton()
|
||||
return singleton;
|
||||
}
|
||||
|
||||
void EditorEvent::EventHelper::emit(const String &event, const Array &args)
|
||||
void EditorEvent::EventHelper::emit(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
auto evl = listeners.begin();
|
||||
while (evl != listeners.end()) {
|
||||
|
||||
@@ -10,9 +10,9 @@ public:
|
||||
class H {};
|
||||
H *obj;
|
||||
void (H::*method)(const String &event,
|
||||
const Array &args);
|
||||
const Vector<Variant> &args);
|
||||
void execute(const String &event,
|
||||
const Array &args) const
|
||||
const Vector<Variant> &args) const
|
||||
{
|
||||
(obj->*method)(event, args);
|
||||
}
|
||||
@@ -20,17 +20,20 @@ public:
|
||||
std::list<event_listener_ptrs> listeners;
|
||||
typedef event_listener_ptrs::H *obj_t;
|
||||
typedef void (event_listener_ptrs::H::*method_t)(
|
||||
const String &event, const Array &args);
|
||||
const String &event, const Vector<Variant> &args);
|
||||
|
||||
public:
|
||||
template <class T>
|
||||
void add_listener(T *obj, void (T::*method)(const String &event,
|
||||
const Array &args));
|
||||
void
|
||||
add_listener(T *obj,
|
||||
void (T::*method)(const String &event,
|
||||
const Vector<Variant> &args));
|
||||
template <class T>
|
||||
void remove_listener(T *obj,
|
||||
void (T::*method)(const String &event,
|
||||
const Array &args));
|
||||
void emit(const String &event, const Array &args);
|
||||
void
|
||||
remove_listener(T *obj,
|
||||
void (T::*method)(const String &event,
|
||||
const Vector<Variant> &args));
|
||||
void emit(const String &event, const Vector<Variant> &args);
|
||||
};
|
||||
EventHelper event;
|
||||
|
||||
@@ -44,7 +47,8 @@ public:
|
||||
};
|
||||
template <class T>
|
||||
void EditorEvent::EventHelper::remove_listener(
|
||||
T *obj, void (T::*method)(const String &event, const Array &args))
|
||||
T *obj,
|
||||
void (T::*method)(const String &event, const Vector<Variant> &args))
|
||||
{
|
||||
listeners.remove_if([obj, method](const event_listener_ptrs &e) {
|
||||
return e.obj == reinterpret_cast<obj_t>(obj) &&
|
||||
@@ -53,7 +57,8 @@ void EditorEvent::EventHelper::remove_listener(
|
||||
}
|
||||
template <class T>
|
||||
void EditorEvent::EventHelper::add_listener(
|
||||
T *obj, void (T::*method)(const String &event, const Array &args))
|
||||
T *obj,
|
||||
void (T::*method)(const String &event, const Vector<Variant> &args))
|
||||
{
|
||||
auto evl = listeners.begin();
|
||||
bool bad = false;
|
||||
|
||||
@@ -52,9 +52,8 @@ void LineMetadataEditor::_notification(int which)
|
||||
line_buildings_list->set_owner(this);
|
||||
EditorEvent::get_singleton()->event.add_listener(
|
||||
this, &LineMetadataEditor::event_handler);
|
||||
Array args;
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"lines_get_current_line", args);
|
||||
"lines_get_current_line", varray());
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
EditorEvent::get_singleton()->event.remove_listener(
|
||||
@@ -71,7 +70,8 @@ void LineMetadataEditor::_bind_methods()
|
||||
{
|
||||
}
|
||||
|
||||
void LineMetadataEditor::event_handler(const String &event, const Array &args)
|
||||
void LineMetadataEditor::event_handler(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
if (event == "lines_select_line") {
|
||||
const String ¤t_line = args[0];
|
||||
|
||||
@@ -11,5 +11,5 @@ private:
|
||||
Vector<Control *> u_controls;
|
||||
void _notification(int which);
|
||||
static void _bind_methods();
|
||||
void event_handler(const String &event, const Array &args);
|
||||
void event_handler(const String &event, const Vector<Variant> &args);
|
||||
};
|
||||
@@ -93,10 +93,8 @@ void NavPanel::_notification(int which)
|
||||
Camera *cam = get_viewport()->get_camera();
|
||||
camera_xform.orthonormalize();
|
||||
cam->set_global_transform(camera_xform);
|
||||
Array move_args;
|
||||
move_args.push_back(camera_xform);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"editor_camera_moved", move_args);
|
||||
"editor_camera_moved", varray(camera_xform));
|
||||
transform_changhed = false;
|
||||
print_line("moved: " +
|
||||
(camera_xform.origin.operator String()));
|
||||
|
||||
@@ -962,11 +962,11 @@ void RoadLinesData::update_buildings_from_lines()
|
||||
::lines[line].buildings[i].y_rotation);
|
||||
b.xform.origin = pt;
|
||||
b.xform.basis = basis;
|
||||
Array args;
|
||||
args.push_back(
|
||||
::lines[line].buildings[i].building_key);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"building_updated", args);
|
||||
"building_updated",
|
||||
varray(::lines[line]
|
||||
.buildings[i]
|
||||
.building_key));
|
||||
} else {
|
||||
Vector3 pt = get_point_by_offsets(
|
||||
line,
|
||||
@@ -984,10 +984,8 @@ void RoadLinesData::update_buildings_from_lines()
|
||||
BuildingsData::building::from_dict(&nb, data);
|
||||
String bkey = bd->create_building(nb);
|
||||
assert(bkey.length() > 0);
|
||||
Array args;
|
||||
args.push_back(bkey);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"building_created", args);
|
||||
"building_created", varray(bkey));
|
||||
}
|
||||
}
|
||||
e = e->next();
|
||||
|
||||
@@ -28,40 +28,40 @@ static ImmediateGeometry *line_im = nullptr;
|
||||
// static ImmediateGeometry *debug_im = nullptr;
|
||||
static Ref<Material> debug_material;
|
||||
|
||||
#define __evhandler(vname, mtype) \
|
||||
template <class T> class GDEventHandler_##vname : public Object { \
|
||||
GDCLASS(GDEventHandler_##vname, Object) \
|
||||
T *obj; \
|
||||
\
|
||||
public: \
|
||||
GDEventHandler_##vname(T *obj) \
|
||||
: Object() \
|
||||
, obj(obj) \
|
||||
{ \
|
||||
} \
|
||||
virtual ~GDEventHandler_##vname() \
|
||||
{ \
|
||||
} \
|
||||
bool connect(Object *obj, const String &signal) \
|
||||
{ \
|
||||
return obj->connect(signal, this, "handler"); \
|
||||
} \
|
||||
void disconnect(Object *obj, const String &signal) \
|
||||
{ \
|
||||
obj->disconnect(signal, this, "handler"); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
void handler(const String &event, const Array &args) \
|
||||
{ \
|
||||
obj->vname(event, args); \
|
||||
} \
|
||||
static void _bind_methods() \
|
||||
{ \
|
||||
ClassDB::bind_method( \
|
||||
D_METHOD("handler", "args"), \
|
||||
&GDEventHandler_##vname::handler); \
|
||||
} \
|
||||
#define __evhandler(vname, mtype) \
|
||||
template <class T> class GDEventHandler_##vname : public Object { \
|
||||
GDCLASS(GDEventHandler_##vname, Object) \
|
||||
T *obj; \
|
||||
\
|
||||
public: \
|
||||
GDEventHandler_##vname(T *obj) \
|
||||
: Object() \
|
||||
, obj(obj) \
|
||||
{ \
|
||||
} \
|
||||
virtual ~GDEventHandler_##vname() \
|
||||
{ \
|
||||
} \
|
||||
bool connect(Object *obj, const String &signal) \
|
||||
{ \
|
||||
return obj->connect(signal, this, "handler"); \
|
||||
} \
|
||||
void disconnect(Object *obj, const String &signal) \
|
||||
{ \
|
||||
obj->disconnect(signal, this, "handler"); \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
void handler(const String &event, const Vector<Variant> &args) \
|
||||
{ \
|
||||
obj->vname(event, args); \
|
||||
} \
|
||||
static void _bind_methods() \
|
||||
{ \
|
||||
ClassDB::bind_method( \
|
||||
D_METHOD("handler", "args"), \
|
||||
&GDEventHandler_##vname::handler); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define __evhandler_type(vname, mtype) GDEventHandler_##vname<mtype>
|
||||
@@ -704,9 +704,8 @@ void RoadLinesEditor::select_line(const String &line_name)
|
||||
set_line_index(0);
|
||||
update_line_geometry();
|
||||
}
|
||||
Array args;
|
||||
args.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_select_line", args);
|
||||
EditorEvent::get_singleton()->event.emit("lines_select_line",
|
||||
varray(current_line));
|
||||
update_ui();
|
||||
}
|
||||
|
||||
@@ -725,9 +724,8 @@ void RoadLinesEditor::line_create_point()
|
||||
Transform xform(Basis(), position);
|
||||
int index = get_line_index();
|
||||
rld->insert_line_point(current_line, index + 1, xform);
|
||||
Array args;
|
||||
args.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line",
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
update_line_index_ui();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
@@ -744,9 +742,8 @@ void RoadLinesEditor::line_delete_point()
|
||||
if (rld->lines(current_line).points.size() < 2)
|
||||
return;
|
||||
rld->erase_line_point(current_line, index);
|
||||
Array args;
|
||||
args.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line",
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
update_line_index_ui();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
@@ -765,9 +762,8 @@ void RoadLinesEditor::set_point_to_cursor()
|
||||
Transform xform = cursor->get_global_transform();
|
||||
int index = get_line_index();
|
||||
rld->set_line_point_position(current_line, index, xform.origin);
|
||||
Array args;
|
||||
args.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line",
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
set_ui_point_position(rld->lines(current_line).points[index].origin);
|
||||
}
|
||||
@@ -841,12 +837,14 @@ void RoadLinesEditor::exit()
|
||||
deactivate();
|
||||
}
|
||||
|
||||
void RoadLinesEditor::editor_command(const String &command, const Array &args)
|
||||
void RoadLinesEditor::editor_command(const String &command,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
print_line("command: " + command);
|
||||
}
|
||||
|
||||
void RoadLinesEditor::editor_event(const String &event, const Array &args)
|
||||
void RoadLinesEditor::editor_event(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
print_line("RoadLinesEditor::event: " + event);
|
||||
if (event == "mouse_press" || event == "mouse_drag") {
|
||||
@@ -974,9 +972,8 @@ void RoadLinesEditor::set_point_position(const Vector3 &position)
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
int index = get_line_index();
|
||||
rld->set_line_point_position(current_line, index, position);
|
||||
Array args;
|
||||
args.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
|
||||
EditorEvent::get_singleton()->event.emit("lines_changed_line",
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
}
|
||||
void RoadLinesEditor::set_ui_cursor_position(const Vector3 &cursor_position)
|
||||
@@ -1095,7 +1092,6 @@ void RoadLinesEditor::place_generated_objects()
|
||||
}
|
||||
void RoadLinesEditor::rebuild_roads()
|
||||
{
|
||||
Array args;
|
||||
int debug_flags = 0;
|
||||
if (debug_road_nodes)
|
||||
debug_flags |= (1 << 0);
|
||||
@@ -1104,13 +1100,11 @@ void RoadLinesEditor::rebuild_roads()
|
||||
if (debug_road_wedges)
|
||||
debug_flags |= (1 << 2);
|
||||
print_line("rebuild_roads: debug: " + itos(debug_flags));
|
||||
args.push_back(debug_flags);
|
||||
editor->editor_command("rebuild_roads", args);
|
||||
editor->editor_command("rebuild_roads", varray(debug_flags));
|
||||
}
|
||||
void RoadLinesEditor::remove_road_meshes()
|
||||
{
|
||||
Array args;
|
||||
editor->editor_command("remove_road_meshes", args);
|
||||
editor->editor_command("remove_road_meshes", varray());
|
||||
}
|
||||
void RoadLinesEditor::handle_input()
|
||||
{
|
||||
@@ -1135,9 +1129,7 @@ void RoadLinesEditor::set_debug_road_wedges(bool checked)
|
||||
}
|
||||
void RoadLinesEditor::place_zebras()
|
||||
{
|
||||
Array args;
|
||||
args.push_back("zebra");
|
||||
editor->editor_command("remove_buildings_by_prefix", args);
|
||||
editor->editor_command("remove_buildings_by_prefix", varray("zebra"));
|
||||
/*
|
||||
func place_zebras():
|
||||
var road_nodes = SceneComps.get_component("road_nodes2")
|
||||
@@ -1250,8 +1242,7 @@ String RoadLinesEditor::get_current_line_metadata() const
|
||||
}
|
||||
void RoadLinesEditor::remove_generated_stuff()
|
||||
{
|
||||
Array args;
|
||||
editor->editor_command("remove_generated_stuff", args);
|
||||
editor->editor_command("remove_generated_stuff", varray());
|
||||
}
|
||||
template <class T> T *RoadLinesEditor::get_as_node(const String &path)
|
||||
{
|
||||
@@ -1262,13 +1253,12 @@ template <class T> T *RoadLinesEditor::get_as_node(const String &path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void RoadLinesEditor::event_handler(const String &event, const Array &args)
|
||||
void RoadLinesEditor::event_handler(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
if (event == "lines_get_current_line" && current_line != "") {
|
||||
Array nargs;
|
||||
nargs.push_back(current_line);
|
||||
EditorEvent::get_singleton()->event.emit("lines_select_line",
|
||||
nargs);
|
||||
varray(current_line));
|
||||
}
|
||||
if (event == "lines_changed_line") {
|
||||
if (!update_roads)
|
||||
|
||||
@@ -11,7 +11,7 @@ class RoadLinesEditor {
|
||||
Ref<RegEx> re;
|
||||
bool camera_moved;
|
||||
Vector3 camera_motion;
|
||||
void event_handler(const String &event, const Array &args);
|
||||
void event_handler(const String &event, const Vector<Variant> &args);
|
||||
bool update_roads; // 201
|
||||
bool debug_road_nodes; // 210
|
||||
bool debug_road_edges; // 211
|
||||
@@ -33,8 +33,8 @@ public:
|
||||
void move_cursor_to_closest_building();
|
||||
void update(float delta);
|
||||
void exit();
|
||||
void editor_command(const String &command, const Array &args);
|
||||
void editor_event(const String &event, const Array &args);
|
||||
void editor_command(const String &command, const Vector<Variant> &args);
|
||||
void editor_event(const String &event, const Vector<Variant> &args);
|
||||
int get_camera_mode() const;
|
||||
void update_ui();
|
||||
void create_new_line_at_cursor(const String &line_name);
|
||||
|
||||
@@ -234,7 +234,8 @@ void StreamWorld::remove_building(const String &key)
|
||||
update_items();
|
||||
}
|
||||
|
||||
void StreamWorld::run_command(const String &command, const Array &args)
|
||||
void StreamWorld::run_command(const String &command,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
if (command == "get_closest_building") {
|
||||
if (args.size() == 0) {
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void run_command(const String &command, const Array &args);
|
||||
void run_command(const String &command, const Vector<Variant> &args);
|
||||
StreamWorld();
|
||||
~StreamWorld();
|
||||
static void cleanup();
|
||||
|
||||
@@ -21,7 +21,7 @@ class HandleCommandButton : public Object {
|
||||
WorldEditor *editor;
|
||||
String button_path;
|
||||
String command;
|
||||
Array command_args;
|
||||
Vector<Variant> command_args;
|
||||
Button *get_button()
|
||||
{
|
||||
Button *button = Object::cast_to<Button>(
|
||||
@@ -37,7 +37,7 @@ class HandleCommandButton : public Object {
|
||||
public:
|
||||
HandleCommandButton(WorldEditor *editor, const String &button_path,
|
||||
const String &command,
|
||||
const Array &command_args = Array())
|
||||
const Vector<Variant> &command_args = varray())
|
||||
: Object()
|
||||
, editor(editor)
|
||||
, button_path(button_path)
|
||||
@@ -217,8 +217,6 @@ static std::unordered_map<int, String> vmode = { { 2, "%v_buildings" },
|
||||
|
||||
void WorldEditor::tools_button(const String &button)
|
||||
{
|
||||
Array change;
|
||||
change.resize(2);
|
||||
print_line("tools_button: " + button);
|
||||
if (modes.find(button) == modes.end())
|
||||
goto end;
|
||||
@@ -227,9 +225,8 @@ void WorldEditor::tools_button(const String &button)
|
||||
goto end;
|
||||
print_line("mode change: " + itos(current_mode) + " " +
|
||||
itos(modes[button]));
|
||||
change[0] = current_mode;
|
||||
change[1] = modes[button];
|
||||
EditorEvent::get_singleton()->event.emit("mode_change_pre", change);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"mode_change_pre", varray(current_mode, modes[button]));
|
||||
switch (current_mode) {
|
||||
case MODE_ROAD_LINES:
|
||||
road_lines_editor->exit();
|
||||
@@ -255,14 +252,16 @@ void WorldEditor::tools_button(const String &button)
|
||||
mode_npc();
|
||||
break;
|
||||
}
|
||||
EditorEvent::get_singleton()->event.emit("mode_change_post", change);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"mode_change_post", varray(current_mode, modes[button]));
|
||||
assert(modes[button] >= 0);
|
||||
current_mode = modes[button];
|
||||
assert(current_mode >= 0);
|
||||
end:;
|
||||
}
|
||||
|
||||
void WorldEditor::editor_command(const String &command, const Array &args)
|
||||
void WorldEditor::editor_command(const String &command,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
print_line("running command: " + command);
|
||||
if (command.begins_with("select_") &&
|
||||
@@ -328,7 +327,8 @@ int WorldEditor::get_current_mode() const
|
||||
return current_mode;
|
||||
}
|
||||
|
||||
void WorldEditor::event_signal_handler(const String &event, const Array &args)
|
||||
void WorldEditor::event_signal_handler(const String &event,
|
||||
const Vector<Variant> &args)
|
||||
{
|
||||
if (event == "mode_change_pre") {
|
||||
int prev_mode = args[0];
|
||||
@@ -356,10 +356,10 @@ void WorldEditor::event_signal_handler(const String &event, const Array &args)
|
||||
p->show();
|
||||
switch (mode_next) {
|
||||
case 2:
|
||||
editor_command("get_building_types", Array());
|
||||
editor_command("get_building_types", varray());
|
||||
break;
|
||||
case 6:
|
||||
editor_command("get_lines_list", Array());
|
||||
editor_command("get_lines_list", varray());
|
||||
break;
|
||||
}
|
||||
} else if (event == "editor_camera_moved") {
|
||||
@@ -382,7 +382,8 @@ StreamWorld *WorldEditor::get_stream_world()
|
||||
return stream_world;
|
||||
}
|
||||
|
||||
void WorldEditor::world_command_result(const String &what, const Array &data)
|
||||
void WorldEditor::world_command_result(const String &what,
|
||||
const Vector<Variant> &data)
|
||||
{
|
||||
print_line("what: " + what);
|
||||
EditorEvent::get_singleton()->event.emit("result:" + what, data);
|
||||
@@ -471,12 +472,10 @@ void WorldEditor::_notification(int which)
|
||||
"mouse1")) {
|
||||
dragging = false;
|
||||
drag_delay = 0.2f;
|
||||
Array args;
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"mouse_drag_off", args);
|
||||
"mouse_drag_off", varray(position));
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
@@ -526,10 +525,9 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
}
|
||||
if (event->is_action_pressed("mouse1")) {
|
||||
// if (Input::get_singleton()->is_action_just_pressed("mouse1")) {
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
EditorEvent::get_singleton()->event.emit("mouse_press", args);
|
||||
EditorEvent::get_singleton()->event.emit("mouse_press",
|
||||
varray(position));
|
||||
// }
|
||||
input_handled = true;
|
||||
}
|
||||
@@ -537,22 +535,19 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
motion += mm->get_relative();
|
||||
if (Input::get_singleton()->is_action_pressed("mouse1")) {
|
||||
if (dragging) {
|
||||
Array args;
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"mouse_drag", args);
|
||||
"mouse_drag", varray(position));
|
||||
} else {
|
||||
if (drag_delay < 0.0f && !dragging) {
|
||||
dragging = true;
|
||||
Array args;
|
||||
Vector2 position =
|
||||
get_viewport()
|
||||
->get_mouse_position();
|
||||
args.push_back(position);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"mouse_drag_on", args);
|
||||
"mouse_drag_on",
|
||||
varray(position));
|
||||
}
|
||||
}
|
||||
input_handled = true;
|
||||
|
||||
@@ -21,7 +21,8 @@ protected:
|
||||
void mode_npc();
|
||||
void tools_button(const String &button);
|
||||
StreamWorld *get_stream_world();
|
||||
void world_command_result(const String &what, const Array &data);
|
||||
void world_command_result(const String &what,
|
||||
const Vector<Variant> &data);
|
||||
void _notification(int which);
|
||||
void _unhandled_input(const Ref<InputEvent> &event);
|
||||
static void _bind_methods();
|
||||
@@ -47,10 +48,11 @@ public:
|
||||
};
|
||||
WorldEditor();
|
||||
virtual ~WorldEditor();
|
||||
void editor_command(const String &command, const Array &args);
|
||||
void editor_command(const String &command, const Vector<Variant> &args);
|
||||
int get_camera_mode() const;
|
||||
int get_current_mode() const;
|
||||
void event_signal_handler(const String &event, const Array &args);
|
||||
void event_signal_handler(const String &event,
|
||||
const Vector<Variant> &args);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user