import { MathEx } from "../math/MathEx" ; import { Debug } from "../io/Debug" ; import { ExecutionStatus } from "./ExecutionStatus" ; import { Vector3 } from "../math/Vector3" ; import { Matrix44 } from "../math/Matrix44" ; import { Quaternion } from "../math/Quaternion" ; import { Color } from "../graphics/Color" ; import { Ray , RaySphereCollisionResult } from "../math/Ray" ; import { Basis } from "../math/Basis" ; import { Plane } from "../math/Plane" ; import { HudControl , EngineHud } from "../core/hud/EngineHud" ; import { RaycastResult } from "../collision/RaycastResult" ; import { SavedData } from "../io/SavedData" ; import { Time } from "../core/Time" ; import { Project } from "../core/Project" ; import { Gamepads } from "../input/Gamepads" ; import { Entities , EntityProps } from "../core/Entities" ; import { Scenes } from "../core/Scenes" ; import { Assets } from "../assets/Assets" ; import { Physics } from "../physics/Physics" ; import { Interfaces } from "../core/Interfaces" ; import { Config } from "../core/Config" ; import { Update } from "../core/Update" ; import { Scene } from "../assets/Scene" ; import { Asset } from "../assets/Asset" ; import { Vector2 } from "../math/Vector2" ; import { Entity } from "../core/Entity" ; import { VoidSyncEvent } from "ts-events" ; import { Random } from "../math/Random" ; import { Input } from "../input/Input" ; import { CollisionFilter } from "../collision/CollisionFilter" ; import { VertexBuffer } from "../graphics/VertexBuffer" ; import { AABB } from "../math/AABB" ; import { IHttpRequestOptions , Http } from "../network/HTTP" ; import { RotationOrder } from "../math/Types" ; namespace Private { export const transientState = { } ; } export class BehaviorAPI { static api = { Math : { PI : ( ) => Math . PI , sin : ( angleRadians ) => Math . sin ( angleRadians ) , cos : ( angleRadians ) => Math . cos ( angleRadians ) , tan : ( angleRadians ) => Math . tan ( angleRadians ) , sqrt : ( value ) => Math . sqrt ( value ) , min : ( a , b ) => Math . min ( a , b ) , max : ( a , b ) => Math . max ( a , b ) , random : ( ) => Math . random ( ) , abs : ( value ) => Math . abs ( value ) , sign : ( value ) => Math . sign ( value ) , floor : ( value ) => Math . floor ( value ) , ceil : ( value ) => Math . ceil ( value ) , round : ( value ) => Math . round ( value ) , acos : ( value ) => Math . acos ( value ) , atan : ( value ) => Math . atan ( value ) , atan2 : ( y , x ) => Math . atan2 ( y , x ) , pow : ( base , exponent ) => Math . pow ( base , exponent ) , exp : ( value ) => Math . exp ( value ) , log : ( value ) => Math . log ( value ) } , MathEx : { toRadians : ( angleDegrees ) => MathEx . toRadians ( angleDegrees ) , toDegrees : ( angleRadians ) => MathEx . toDegrees ( angleRadians ) , clamp : ( value , min , max ) => MathEx . clamp ( value , min , max ) , degreesToRadians : ( ) => MathEx . degreesToRadians , radiansToDegrees : ( ) => MathEx . radiansToDegrees , lerp : ( a , b , k ) => MathEx . lerp ( a , b , k ) } , console : { log : ( ... args ) => Debug . log ( args ) , assert : ( value , message ? ) => console . assert ( value , message ) , clear : ( ) => console . clear ( ) , logVector3 : ( value ) => Debug . logVector3 ( value ) } , location : { reload : ( ) => location . reload ( ) } , window : { open : ( url ) => window . open ( url ) } , JSON : { stringify : ( obj ) => JSON . stringify ( obj , null , 2 ) , parse : ( str ) => JSON . parse ( str ) } , Random : { range : ( rangeStart , rangeEnd ) => Random . range ( rangeStart , rangeEnd ) , rangeInt : ( rangeStart , rangeEnd ) => Random . rangeInt ( rangeStart , rangeEnd ) } , Scenes : { load : ( path , additive ? ) : Promise < Scene > => Scenes . load ( path , additive ) } , Assets : { load : ( path ) : Promise < Asset > => Assets . load ( path ) , loadById : ( id ) : Promise < Asset > => Assets . loadById ( id ) } , Renderer : { screenSize : ( ) : Vector2 => Interfaces . renderer . screenSize } , Entities : { create : ( props ? ) : Entity => Entities . create ( props ) , find : ( name ) : Entity | null => Entities . find ( name ) } , Gamepads : { forEach : ( handler ) => Gamepads . forEach ( handler ) , get : ( index ) => Gamepads . get ( index ) } , Input : { touchX : ( ) => Input . touchX , touchY : ( ) => Input . touchY , touchPressed : ( ) => Input . touchPressed , touchMoved : ( ) => Input . touchMoved , touchReleased : ( ) => Input . touchReleased , wheelMoved : ( ) => Input . wheelMoved , keyChanged : ( ) => Input . keyChanged } , Time : { deltaTime : ( ) => Time . deltaTime , smoothDeltaTime : ( ) => Time . smoothDeltaTime , fps : ( ) => Time . fps , currentFrame : ( ) => Time . currentFrame , time : ( ) => Time . time } , Project : { name : ( ) => Project . projectName , isOpenSource : ( ) => Project . isOpenSource , importToEditor : ( ) => Project . importToEditor ( ) } , SavedData : { get : ( ) => SavedData . get ( ) , flush : ( ) => SavedData . flush ( ) } , Update : { hook : ( ) : VoidSyncEvent => Update . hook } , Game : { state : ( ) => Private . transientState } , ExecutionStatus : { Continue : ( ) => ExecutionStatus . Continue , Finish : ( ) => ExecutionStatus . Finish } , Vector3 : { up : ( ) => Vector3 . fromPool ( ) . copy ( Vector3 . up ) , right : ( ) => Vector3 . fromPool ( ) . copy ( Vector3 . right ) , forward : ( ) => Vector3 . fromPool ( ) . copy ( Vector3 . forward ) , zero : ( ) => Vector3 . fromPool ( ) . copy ( Vector3 . zero ) , one : ( ) => Vector3 . fromPool ( ) . copy ( Vector3 . one ) , distance : ( a , b ) => Vector3 . distance ( a , b ) , distanceSq : ( a , b ) => Vector3 . distanceSq ( a , b ) , fromPool : ( ) => Vector3 . fromPool ( ) } , Vector2 : { zero : ( ) => Vector2 . fromPool ( ) . copy ( Vector2 . zero ) , one : ( ) => Vector2 . fromPool ( ) . copy ( Vector2 . one ) , fromPool : ( ) => Vector2 . fromPool ( ) } , Plane : { fromPool : ( ) => Plane . fromPool ( ) } , Basis : { fromMatrix : ( m ) => Basis . fromMatrix ( m ) } , Matrix44 : { identity : ( ) => Matrix44 . fromPool ( ) . copy ( Matrix44 . identity ) , fromPool : ( ) => Matrix44 . fromPool ( ) } , Quaternion : { identity : ( ) => Quaternion . fromPool ( ) . copy ( Quaternion . identity ) , fromPool : ( ) => Quaternion . fromPool ( ) , fromEulerAngles : ( x , y , z , order ? ) => Quaternion . fromEulerAngles ( x , y , z , order ) , fromAxisAngle : ( axis , angle ) => Quaternion . fromAxisAngle ( axis , angle ) } , Color : { white : ( ) => Color . dummy . copy ( Color . white ) , black : ( ) => Color . dummy . copy ( Color . black ) } , Object : { keys : ( obj ) => Object . keys ( obj ) , values : ( obj ) => Object . values ( obj ) , entries : ( obj ) => Object . entries ( obj ) , assign : ( target , ... sources ) => Object . assign ( target , sources ) } , Promise : { all : ( promises ) => Promise . all ( promises ) } , HorizontalAlignment : { Left : ( ) => 0 , Center : ( ) => 1 , Right : ( ) => 2 , Stretch : ( ) => 3 } , VerticalAlignment : { Top : ( ) => 0 , Center : ( ) => 1 , Bottom : ( ) => 2 , Stretch : ( ) => 3 } , Array : { isArray : ( a ) => Array . isArray ( a ) , from : ( a ) => Array . from ( a ) } , Physics : { rayCast : ( ray , filter ? ) : RaycastResult | null => ( Physics . rayCast ( ray , filter ) ) } , Collision : { rayCastOnSphere : ( ray , center , radius ) : RaySphereCollisionResult | null => ( ray . castOnSphere ( center , radius ) ) } , EngineHud : { setControls : ( controls ) => EngineHud . setControls ( controls ) } , AABB : { fromVertexBuffer : ( vb ) => AABB . fromVertexBuffer ( vb ) } , Config : { isWeb : ( ) => Config . isWeb ( ) , isDesktop : ( ) => Config . isDesktop ( ) , isProduction : ( ) => Config . isProduction ( ) , isDevelopment : ( ) => Config . isDevelopment ( ) , isEditor : ( ) => Config . isEditor ( ) , isStandalone : ( ) => Config . isStandalone ( ) } , Http : { request : ( options ) => Http . request ( options ) } , Date : { now : ( ) => Date . now ( ) } } ; }