fix: edit history ignores preview data

This commit is contained in:
Sara Gerretsen 2025-12-13 16:07:51 +01:00
parent 656917f6fc
commit cd730ac8d4
3 changed files with 15 additions and 9 deletions

View file

@ -14,7 +14,9 @@ void PointPrimitiveNode::on_underlying_changed() {
if (!this->pushing_change && this->is_inside_tree()) {
this->pushing_change = true;
Vector2 const center{ this->primitive->get_center() };
set_global_position({ center.x, this->primitive->get_height(), center.y });
Vector3 global_position{ center.x, this->primitive->get_height(), center.y };
set_global_position(global_position);
this->last_pushed_position = global_position;
this->pushing_change = false;
}
}
@ -42,7 +44,6 @@ void PointPrimitiveNode::preview_transform_changes() {
if (position.y != this->primitive->get_height()) {
this->primitive->set_height(position.y);
}
this->pushing_change = false;
}
}
@ -52,16 +53,18 @@ void PointPrimitiveNode::push_transform_changes() {
this->pushing_change = true;
Vector3 const position{ get_global_position() };
Vector2 const center{ position.x, position.z };
if (center != this->primitive->get_center()) {
Vector2 last_pushed_center{ this->last_pushed_position.x, last_pushed_position.z };
if (center != last_pushed_center) {
EditHistory::get_singleton()->push_action(
callable_mp(*this->primitive, &PointPrimitive::set_center).bind(center),
callable_mp(*this->primitive, &PointPrimitive::set_center).bind(this->primitive->get_center()));
callable_mp(*this->primitive, &PointPrimitive::set_center).bind(last_pushed_center));
}
if (position.y != this->primitive->get_height()) {
if (position.y != this->last_pushed_position.y) {
EditHistory::get_singleton()->push_action(
callable_mp(*this->primitive, &PointPrimitive::set_height).bind(position.y),
callable_mp(*this->primitive, &PointPrimitive::set_height).bind(this->primitive->get_height()));
callable_mp(*this->primitive, &PointPrimitive::set_height).bind(this->last_pushed_position.y));
}
this->last_pushed_position = position;
this->pushing_change = false;
}
}

View file

@ -18,6 +18,7 @@ public:
Ref<PointPrimitive> get_primitive() const;
private:
Vector3 last_pushed_position{};
bool pushing_change{ false };
Ref<PointPrimitive> primitive{};
Callable underlying_changed_callable{ callable_mp(this, &self_type::on_underlying_changed) };

View file

@ -47,6 +47,7 @@ script/source = "extends Area3D
var dragged : bool = false
var slope_adjusted : float = 0.0
var slope_pre_adjusted : float = 0.0
var refresh_time : float
@onready
var parent = get_parent() as PointPrimitiveNode
@ -65,8 +66,8 @@ func _input(event: InputEvent) -> void:
dragged = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
EditHistory.push_action(
$\"..\".get_primitive().set.bind(\"slope\", slope_adjusted),
$\"..\".get_primitive().set.bind(\"slope\", $\"..\".get_primitive().slope)
parent.get_primitive().set.bind(\"slope\", slope_adjusted),
parent.get_primitive().set.bind(\"slope\", slope_pre_adjusted)
)
get_viewport().set_input_as_handled()
elif event is InputEventMouseMotion:
@ -78,7 +79,8 @@ func _input_event(_camera: Camera3D, event: InputEvent, _event_position: Vector3
if not dragged and event is InputEventMouseButton and (event as InputEventMouseButton).is_pressed():
get_viewport().set_input_as_handled()
dragged = true
slope_adjusted = $\"..\".get_primitive().slope
slope_adjusted = parent.get_primitive().slope
slope_pre_adjusted = slope_adjusted
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
"