Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Sep 13, 2024
1 parent d9e79c5 commit 24ea437
Show file tree
Hide file tree
Showing 2 changed files with 692 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @flow
import { mapFor } from '../../Utils/MapFor';

const gd: libGDevelop = global.gd;

// - The term "object" is used in comments about the layout declaration because
Expand Down Expand Up @@ -59,12 +57,16 @@ export interface PropertiesContainer {
*/
export const getObjectAnchor = (
eventBasedObject: gdEventsBasedObject,
customObjectConfiguration: PropertiesContainer,
objectName: string
): ObjectAnchor => {
const childObject = eventBasedObject.getObjects().getObject(objectName);
if (!childObject.hasBehaviorNamed('Anchor')) {
return null;
return {
leftEdgeAnchor: gd.CustomObjectConfiguration.NoAnchor,
topEdgeAnchor: gd.CustomObjectConfiguration.NoAnchor,
rightEdgeAnchor: gd.CustomObjectConfiguration.NoAnchor,
bottomEdgeAnchor: gd.CustomObjectConfiguration.NoAnchor,
};
}
const properties = childObject.getBehavior('Anchor').getProperties();
const leftEdgeAnchor = getPropertyValue(properties, 'leftEdgeAnchor');
Expand Down Expand Up @@ -275,7 +277,6 @@ export interface LayoutedParent<
CovariantChildRenderedInstance: ChildRenderedInstance
> {
eventBasedObject: gdEventsBasedObject | null;
_associatedObjectConfiguration: gdObjectConfiguration;
getWidth(): number;
getHeight(): number;
getRendererOfInstance: (
Expand All @@ -292,9 +293,6 @@ export const getLayoutedRenderedInstance = <T: ChildRenderedInstance>(
if (!eventBasedObject) {
return null;
}
const customObjectConfiguration = gd.asCustomObjectConfiguration(
parent._associatedObjectConfiguration
);

const layoutedInstance = parent.getLayoutedInstance(initialInstance);
const renderedInstance = parent.getRendererOfInstance(
Expand All @@ -303,7 +301,6 @@ export const getLayoutedRenderedInstance = <T: ChildRenderedInstance>(

const objectAnchor = getObjectAnchor(
eventBasedObject,
customObjectConfiguration,
layoutedInstance.getObjectName()
);
const leftEdgeAnchor = objectAnchor
Expand Down Expand Up @@ -415,7 +412,7 @@ export const getLayoutedRenderedInstance = <T: ChildRenderedInstance>(
} else {
const parentInitialCenterY = (parentInitialMaxY + parentInitialMinY) / 2;

const parentMinY = parentInitialMinY * parentScaleX;
const parentMinY = parentInitialMinY * parentScaleY;
const parentMaxY = parentInitialMaxY * parentScaleY;
const parentCenterY = (parentMaxY + parentMinY) / 2;

Expand Down
Loading

0 comments on commit 24ea437

Please sign in to comment.