-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce32859
commit 525fb54
Showing
20 changed files
with
248 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export interface FTransformOptions { | ||
position?: { x: number, y: number } | ||
scale?: { x: number, y: number } | ||
rotation?: number | ||
rotationDegree?: number | ||
} | ||
|
||
/** | ||
* @description 2D Transforms for a component. | ||
* @category Core | ||
*/ | ||
export class FTransform { | ||
/** | ||
* Position of the component. | ||
*/ | ||
position: { x: number, y: number } | ||
/** | ||
* Scale of the component. | ||
*/ | ||
scale: { x: number, y: number } | ||
/** | ||
* Rotation of the component. | ||
*/ | ||
rotation: number | ||
|
||
/** | ||
* @description Create a new FTransform. | ||
* @param options The options for the collider. | ||
* @param options.position The position of the collider. If not defined, it will default to `{ x: 0, y: 5 }`. | ||
* @param options.scale The scale of the collider. If not defined, it will default to `{ x: 1, y: 1 }`. | ||
* @param options.rotation The rotation of the collider. If not defined, it will default to 0. | ||
* @param options.rotationDegree The rotation of the collider in degrees. If not defined, it will default to undefined. | ||
* @example | ||
* ```ts | ||
* const collider = new FTransform({ | ||
* position: { x: 0, y: 0 }, | ||
* scale: { x: 1, y: 1 }, | ||
* rotation: 0, | ||
* }) | ||
* ``` | ||
*/ | ||
constructor(options?: FTransformOptions) { | ||
// Define default options | ||
const DEFAULT_OPTIONS = { | ||
position: { x: 0, y: 5 }, | ||
scale: { x: 1, y: 1 }, | ||
rotation: 0, | ||
} | ||
// Apply default options | ||
options = { ...DEFAULT_OPTIONS, ...options } | ||
// Validate options | ||
if (!options.position || !options.scale || (options.rotation === undefined && options.rotationDegree === undefined)) | ||
throw new Error('FibboError: FComponent requires position, scale and rotation options') | ||
|
||
// Set the transform values | ||
this.position = options.position | ||
this.scale = options.scale | ||
this.rotation = options.rotationDegree ? options.rotationDegree * (Math.PI / 180) : options.rotation ?? 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.