Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SwitchSystem<RoomType>

Represents a system responsible for handling switches in Electrical.

See SwitchSystemEvents for events to listen to.

Type parameters

  • RoomType: Hostable

Hierarchy

Implements

Index

Methods

Static readSwitches

  • readSwitches(byte: number): SwitchSetup
  • Read the value of each switch from a byte.

    example
    console.log(readSwitches(0x5));
    // [ true, false, true, false, false ]
    

    Parameters

    • byte: number

      The byte to read from.

    Returns SwitchSetup

    An array of the value of each switch.

Static writeSwitches

  • writeSwitches(switches: SwitchSetup): number
  • Write the value of each switch to a byte.

    example
    console.log(writeSwitches([ false, true, false, false, true ]));
    // 0x12 (18)
    

    Parameters

    • switches: SwitchSetup

      An array of the value of each switch.

    Returns number

    The byte representation of the switches.

Deserialize

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

Detoriorate

  • Detoriorate(delta: number): void

HandleRepair

  • HandleRepair(player: undefined | PlayerData<RoomType>, amount: number, rpc: undefined | RepairSystemMessage): Promise<void>

HandleSabotage

  • HandleSabotage(player: undefined | PlayerData<RoomType>, rpc: undefined | RepairSystemMessage): Promise<void>

Serialize

emit

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

emitSerial

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

emitSync

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

flip

  • flip(num: number): Promise<void>
  • Invert the position of a switch.

    example
    // Invert the position of each switch.
    for (let i = 0; i < 5; i++) {
      electrical.flip(i);
    }
    

    Parameters

    • num: number

      The ID of the switch to invert.

    Returns Promise<void>

getListeners

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

off

  • off<EventName>(event: EventName, listener: Listener<SwitchSystemEvents<Hostable<any>>[EventName]>): void
  • off<K>(event: string, listener: Listener<K>): void
  • Type parameters

    • EventName: "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "electrical.switchflip"

    Parameters

    Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns void

on

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

    • EventName: "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "electrical.switchflip"

    Parameters

    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<SwitchSystemEvents<Hostable<any>>[EventName]>): () => void
  • once<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "electrical.switchflip"

    Parameters

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

removeAllListeners

  • removeAllListeners(): void

removeListeners

  • removeListeners(event: string): void

repair

  • repair(): Promise<void>

sabotage

  • sabotage(): Promise<void>

setSwitch

  • setSwitch(num: number, value: boolean): Promise<void>
  • Set the value of a switch as flipped or not flipped

    example
    // Randomise each switch.
    for (let i = 0; i < 5; i++) {
      electrical.setSwitch(i, Math.random() > 0.5);
    }
    

    Parameters

    • num: number

      The ID of the switch to flip.

    • value: boolean

      Whether the switch is flipped.

    Returns Promise<void>

wait

waitf

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

    • EventName: "doors.open" | "doors.close" | "system.sabotage" | "system.repair" | "electrical.switchflip"

    Parameters

    • event: EventName
    • filter: (ev: SwitchSystemEvents<Hostable<any>>[EventName]) => boolean | Promise<boolean>

    Returns Promise<SwitchSystemEvents<Hostable<any>>[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

actual

actual: SwitchSetup

The current switch states.

brightness

brightness: number

The brightness of lights.

expected

expected: SwitchSetup

The switch states that are expected.

systemType

systemType: SystemType

Constructors

constructor

Accessors

dirty

  • get dirty(): boolean
  • set dirty(isDirty: boolean): void

room

  • get room(): RoomType

sabotaged

  • get sabotaged(): boolean

Generated using TypeDoc