Added MSA GameLib

2025-08-09 18:35:50 +02:00
parent 39c99f04ba
commit ad4596f694

111
ModuleServerAPIGameLib.md Normal file

@@ -0,0 +1,111 @@
# ModuleClientApi - GameLib
Class representing the GameLib inside the ModuleServerAPI.
## Timing
Several functions to synchronize clients using the synced time you can retrieve using `api.getTime()`.
### toTimeSpan
Creates a timespan object.
```javascript
api.GameLib.Timing.toTimeSpan(duration, startTimestamp?);
```
| Argument | Type | Description |
| ------------------------- | ------ | ---------------------------------------------------- |
| duration | number | The duration of the timespan in milliseconds. |
| (Optional) startTimestamp | number | The start timestamp of the timespan in milliseconds. |
**Return** [TimeSpan](./ModuleApiGameLibTimeSpan) _TimeSpan instance._
### toFrameCycle
Creates a frame cycle object.
```javascript
api.GameLib.Timing.toFrameCycle(startTimestamp, frameInterval, totalFrames, startFrame?);
```
| Argument | Type | Description |
| -------------- | ------ | ------------------------------------------------------- |
| startTimestamp | number | The start timestamp of the frame cycle in milliseconds. |
| frameInterval | number | The interval between frames in milliseconds. |
| totalFrames | number | The total number of frames in the cycle. |
| startFrame | number | The start frame of the cycle. |
**Return** [FrameCycle](./ModuleApiGameLibFrameCycle) _FrameCycle instance._
### toRatio
Creates a ratio object.
```javascript
api.GameLib.Timing.toRatio(value);
```
| Argument | Type | Description |
| -------- | ------ | ----------------------- |
| value | number | The value of the ratio. |
**Return** [Ratio](./ModuleApiGameLibRatio) _Ratio instance._
### getCurrentFrameIndex
Gets the current frame index of the frame cycle.
```javascript
api.GameLib.Timing.getCurrentFrameIndex(cycle);
```
| Argument | Type | Description |
| -------- | ------------------------------------------ | ------------------- |
| cycle | [FrameCycle](./ModuleApiGameLibFrameCycle) | FrameCycle instance |
**Return** number _The current frame index._
### getFrameIndexAtTimestamp
Gets the current frame index of the frame cycle.
```javascript
api.GameLib.Timing.getFrameIndexAtTimestamp(cycle, timestamp);
```
| Argument | Type | Description |
| --------- | ------------------------------------------ | ---------------------------------------- |
| cycle | [FrameCycle](./ModuleApiGameLibFrameCycle) | FrameCycle instance |
| timestamp | number | The timestamp to get the frame index at. |
**Return** number _The frame index at the given timestamp._
### getCurrentTimeSpanRatio
Gets the ratio of the current time span.
```javascript
api.GameLib.Timing.getCurrentTimeSpanRatio(span);
```
| Argument | Type | Description |
| -------- | -------------------------------------- | ----------------- |
| span | [TimeSpan](./ModuleApiGameLibTimeSpan) | TimeSpan instance |
**Return** [Ratio](./ModuleApiGameLibRatio) _The ratio of the current time span._
### getTimeSpanRatioAtTimestamp
Gets the ratio of the time span at the given timestamp.
```javascript
api.GameLib.Timing.getTimeSpanRatioAtTimestamp(span, timestamp);
```
| Argument | Type | Description |
| --------- | -------------------------------------- | ---------------------------------- |
| span | [TimeSpan](./ModuleApiGameLibTimeSpan) | TimeSpan instance |
| timestamp | number | The timestamp to get the ratio at. |
**Return** [Ratio](./ModuleApiGameLibRatio) _The ratio of the time span at the given timestamp._