Proper display of building types

This commit is contained in:
2024-07-26 23:37:15 +03:00
parent d61618c895
commit 72beab0829
4 changed files with 11657 additions and 4899 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -38,17 +38,30 @@ func editor_event(evname: String, args: Array):
var mode_next = args[1]
if vmode.has(mode_next):
vmode[mode_next].show()
if mode_next == 2:
$WorldEditor.editor_command("get_building_types", [])
elif evname == "result:get_closest_building":
print(evname, args)
select_building(args[0], args[3])
select_building(args[0], args[3], args[4])
elif evname == "result:get_building_types":
print(evname, args)
var btypes = args[0]
$"%building_type".clear()
for k in btypes.keys():
$"%building_type".add_item(k)
else:
breakpoint
var selected_building
var selected_building_xform
func select_building(xform, id):
func select_building(xform, id, mid):
selected_building = id
selected_building_xform = xform
print("selected id: ", id)
for h in range($"%building_type".get_item_count()):
var item = $"%building_type".get_item_text(h)
if item == mid:
$"%building_type".select(h)
break
if !$building_cursor.visible:
$building_cursor.show()
$building_cursor.global_transform.origin = xform.origin

View File

@@ -36,13 +36,6 @@ void StreamWorld::read_buildings_json(const String &buildings_path)
continue;
}
building::from_dict(&b, json[key], key);
#if 0
b.key = key;
b.id = json[key].get("id");
String aabb_s = json[key].get("aabb");
b.xform = from_string<Transform>(key);
b.aabb = from_string<AABB>(aabb_s);
#endif
buildings.push_back(b);
e = e->next();
}
@@ -67,7 +60,7 @@ void StreamWorld::save_buildings_json(const String &buildings_path)
int i;
String buildings_json = FileAccess::get_file_as_string(buildings_path);
String backup_path = buildings_path + ".bak";
String store_path = buildings_path + ".new";
String store_path = buildings_path;
FileAccess *fa = FileAccess::open(backup_path, FileAccess::WRITE);
fa->store_string(buildings_json);
fa->close();
@@ -410,11 +403,12 @@ void StreamWorld::run_command(const String &command, const Array &args)
}
}
Array ret_data;
ret_data.resize(4);
ret_data.resize(5);
ret_data[0] = ret;
ret_data[1] = dst;
ret_data[2] = rkey;
ret_data[3] = id;
ret_data[4] = buildings[id].id;
emit_signal("command_result", command, ret_data);
} else if (command == "get_building_id_for_key") {
if (args.size() == 0) {
@@ -454,6 +448,12 @@ void StreamWorld::run_command(const String &command, const Array &args)
String buildings_path =
config.get_value("buildings", "buildings_path");
save_buildings_json(buildings_path);
} else if (command == "get_building_types") {
Dictionary buildings_data =
config.get_value("buildings", "building_data");
Array ret_data;
ret_data.push_back(buildings_data);
emit_signal("command_result", command, ret_data);
} else
print_error("No command " + command);
}

View File

@@ -132,6 +132,10 @@ void WorldEditor::editor_command(const String &command, const Array &args)
if (stream_world) {
stream_world->run_command(command, args);
}
} else if (command == "get_building_types") {
if (stream_world) {
stream_world->run_command(command, args);
}
}
}