Skip to content

Computed packet properties #76

@mkapal

Description

@mkapal

Some packet properties require manual bitwise comparison in order to get the desired information, resulting in worse developer experience.

The idea is to use JavaScript class getters to expose dynamic class instance properties based on other packet values.

Example solution: IS_NPL packet

Implementation

class IS_NPL extends Packet {
  // ...
  @byte() PType: PlayerType | 0 = 0;
  // ... new code below
  public get isFemale() {
    return (this.PType & PlayerType.FEMALE) !== 0;
  }
}

Usage

inSim.on(PacketType.IS_NPL, (packet) => {
  console.log((packet.PType & PlayerType.FEMALE) !== 0); // raw
  console.log(packet.isFemale); // computed property
});

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions