hytopia 0.1.27 → 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. package/bin/scripts.js +1 -0
  2. package/docs/server.basecharactercontroller.md +5 -5
  3. package/docs/server.basecharactercontroller.ontick.md +13 -0
  4. package/docs/server.basecharactercontroller.tick.md +53 -0
  5. package/docs/server.blocktype.md +2 -2
  6. package/docs/server.blocktype.onentitycollision.md +1 -1
  7. package/docs/server.blocktype.onentitycontactforce.md +1 -1
  8. package/docs/server.defaultcharactercontroller.canjump.md +1 -1
  9. package/docs/server.defaultcharactercontroller.canrun.md +1 -1
  10. package/docs/server.defaultcharactercontroller.canwalk.md +1 -1
  11. package/docs/server.defaultcharactercontroller.md +3 -17
  12. package/docs/server.entity.createcustomcharactercontroller.md +2 -2
  13. package/docs/server.entity.md +9 -9
  14. package/docs/server.entity.onblockcollision.md +1 -1
  15. package/docs/server.entity.onblockcontactforce.md +1 -1
  16. package/docs/server.entity.ondespawn.md +1 -1
  17. package/docs/server.entity.onentitycollision.md +1 -1
  18. package/docs/server.entity.onentitycontactforce.md +1 -1
  19. package/docs/server.entity.onspawn.md +1 -1
  20. package/docs/server.entity.ontick.md +1 -1
  21. package/docs/server.entityoptions.createcustomcharactercontroller.md +13 -0
  22. package/docs/server.entityoptions.md +19 -0
  23. package/docs/server.facecallback.md +15 -0
  24. package/docs/server.facecompletecallback.md +15 -0
  25. package/docs/server.faceoptions.md +18 -0
  26. package/docs/server.hytopia.basecharactercontroller.md +5 -5
  27. package/docs/server.hytopia.basecharactercontroller.ontick.md +13 -0
  28. package/docs/server.hytopia.basecharactercontroller.tick.md +53 -0
  29. package/docs/server.hytopia.blocktype.md +2 -2
  30. package/docs/server.hytopia.blocktype.onentitycollision.md +1 -1
  31. package/docs/server.hytopia.blocktype.onentitycontactforce.md +1 -1
  32. package/docs/server.hytopia.defaultcharactercontroller.canjump.md +1 -1
  33. package/docs/server.hytopia.defaultcharactercontroller.canrun.md +1 -1
  34. package/docs/server.hytopia.defaultcharactercontroller.canwalk.md +1 -1
  35. package/docs/server.hytopia.defaultcharactercontroller.md +3 -17
  36. package/docs/server.hytopia.entity.createcustomcharactercontroller.md +2 -2
  37. package/docs/server.hytopia.entity.md +9 -9
  38. package/docs/server.hytopia.entity.onblockcollision.md +1 -1
  39. package/docs/server.hytopia.entity.onblockcontactforce.md +1 -1
  40. package/docs/server.hytopia.entity.ondespawn.md +1 -1
  41. package/docs/server.hytopia.entity.onentitycollision.md +1 -1
  42. package/docs/server.hytopia.entity.onentitycontactforce.md +1 -1
  43. package/docs/server.hytopia.entity.onspawn.md +1 -1
  44. package/docs/server.hytopia.entity.ontick.md +1 -1
  45. package/docs/server.hytopia.entityoptions.createcustomcharactercontroller.md +13 -0
  46. package/docs/server.hytopia.entityoptions.md +19 -0
  47. package/docs/server.hytopia.facecallback.md +15 -0
  48. package/docs/server.hytopia.facecompletecallback.md +15 -0
  49. package/docs/server.hytopia.faceoptions.md +18 -0
  50. package/docs/server.hytopia.md +77 -0
  51. package/docs/server.hytopia.movecallback.md +15 -0
  52. package/docs/server.hytopia.movecompletecallback.md +15 -0
  53. package/docs/server.hytopia.moveoptions.md +23 -0
  54. package/docs/server.hytopia.simplecharactercontroller.face.md +89 -0
  55. package/docs/server.hytopia.simplecharactercontroller.md +88 -0
  56. package/docs/server.hytopia.simplecharactercontroller.move.md +89 -0
  57. package/docs/server.md +77 -0
  58. package/docs/server.movecallback.md +15 -0
  59. package/docs/server.movecompletecallback.md +15 -0
  60. package/docs/server.moveoptions.md +23 -0
  61. package/docs/server.simplecharactercontroller.face.md +89 -0
  62. package/docs/server.simplecharactercontroller.md +88 -0
  63. package/docs/server.simplecharactercontroller.move.md +89 -0
  64. package/examples/entity-spawn/index.ts +1 -1
  65. package/examples/payload-game/index.ts +46 -104
  66. package/package.json +1 -1
  67. package/server.api.json +1048 -264
  68. package/server.d.ts +191 -51
  69. package/server.js +57 -57
  70. package/tsconfig.json +4 -1
  71. package/docs/server.basecharactercontroller.ontickpathfindingmovement.md +0 -13
  72. package/docs/server.basecharactercontroller.tickpathfindingmovement.md +0 -69
  73. package/docs/server.defaultcharactercontroller.tickpathfindingmovement.md +0 -69
  74. package/docs/server.hytopia.basecharactercontroller.ontickpathfindingmovement.md +0 -13
  75. package/docs/server.hytopia.basecharactercontroller.tickpathfindingmovement.md +0 -69
  76. package/docs/server.hytopia.defaultcharactercontroller.tickpathfindingmovement.md +0 -69
  77. package/examples/character-controller/tsconfig.json +0 -27
  78. package/examples/entity-spawn/tsconfig.json +0 -27
  79. package/examples/payload-game/tsconfig.json +0 -27
package/server.d.ts CHANGED
@@ -290,6 +290,11 @@ export declare interface AudioOptions {
290
290
  export declare abstract class BaseCharacterController {
291
291
  /** The entity the controller is for. */
292
292
  readonly entity: Entity;
293
+ /**
294
+ * A callback function for when the controller ticks.
295
+ * @param deltaTimeMs - The delta time in milliseconds since the last tick.
296
+ */
297
+ onTick?: (deltaTimeMs: number) => void;
293
298
  /**
294
299
  * A callback function for when the controller ticks
295
300
  * player movement.
@@ -298,13 +303,6 @@ export declare abstract class BaseCharacterController {
298
303
  * @param deltaTimeMs - The delta time in milliseconds since the last tick.
299
304
  */
300
305
  onTickPlayerMovement?: (inputState: PlayerInputState, orientationState: PlayerOrientationState, deltaTimeMs: number) => void;
301
- /**
302
- * A callback function for when the controller ticks
303
- * pathfinding movement.
304
- * @param destination - The destination to move to.
305
- * @param deltaTimeMs - The delta time in milliseconds since the last tick.
306
- */
307
- onTickPathfindingMovement?: (destination: Vector3, deltaTimeMs: number) => void;
308
306
  /**
309
307
  * @param entity - The entity the controller is for.
310
308
  * @param _options - Arbitrary options you may provide or omit for your controller implementation.
@@ -325,13 +323,11 @@ export declare abstract class BaseCharacterController {
325
323
  */
326
324
  tickPlayerMovement(inputState: PlayerInputState, orientationState: PlayerOrientationState, deltaTimeMs: number): void;
327
325
  /**
328
- * Override this method to implement pathfinding
329
- * movement logic for your character controller.
330
- * NOTE: This method is not fully supported yet.
331
- * @param destination - The destination target to move to.
326
+ * Override this method to handle entity movements
327
+ * based on your character controller.
332
328
  * @param deltaTimeMs - The delta time in milliseconds since the last tick.
333
329
  */
334
- tickPathfindingMovement(destination: Vector3, deltaTimeMs: number): void;
330
+ tick(deltaTimeMs: number): void;
335
331
  }
336
332
 
337
333
  /**
@@ -382,16 +378,18 @@ export declare class Block {
382
378
  export declare class BlockType implements protocol.Serializable {
383
379
  /**
384
380
  * A callback function that is invoked when an entity collides with blocks of this type.
385
- * @param entity - The entity that collided with the block.
381
+ * @param blockType - The block type the collision is for.
382
+ * @param entity - The entity that collided with the block type.
386
383
  * @param started - Whether the collision started.
387
384
  */
388
- onEntityCollision?: (this: BlockType, entity: Entity, started: boolean) => void;
385
+ onEntityCollision?: (blockType: BlockType, entity: Entity, started: boolean) => void;
389
386
  /**
390
387
  * A callback function that is invoked when an entity contacts a block of this type.
391
- * @param entity - The entity that contacted the block.
388
+ * @param blockType - The block type the contact is for.
389
+ * @param entity - The entity that contacted the block type.
392
390
  * @param contactForceData - The contact force data.
393
391
  */
394
- onEntityContactForce?: (this: BlockType, entity: Entity, contactForceData: ContactForceData) => void;
392
+ onEntityContactForce?: (blockType: BlockType, entity: Entity, contactForceData: ContactForceData) => void;
395
393
 
396
394
 
397
395
 
@@ -1104,22 +1102,22 @@ export declare class DefaultCharacterController extends BaseCharacterController
1104
1102
  walkVelocity: number;
1105
1103
  /**
1106
1104
  * A function allowing custom logic to determine if the entity can walk.
1107
- * @param this - The character controller instance.
1108
- * @returns Whether the entity can walk.
1105
+ * @param defaultCharacterController - The character controller instance.
1106
+ * @returns Whether the entity of the character controller can walk.
1109
1107
  */
1110
- canWalk: (this: DefaultCharacterController) => boolean;
1108
+ canWalk: (defaultCharacterController: DefaultCharacterController) => boolean;
1111
1109
  /**
1112
1110
  * A function allowing custom logic to determine if the entity can run.
1113
- * @param this - The character controller instance.
1114
- * @returns Whether the entity can run.
1111
+ * @param defaultCharacterController - The character controller instance.
1112
+ * @returns Whether the entity of the character controller can run.
1115
1113
  */
1116
- canRun: (this: DefaultCharacterController) => boolean;
1114
+ canRun: (defaultCharacterController: DefaultCharacterController) => boolean;
1117
1115
  /**
1118
1116
  * A function allowing custom logic to determine if the entity can jump.
1119
- * @param this - The character controller instance.
1120
- * @returns Whether the entity can jump.
1117
+ * @param defaultCharacterController - The character controller instance.
1118
+ * @returns Whether the entity of the character controller can jump.
1121
1119
  */
1122
- canJump: (this: DefaultCharacterController) => boolean;
1120
+ canJump: (defaultCharacterController: DefaultCharacterController) => boolean;
1123
1121
 
1124
1122
 
1125
1123
 
@@ -1148,13 +1146,6 @@ export declare class DefaultCharacterController extends BaseCharacterController
1148
1146
  * @param deltaTimeMs - The delta time in milliseconds since the last tick.
1149
1147
  */
1150
1148
  tickPlayerMovement(inputState: PlayerInputState, orientationState: PlayerOrientationState, deltaTimeMs: number): void;
1151
- /**
1152
- * Ticks the pathfinding movement for the character controller,
1153
- * overriding the default implementation.
1154
- * @param destination - The destination to move to.
1155
- * @param deltaTimeMs - The delta time in milliseconds since the last tick.
1156
- */
1157
- tickPathfindingMovement(destination: Vector3, deltaTimeMs: number): void;
1158
1149
  }
1159
1150
 
1160
1151
  /** Options for creating a DefaultCharacterController instance. @public */
@@ -1210,55 +1201,55 @@ export declare interface DefaultCharacterControllerOptions {
1210
1201
  */
1211
1202
  export declare class Entity extends RigidBody implements protocol.Serializable {
1212
1203
  /**
1213
- * A function that creates a custom character controller for the entity.
1214
- * @param this - The Entity instance.
1204
+ * A function that creates a custom character controller for the entity when it spawns.
1205
+ * @param entity - The Entity instance the character controller is created for.
1215
1206
  * @returns A character controller that extends {@link BaseCharacterController}.
1216
1207
  */
1217
- createCustomCharacterController?: (this: Entity) => BaseCharacterController;
1208
+ createCustomCharacterController?: (entity: Entity) => BaseCharacterController;
1218
1209
  /**
1219
1210
  * A function that is called when the entity collides with a block.
1220
- * @param this - The Entity instance.
1211
+ * @param entity - The Entity instance the collision is for.
1221
1212
  * @param block - The block that the entity collided with.
1222
1213
  * @param started - Whether the collision started or ended.
1223
1214
  */
1224
- onBlockCollision?: (this: Entity, block: BlockType, started: boolean) => void;
1215
+ onBlockCollision?: (entity: Entity, block: BlockType, started: boolean) => void;
1225
1216
  /**
1226
1217
  * A function that is called when the entity collides with a block.
1227
- * @param this - The Entity instance.
1218
+ * @param entity - The Entity instance the collision is for.
1228
1219
  * @param block - The block that the entity collided with.
1229
1220
  * @param contactForceData - The contact force data.
1230
1221
  */
1231
- onBlockContactForce?: (this: Entity, block: BlockType, contactForceData: ContactForceData) => void;
1222
+ onBlockContactForce?: (entity: Entity, block: BlockType, contactForceData: ContactForceData) => void;
1232
1223
  /**
1233
1224
  * A function that is called when the entity collides with another entity.
1234
- * @param this - The Entity instance.
1235
- * @param entity - The entity that the entity collided with.
1225
+ * @param entity - The Entity instance the collision is for.
1226
+ * @param otherEntity - The other entity that the entity collided with.
1236
1227
  * @param started - Whether the collision started or ended.
1237
1228
  */
1238
- onEntityCollision?: (this: Entity, entity: Entity, started: boolean) => void;
1229
+ onEntityCollision?: (entity: Entity, otherEntity: Entity, started: boolean) => void;
1239
1230
  /**
1240
1231
  * A function that is called when the entity contacts another entity.
1241
- * @param this - The Entity instance.
1242
- * @param entity - The entity that the entity collided with.
1232
+ * @param entity - The Entity instance the collision is for.
1233
+ * @param otherEntity - The other entity that the entity collided with.
1243
1234
  * @param contactForceData - The contact force data.
1244
1235
  */
1245
- onEntityContactForce?: (this: Entity, entity: Entity, contactForceData: ContactForceData) => void;
1236
+ onEntityContactForce?: (entity: Entity, otherEntity: Entity, contactForceData: ContactForceData) => void;
1246
1237
  /**
1247
1238
  * A function that is called when the entity is spawned.
1248
- * @param this - The Entity instance.
1239
+ * @param entity - The Entity instance that spawned.
1249
1240
  */
1250
- onSpawn?: (this: Entity) => void;
1241
+ onSpawn?: (entity: Entity) => void;
1251
1242
  /**
1252
1243
  * A function that is called when the entity is despawned.
1253
- * @param this - The Entity instance.
1244
+ * @param entity - The Entity instance that despawned.
1254
1245
  */
1255
- onDespawn?: (this: Entity) => void;
1246
+ onDespawn?: (entity: Entity) => void;
1256
1247
  /**
1257
1248
  * A function that is called every tick.
1258
- * @param this - The Entity instance.
1249
+ * @param entity - The Entity instance that ticked.
1259
1250
  * @param tickDeltaMs - The delta time in milliseconds since the last tick.
1260
1251
  */
1261
- onTick?: (this: Entity, tickDeltaMs: number) => void;
1252
+ onTick?: (entity: Entity, tickDeltaMs: number) => void;
1262
1253
 
1263
1254
 
1264
1255
 
@@ -1421,6 +1412,12 @@ export declare class EntityManager {
1421
1412
 
1422
1413
  /** Options for creating an Entity instance. @public */
1423
1414
  export declare interface EntityOptions {
1415
+ /**
1416
+ * A function that creates a custom character controller for the entity when it spawns.
1417
+ * @param entity - The Entity instance.
1418
+ * @returns A character controller that extends {@link BaseCharacterController}.
1419
+ */
1420
+ createCustomCharacterController?: (entity: Entity) => BaseCharacterController;
1424
1421
  /** The URI or path to the .gltf model asset to be used for the entity. */
1425
1422
  modelUri?: string;
1426
1423
  /** The looped animations to start when the entity is spawned. */
@@ -1507,6 +1504,34 @@ export declare class EventRouter {
1507
1504
  emit<TPayload>(event: Event_2<TPayload>): boolean;
1508
1505
  }
1509
1506
 
1507
+ /**
1508
+ * A callback function called when the entity associated with the
1509
+ * SimpleCharacterController updates its rotation as it is
1510
+ * attempting to face a target coordinate.
1511
+ * @param currentRotation - The current rotation of the entity.
1512
+ * @param targetRotation - The target rotation of the entity.
1513
+ * @public
1514
+ */
1515
+ export declare type FaceCallback = (currentRotation: Rotation, targetRotation: Rotation) => void;
1516
+
1517
+ /**
1518
+ * A callback function called when the entity associated with the
1519
+ * SimpleCharacterController finishes rotating and is now facing
1520
+ * a target coordinate.
1521
+ * @param endRotation - The rotation of the entity after it has finished rotating.
1522
+ * @public
1523
+ */
1524
+ export declare type FaceCompleteCallback = (endRotation: Rotation) => void;
1525
+
1526
+ /**
1527
+ * Options for the {@link SimpleCharacterController.face} method.
1528
+ * @public
1529
+ */
1530
+ export declare type FaceOptions = {
1531
+ faceCallback?: FaceCallback;
1532
+ faceCompleteCallback?: FaceCompleteCallback;
1533
+ };
1534
+
1510
1535
  /**
1511
1536
  * Manages the game and associated worlds and systems.
1512
1537
  *
@@ -1616,6 +1641,13 @@ declare namespace HYTOPIA {
1616
1641
  RigidBodyType,
1617
1642
  RigidBodyAdditionalMassProperties,
1618
1643
  RigidBodyOptions,
1644
+ SimpleCharacterController,
1645
+ FaceCallback,
1646
+ FaceCompleteCallback,
1647
+ FaceOptions,
1648
+ MoveCallback,
1649
+ MoveCompleteCallback,
1650
+ MoveOptions,
1619
1651
  Simulation,
1620
1652
  WebServer,
1621
1653
  PORT,
@@ -1629,6 +1661,42 @@ declare namespace HYTOPIA {
1629
1661
  }
1630
1662
  export default HYTOPIA;
1631
1663
 
1664
+ /**
1665
+ * A callback function called when the entity associated with the
1666
+ * SimpleCharacterController updates its translation as it is
1667
+ * attempting to move to a target coordinate.
1668
+ * @param currentTranslation - The current translation of the entity.
1669
+ * @param targetTranslation - The target translation of the entity.
1670
+ * @public
1671
+ */
1672
+ export declare type MoveCallback = (currentTranslation: Vector3, targetTranslation: Vector3) => void;
1673
+
1674
+ /**
1675
+ * A callback function called when the entity associated with the
1676
+ * SimpleCharacterController reaches the target coordinate. An entity
1677
+ * must reach the x,y,z coordinate for the callback to be called.
1678
+ * @param endTranslation - The translation of the entity after it has finished moving.
1679
+ * @public
1680
+ */
1681
+ export declare type MoveCompleteCallback = (endTranslation: Vector3) => void;
1682
+
1683
+ /**
1684
+ * Options for the {@link SimpleCharacterController.move} method.
1685
+ * @public
1686
+ */
1687
+ export declare type MoveOptions = {
1688
+ /** Callback called each tick movement of the character controller's entity. */
1689
+ moveCallback?: MoveCallback;
1690
+ /** Callback called when the character controller's entity has finished moving. */
1691
+ moveCompleteCallback?: MoveCompleteCallback;
1692
+ /** Axes to ignore when moving the character controller's entity. Also ignored for determining completion. */
1693
+ moveIgnoreAxes?: {
1694
+ x?: boolean;
1695
+ y?: boolean;
1696
+ z?: boolean;
1697
+ };
1698
+ };
1699
+
1632
1700
  /**
1633
1701
  * A player in the game.
1634
1702
  *
@@ -2294,6 +2362,78 @@ export declare interface Rotation {
2294
2362
  w: number;
2295
2363
  }
2296
2364
 
2365
+ /**
2366
+ * A simple character controller with basic movement functions.
2367
+ *
2368
+ * @remarks
2369
+ * This class implements simple movement methods that serve
2370
+ * as a way to add realistic movement and rotational facing
2371
+ * functionality to an entity. This is also a great base to
2372
+ * extend for your own more complex character controller
2373
+ * that implements things like pathfinding. Compatible with
2374
+ * entities that have kinematic or dynamic rigid body types.
2375
+ *
2376
+ * @example
2377
+ * ```typescript
2378
+ * // Create a custom character controller for myEntity, prior to spawning it.
2379
+ * myEntity.createCustomCharacterController = () => {
2380
+ * return new SimpleCharacterController(myEntity);
2381
+ * };
2382
+ *
2383
+ * // Spawn the entity in the world.
2384
+ * myEntity.spawn(world, { x: 53, y: 10, z: 23 });
2385
+ *
2386
+ * // Move the entity at a speed of 4 blocks
2387
+ * // per second to the coordinate (10, 1, 10).
2388
+ * // console.log when we reach the target.
2389
+ * myEntity.characterController.move({ x: 10, y: 1, z: 10 }, 4, {
2390
+ * moveCompleteCallback: endPosition => {
2391
+ * console.log('Finished moving to', endPosition);
2392
+ * },
2393
+ * });
2394
+ * ```
2395
+ *
2396
+ * @public
2397
+ */
2398
+ export declare class SimpleCharacterController extends BaseCharacterController {
2399
+
2400
+
2401
+
2402
+
2403
+
2404
+
2405
+
2406
+
2407
+
2408
+ /**
2409
+ * Rotates the entity at a given speed to face a target coordinate.
2410
+ *
2411
+ * @remarks
2412
+ * If this method is called while the entity is already attempting
2413
+ * to face another target, the previous target will be ignored and
2414
+ * the entity will start attempting to face the new target.
2415
+ *
2416
+ * @param target - The target coordinate to face.
2417
+ * @param speed - The speed at which to rotate to the target coordinate.
2418
+ * @param options - Additional options for the face operation, such as callbacks.
2419
+ */
2420
+ face(target: Vector3, speed: number, options?: FaceOptions): void;
2421
+ /**
2422
+ * Moves the entity at a given speed in a straight line to a target coordinate.
2423
+ *
2424
+ * @remarks
2425
+ * If this method is called while the entity is already attempting
2426
+ * to move to another target, the previous target will be ignored and
2427
+ * the entity will start attempting to move to the new target.
2428
+ *
2429
+ * @param target - The target coordinate to move to.
2430
+ * @param speed - The speed at which to move to the target coordinate.
2431
+ * @param options - Additional options for the move operation, such as callbacks.
2432
+ */
2433
+ move(target: Vector3, speed: number, options?: MoveOptions): void;
2434
+
2435
+ }
2436
+
2297
2437
  /**
2298
2438
  * Represents the physics simulation for a world.
2299
2439
  *