Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GameData<RoomType>

Represents a room object containing data about players.

See GameDataEvents for events to listen to.

Type parameters

  • RoomType: Hostable

Hierarchy

Implements

Index

Methods

Awake

  • Awake(): void

Deserialize

  • Deserialize(reader: HazelReader, spawn?: boolean): void

Destroy

  • Destroy(): void

FixedUpdate

  • FixedUpdate(delta: number): void

HandleRpc

PreSerialize

  • PreSerialize(): void

Serialize

  • Serialize(writer: HazelWriter, spawn?: boolean): boolean

add

  • add(playerId: number): Promise<PlayerInfo<RoomType>>
  • Add a player to player data.

    example
    // Get an available player ID and add it to the gamedata.
    const playerId = room.getAvailablePlayerID();
    room.gamedata.add(playerId);
    

    Parameters

    • playerId: number

      The player ID of the player to add.

    Returns Promise<PlayerInfo<RoomType>>

canBeManaged

  • canBeManaged(): boolean

completeTask

  • Mark a player's task as complete.

    example
    // Complete all of a player's tasks.
    for (let i = 0; i < player.playerInfo.tasks.length; i++) {
      room.gamedata.completeTask(player, i);
    }
    

    Parameters

    • resolvable: PlayerIDResolvable

      The player of the tasks to mark complete.

    • taskIdx: number

      The index of the player's tasks to mark complete.

    Returns void

despawn

  • despawn(): void
  • Despawns the component from the room it belongs in.

    Returns void

emit

  • emit<Event>(event: Event): Promise<Event>

emitSerial

  • emitSerial<Event>(event: Event): Promise<Event>

emitSync

  • emitSync<Event>(event: Event): Event

getComponent

  • getComponent<T>(component: NetworkableConstructor<T>): undefined | T
  • Type parameters

    • T: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>, T>

    Parameters

    • component: NetworkableConstructor<T>

    Returns undefined | T

getListeners

  • getListeners<Event>(event: string): Listener<Event>[]

markDirty

off

  • off<EventName>(event: EventName, listener: Listener<GameDataEvents<RoomType>[EventName]>): void
  • off<K>(event: string, listener: Listener<K>): void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks"

    Parameters

    • event: EventName
    • listener: Listener<GameDataEvents<RoomType>[EventName]>

    Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns void

on

  • on<EventName>(event: EventName, listener: Listener<GameDataEvents<RoomType>[EventName]>): () => void
  • on<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks"

    Parameters

    • event: EventName
    • listener: Listener<GameDataEvents<RoomType>[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

once

  • once<EventName>(event: EventName, listener: Listener<GameDataEvents<RoomType>[EventName]>): () => void
  • once<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks"

    Parameters

    • event: EventName
    • listener: Listener<GameDataEvents<RoomType>[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

remove

removeAllListeners

  • removeAllListeners(): void

removeListeners

  • removeListeners(event: string): void

resolvePlayerData

setTasks

  • Set the tasks of a player.

    example
    room.gamedata.setTasks(player, [
      TheSkeldTask.ReactorUnlockManifolds,
      TheSkeldTask.ElectricDownloadData,
      TheSkeldTask.ShieldsPrimeShields,
      TheSkeldTask.NavigationDownloadData
    ]);
    

    Parameters

    • player: PlayerIDResolvable

      The player to set the tasks of.

    • taskTypes: number[]

      The task types to give to the player, see TaskType.

    Returns Promise<void>

spawn

  • spawn(): void
  • Spawn this component if does not exist in the room it belongs in.

    Returns void

wait

  • wait<EventName>(event: EventName): Promise<GameDataEvents<RoomType>[EventName]>
  • wait(event: string): Promise<BasicEvent>
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks"

    Parameters

    • event: EventName

    Returns Promise<GameDataEvents<RoomType>[EventName]>

  • Parameters

    • event: string

    Returns Promise<BasicEvent>

waitf

  • waitf<EventName>(event: EventName, filter: (ev: GameDataEvents<RoomType>[EventName]) => boolean | Promise<boolean>): Promise<GameDataEvents<RoomType>[EventName]>
  • waitf<K>(event: string, filter: (ev: K) => boolean | Promise<boolean>): Promise<BasicEvent>
  • Type parameters

    • EventName: "component.spawn" | "component.despawn" | "gamedata.addplayer" | "gamedata.removeplayer" | "gamedata.settasks"

    Parameters

    • event: EventName
    • filter: (ev: GameDataEvents<RoomType>[EventName]) => boolean | Promise<boolean>
        • (ev: GameDataEvents<RoomType>[EventName]): boolean | Promise<boolean>
        • Parameters

          Returns boolean | Promise<boolean>

    Returns Promise<GameDataEvents<RoomType>[EventName]>

  • Type parameters

    Parameters

    • event: string
    • filter: (ev: K) => boolean | Promise<boolean>
        • (ev: K): boolean | Promise<boolean>
        • Parameters

          • ev: K

          Returns boolean | Promise<boolean>

    Returns Promise<BasicEvent>

Properties

components

components: Networkable<any, NetworkableEvents<Hostable<any>>, RoomType>[]

dirtyBit

dirtyBit: number = 0

The dirty state of this component.

flags

flags: number

Flags for this object, see SpawnFlag.

netId

netId: number

The net ID of this component.

ownerId

ownerId: number

The ID of the owner of this component.

Optional player

player: PlayerData<RoomType>

The player that this component belongs to.

players

players: Map<number, PlayerInfo<RoomType>>

The players in the game data.

room

room: RoomType

The room that this component belongs to.

spawnType

spawnType: SpawnType

The type of object that this component belongs to.

Constructors

constructor

Accessors

owner

  • get owner(): RoomType

Generated using TypeDoc