Files
esengine/packages/framework/network/src/components/NetworkIdentity.ts

71 lines
1.6 KiB
TypeScript
Raw Normal View History

import { Component, ECSComponent, Serialize, Serializable, Property } from '@esengine/ecs-framework';
/**
*
* Network identity component
*
*
* Identifies an entity's unique identity on the network.
*/
@ECSComponent('NetworkIdentity')
@Serializable({ version: 1, typeId: 'NetworkIdentity' })
export class NetworkIdentity extends Component {
/**
* ID
* Network entity ID
*/
@Serialize()
@Property({ type: 'integer', label: 'Net ID', readOnly: true })
public netId: number = 0;
/**
* ID
* Owner client ID
*/
@Serialize()
@Property({ type: 'integer', label: 'Owner ID', readOnly: true })
public ownerId: number = 0;
/**
*
* Is owned by local player
*/
public bIsLocalPlayer: boolean = false;
/**
*
* Has authority
*/
public bHasAuthority: boolean = false;
/**
*
* Prefab type
*/
@Serialize()
@Property({ type: 'string', label: 'Prefab Type' })
public prefabType: string = '';
/**
* (ms)
* Sync interval in milliseconds
*/
@Serialize()
@Property({ type: 'number', label: 'Sync Interval', min: 16 })
public syncInterval: number = 100;
/**
*
* Last sync time
*/
public lastSyncTime: number = 0;
/**
*
* Check if sync is needed
*/
public needsSync(now: number): boolean {
return now - this.lastSyncTime >= this.syncInterval;
}
}