Added camera mode to c++

This commit is contained in:
2024-08-19 18:30:02 +03:00
parent 72beab0829
commit d1dc024353
7 changed files with 179 additions and 30 deletions

View File

@@ -436,8 +436,11 @@ void StreamWorld::run_command(const String &command, const Array &args)
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]);
if (item_nodes.has(id)) {
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 if (command == "buildings_checkpoint") {
@@ -454,6 +457,26 @@ void StreamWorld::run_command(const String &command, const Array &args)
Array ret_data;
ret_data.push_back(buildings_data);
emit_signal("command_result", command, ret_data);
} else if (command == "change_building_type") {
if (args.size() == 0) {
print_error("bad command: not enough args: " + command);
return;
}
int id = args[0];
String new_type = args[1];
Dictionary buildings_data =
config.get_value("buildings", "building_data");
if (!building_data.has(new_type)) {
print_error("unknown building type: " + new_type);
return;
}
String old_type = buildings[id].id;
unload_building(id);
buildings[id].id = new_type;
load_building(id);
update_items();
print_line("changed building: " + itos(id) +
" from: " + old_type + " to: " + new_type);
} else
print_error("No command " + command);
}

View File

@@ -11,6 +11,7 @@ WorldEditor::WorldEditor()
, stream_world(nullptr)
, editor_menu(nullptr)
, current_mode(-1)
, current_camera_mode(-1)
{
}
@@ -18,6 +19,16 @@ WorldEditor::~WorldEditor()
{
}
void WorldEditor::set_camera_mode(int mode)
{
current_camera_mode = mode;
}
int WorldEditor::get_camera_mode() const
{
return current_camera_mode;
}
void WorldEditor::disable_all()
{
}
@@ -136,6 +147,10 @@ void WorldEditor::editor_command(const String &command, const Array &args)
if (stream_world) {
stream_world->run_command(command, args);
}
} else if (command == "change_building_type") {
if (stream_world) {
stream_world->run_command(command, args);
}
}
}
@@ -198,6 +213,10 @@ void WorldEditor::_bind_methods()
&WorldEditor::world_exited);
ClassDB::bind_method(D_METHOD("world_command_result", "what", "data"),
&WorldEditor::world_command_result);
ClassDB::bind_method(D_METHOD("set_camera_mode", "mode"),
&WorldEditor::set_camera_mode);
ClassDB::bind_method(D_METHOD("get_camera_mode"),
&WorldEditor::get_camera_mode);
ADD_SIGNAL(MethodInfo("editor_event",
PropertyInfo(Variant::STRING, "event_name"),
PropertyInfo(Variant::ARRAY, "args")));

View File

@@ -7,6 +7,8 @@ class WorldEditor : public Spatial {
protected:
StreamWorld *stream_world;
Control *editor_menu;
void set_camera_mode(int mode);
int get_camera_mode() const;
void disable_all();
void mode_buildings();
void mode_navigation();
@@ -24,6 +26,7 @@ protected:
private:
void world_exited();
int current_mode;
int current_camera_mode;
public:
WorldEditor();