Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d66b175

Browse files
committedOct 15, 2023
Fix tilemap live editing while game is running
1 parent 918f046 commit d66b175

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed
 

‎core/object/undo_redo.cpp

+23-20
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ bool UndoRedo::_redo(bool p_execute) {
7171
}
7272

7373
current_action++;
74-
if (p_execute) {
75-
_process_operation_list(actions.write[current_action].do_ops.front());
76-
}
74+
_process_operation_list(actions.write[current_action].do_ops.front(), p_execute);
7775
version++;
7876
emit_signal(SNAME("version_changed"));
7977

@@ -321,7 +319,7 @@ void UndoRedo::commit_action(bool p_execute) {
321319
}
322320
}
323321

324-
void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
322+
void UndoRedo::_process_operation_list(List<Operation>::Element *E, bool p_execute) {
325323
const int PREALLOCATE_ARGS_COUNT = 16;
326324

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

338336
switch (op.type) {
339337
case Operation::TYPE_METHOD: {
340-
Callable::CallError ce;
341-
Variant ret;
342-
op.callable.callp(nullptr, 0, ret, ce);
343-
if (ce.error != Callable::CallError::CALL_OK) {
344-
ERR_PRINT("Error calling UndoRedo method operation '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, nullptr, 0, ce));
345-
}
338+
if (p_execute) {
339+
Callable::CallError ce;
340+
Variant ret;
341+
op.callable.callp(nullptr, 0, ret, ce);
342+
if (ce.error != Callable::CallError::CALL_OK) {
343+
ERR_PRINT("Error calling UndoRedo method operation '" + String(op.name) + "': " + Variant::get_call_error_text(obj, op.name, nullptr, 0, ce));
344+
}
346345
#ifdef TOOLS_ENABLED
347-
Resource *res = Object::cast_to<Resource>(obj);
348-
if (res) {
349-
res->set_edited(true);
350-
}
346+
Resource *res = Object::cast_to<Resource>(obj);
347+
if (res) {
348+
res->set_edited(true);
349+
}
351350
#endif
351+
}
352352

353353
if (method_callback) {
354354
Vector<Variant> binds;
@@ -373,13 +373,16 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
373373
}
374374
} break;
375375
case Operation::TYPE_PROPERTY: {
376-
obj->set(op.name, op.value);
376+
if (p_execute) {
377+
obj->set(op.name, op.value);
377378
#ifdef TOOLS_ENABLED
378-
Resource *res = Object::cast_to<Resource>(obj);
379-
if (res) {
380-
res->set_edited(true);
381-
}
379+
Resource *res = Object::cast_to<Resource>(obj);
380+
if (res) {
381+
res->set_edited(true);
382+
}
382383
#endif
384+
}
385+
383386
if (property_callback) {
384387
property_callback(prop_callback_ud, obj, op.name, op.value);
385388
}
@@ -400,7 +403,7 @@ bool UndoRedo::undo() {
400403
if (current_action < 0) {
401404
return false; //nothing to redo
402405
}
403-
_process_operation_list(actions.write[current_action].undo_ops.front());
406+
_process_operation_list(actions.write[current_action].undo_ops.front(), true);
404407
current_action--;
405408
version--;
406409
emit_signal(SNAME("version_changed"));

‎core/object/undo_redo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class UndoRedo : public Object {
8585
uint64_t version = 1;
8686

8787
void _pop_history_tail();
88-
void _process_operation_list(List<Operation>::Element *E);
88+
void _process_operation_list(List<Operation>::Element *E, bool p_execute);
8989
void _discard_redo();
9090
bool _redo(bool p_execute);
9191

0 commit comments

Comments
 (0)
Please sign in to comment.