Refactor behaviors functions to a single function called applyBehaviors

This commit is contained in:
Siklos 2022-08-18 10:15:12 +02:00
parent f34ba64f7e
commit e831f95d20
2 changed files with 25 additions and 12 deletions

View file

@ -0,0 +1,21 @@
import { IContainerModel } from '../../../Interfaces/IContainerModel';
import { ImposePosition } from './AnchorBehaviors';
import { RecalculatePhysics } from './RigidBodyBehaviors';
/**
* Recalculate the position of the container and its neighbors
* Mutate and returns the updated container
* @param container Container to recalculate its positions
* @returns Updated container
*/
export function applyBehaviors(container: IContainerModel): IContainerModel {
if (container.properties.isAnchor) {
ImposePosition(container);
}
if (container.properties.isRigidBody) {
RecalculatePhysics(container);
}
return container;
}

View file

@ -3,9 +3,8 @@ import { IContainerModel, ContainerModel } from '../../Interfaces/IContainerMode
import { IHistoryState } from '../../Interfaces/IHistoryState'; import { IHistoryState } from '../../Interfaces/IHistoryState';
import { findContainerById } from '../../utils/itertools'; import { findContainerById } from '../../utils/itertools';
import { getCurrentHistory } from './Editor'; import { getCurrentHistory } from './Editor';
import { RecalculatePhysics } from './Behaviors/RigidBodyBehaviors';
import { ImposePosition } from './Behaviors/AnchorBehaviors';
import { restoreX } from '../SVG/Elements/Container'; import { restoreX } from '../SVG/Elements/Container';
import { applyBehaviors } from './Behaviors/Behaviors';
/** /**
* Handled the property change event in the properties form * Handled the property change event in the properties form
@ -43,13 +42,7 @@ export function OnPropertyChange(
(container.properties as any)[key] = value; (container.properties as any)[key] = value;
} }
if (container.properties.isAnchor) { applyBehaviors(container);
ImposePosition(container);
}
if (container.properties.isRigidBody) {
RecalculatePhysics(container);
}
history.push({ history.push({
LastAction: `Change ${key} of ${container.properties.id}`, LastAction: `Change ${key} of ${container.properties.id}`,
@ -116,9 +109,8 @@ export function OnPropertiesSubmit(
submitCSSForm(form, styleProperty, container); submitCSSForm(form, styleProperty, container);
} }
if (container.properties.isRigidBody) { // Apply the behaviors
RecalculatePhysics(container); applyBehaviors(container);
}
history.push({ history.push({
LastAction: `Change properties of ${container.properties.id}`, LastAction: `Change properties of ${container.properties.id}`,