Files
GDevelop/GDJS/Runtime/object-capabilities/ResizableBehavior.ts
D8H deb802cfec Allow to override behavior properties on object instances (#8171)
* For now, this is limited to instances inside custom objects. This will be made available in the future for all instances in scenes if this works well.
2026-02-09 16:21:24 +01:00

106 lines
2.5 KiB
TypeScript

/*
* GDevelop JS Platform
* Copyright 2013-2023 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
namespace gdjs {
/** @category Behaviors > Default behaviors */
export interface Resizable {
/**
* Change the width of the object. This changes the scale on X axis of the object.
*
* @param newWidth The new width of the object, in pixels.
*/
setWidth(newWidth: float): void;
/**
* Change the height of the object. This changes the scale on Y axis of the object.
*
* @param newHeight The new height of the object, in pixels.
*/
setHeight(newHeight: float): void;
/**
* Change the size of the object.
*
* @param newWidth The new width of the object, in pixels.
* @param newHeight The new height of the object, in pixels.
*/
setSize(newWidth: float, newHeight: float): void;
/**
* Return the width of the object.
* @return The width of the object
*/
getWidth(): float;
/**
* Return the width of the object.
* @return The height of the object
*/
getHeight(): float;
}
/**
* A behavior that forwards the Resizable interface to its object.
* @category Behaviors > Default behaviors
*/
export class ResizableBehavior
extends gdjs.RuntimeBehavior
implements Resizable
{
private object: gdjs.RuntimeObject & Resizable;
constructor(
instanceContainer: gdjs.RuntimeInstanceContainer,
behaviorData,
owner: gdjs.RuntimeObject & Resizable
) {
super(instanceContainer, behaviorData, owner);
this.object = owner;
}
usesLifecycleFunction(): boolean {
return false;
}
override applyBehaviorOverriding(behaviorData): boolean {
// Nothing to update.
return true;
}
onDeActivate() {}
onDestroy() {}
doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
setWidth(newWidth: float): void {
this.object.setWidth(newWidth);
}
setHeight(newHeight: float): void {
this.object.setHeight(newHeight);
}
setSize(newWidth: float, newHeight: float): void {
this.object.setSize(newWidth, newHeight);
}
getWidth(): float {
return this.object.getWidth();
}
getHeight(): float {
return this.object.getHeight();
}
}
gdjs.registerBehavior(
'ResizableCapability::ResizableBehavior',
gdjs.ResizableBehavior
);
}