Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tilemap live editing while game is running #83146

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions core/object/undo_redo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ bool UndoRedo::_redo(bool p_execute) {
}

current_action++;
if (p_execute) {
_process_operation_list(actions.write[current_action].do_ops.front());
}
_process_operation_list(actions.write[current_action].do_ops.front(), p_execute);
version++;
emit_signal(SNAME("version_changed"));

Expand Down Expand Up @@ -321,7 +319,7 @@ void UndoRedo::commit_action(bool p_execute) {
}
}

void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
void UndoRedo::_process_operation_list(List<Operation>::Element *E, bool p_execute) {
const int PREALLOCATE_ARGS_COUNT = 16;

LocalVector<const Variant *> args;
Expand All @@ -337,18 +335,20 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {

switch (op.type) {
case Operation::TYPE_METHOD: {
groud marked this conversation as resolved.
Show resolved Hide resolved
Callable::CallError ce;
Variant ret;
op.callable.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT("Error calling UndoRedo method operation '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, nullptr, 0, ce));
}
if (p_execute) {
Callable::CallError ce;
Variant ret;
op.callable.callp(nullptr, 0, ret, ce);
if (ce.error != Callable::CallError::CALL_OK) {
ERR_PRINT("Error calling UndoRedo method operation '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, nullptr, 0, ce));
}
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
if (res) {
res->set_edited(true);
}
Resource *res = Object::cast_to<Resource>(obj);
if (res) {
res->set_edited(true);
}
#endif
}

if (method_callback) {
Vector<Variant> binds;
Expand All @@ -373,13 +373,16 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
} break;
case Operation::TYPE_PROPERTY: {
obj->set(op.name, op.value);
if (p_execute) {
obj->set(op.name, op.value);
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
if (res) {
res->set_edited(true);
}
Resource *res = Object::cast_to<Resource>(obj);
if (res) {
res->set_edited(true);
}
#endif
}

if (property_callback) {
property_callback(prop_callback_ud, obj, op.name, op.value);
}
Expand All @@ -400,7 +403,7 @@ bool UndoRedo::undo() {
if (current_action < 0) {
return false; //nothing to redo
}
_process_operation_list(actions.write[current_action].undo_ops.front());
_process_operation_list(actions.write[current_action].undo_ops.front(), true);
current_action--;
version--;
emit_signal(SNAME("version_changed"));
Expand Down
2 changes: 1 addition & 1 deletion core/object/undo_redo.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UndoRedo : public Object {
uint64_t version = 1;

void _pop_history_tail();
void _process_operation_list(List<Operation>::Element *E);
void _process_operation_list(List<Operation>::Element *E, bool p_execute);
void _discard_redo();
bool _redo(bool p_execute);

Expand Down