Implemented structure relocation
This commit is contained in:
@@ -30,6 +30,7 @@ void StreamWorld::read_buildings_json(const String &buildings_path)
|
||||
while (e) {
|
||||
struct building b;
|
||||
String key = e->get();
|
||||
b.key = key;
|
||||
b.id = json[key].get("id");
|
||||
if (b.id == "empty") {
|
||||
e = e->next();
|
||||
@@ -277,6 +278,67 @@ void StreamWorld::update_items()
|
||||
|
||||
void StreamWorld::run_command(const String &command, const Array &args)
|
||||
{
|
||||
if (command == "get_closest_building") {
|
||||
if (args.size() == 0) {
|
||||
print_error("bad command: not enough args: " + command);
|
||||
return;
|
||||
}
|
||||
const Transform &xform = args[0];
|
||||
int i;
|
||||
float dst = Math_INF;
|
||||
Transform ret;
|
||||
String rkey;
|
||||
int id = -1;
|
||||
for (i = 0; i < (int)buildings.size(); i++) {
|
||||
Vector3 o = xform.origin;
|
||||
Vector3 m = buildings[i].xform.origin;
|
||||
float mdst = o.distance_squared_to(m);
|
||||
if (dst > mdst) {
|
||||
ret = buildings[i].xform;
|
||||
dst = mdst;
|
||||
rkey = buildings[i].key;
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
Array ret_data;
|
||||
ret_data.resize(4);
|
||||
ret_data[0] = ret;
|
||||
ret_data[1] = dst;
|
||||
ret_data[2] = rkey;
|
||||
ret_data[3] = id;
|
||||
emit_signal("command_result", command, ret_data);
|
||||
} else if (command == "get_building_id_for_key") {
|
||||
if (args.size() == 0) {
|
||||
print_error("bad command: not enough args: " + command);
|
||||
return;
|
||||
}
|
||||
String key = args[1];
|
||||
Array ret_data;
|
||||
ret_data.resize(1);
|
||||
int id = -1, i;
|
||||
for (i = 0; i < (int)buildings.size(); i++)
|
||||
if (buildings[i].key == key) {
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
ret_data[0] = id;
|
||||
emit_signal("command_result", command, ret_data);
|
||||
} else if (command == "update_building_transform") {
|
||||
if (args.size() == 0) {
|
||||
print_error("bad command: not enough args: " + command);
|
||||
return;
|
||||
}
|
||||
int id = args[0];
|
||||
if (id < 0 || id >= (int)buildings.size())
|
||||
return;
|
||||
String key = buildings[id].key;
|
||||
buildings[id].xform == args[1];
|
||||
Spatial *bnode = Object::cast_to<Spatial>(item_nodes[id]);
|
||||
bnode->set_global_transform(args[1]);
|
||||
VariantWriter::write_to_string(buildings[id].xform, key);
|
||||
buildings[id].key = key;
|
||||
} else
|
||||
print_error("No command " + command);
|
||||
}
|
||||
|
||||
void StreamWorld::_notification(int which)
|
||||
@@ -287,6 +349,8 @@ void StreamWorld::_notification(int which)
|
||||
case NOTIFICATION_EXIT_WORLD:
|
||||
break;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
break;
|
||||
if (initialized) {
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
current_scene = Object::cast_to<Node>(this);
|
||||
@@ -303,6 +367,8 @@ void StreamWorld::_notification(int which)
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
break;
|
||||
case NOTIFICATION_PROCESS: {
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
break;
|
||||
update_view();
|
||||
const String *key = scenes.next(nullptr);
|
||||
while (key) {
|
||||
@@ -337,6 +403,9 @@ void StreamWorld::_bind_methods()
|
||||
&StreamWorld::viewer_dead);
|
||||
ClassDB::bind_method(D_METHOD("run_command", "command", "args"),
|
||||
&StreamWorld::run_command);
|
||||
ADD_SIGNAL(MethodInfo("command_result",
|
||||
PropertyInfo(Variant::STRING, "result_name"),
|
||||
PropertyInfo(Variant::ARRAY, "args")));
|
||||
}
|
||||
|
||||
StreamWorld::StreamWorld()
|
||||
@@ -396,4 +465,4 @@ void StreamWorld::cleanup()
|
||||
StreamWorld::~StreamWorld()
|
||||
{
|
||||
RoadProcessing::cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user