interfaces replay - wxyz-abcd/node-haxball GitHub Wiki

Replay

This object consists of functions related to replay files.

  • read(data: Uint8Array, callbacks: object, options?: object): ReplayReader

    Creates and returns a non-blocking replay reader object. You can look at examples/api_structure/replayReader.js for all supported callbacks and example usage.

    Parameters:

    • data: Must be an Uint8Array containing the binary contents of a .hbr file. (Currently, only version 3 is supported.)
    • callbacks: An object that may have all callbacks defined in sections 2, 3.1 and 4 of our event callbacks documentation. In addition, it is possible to use a render callback that has the same signature as defined in section 3 of our Renderer documentation.
    • options: An object that may contain the following keys:
      • requestAnimationFrame: Override function for requestAnimationFrame. (null = use library's default requestAnimationFrame.)
      • cancelAnimationFrame: Override function for cancelAnimationFrame. (null = use library's default cancelAnimationFrame.)
      • fps_limit: Any positive number that will be used as the fps limit. (null = no limit)

    Caution: Any internal error will be thrown and should be caught using a try-catch block.

    Return value: An instance of the ReplayReader structure.

    Example:

    try{
      var replayReader = Replay.read(data, {
        onPlayerChat: (id, message) => {
          console.log(id + " : " + message);
        },
        onPlayerTeamChange: (id, teamId, byId) => {
          console.log(id + " was moved to " + teamId + " by " + byId);
        }
      });
      replayReader.onEnd = ()=>{ // the end of replay data is reached.
        replayReader.destroy(); // release the resources
      };
      replayReader.setSpeed(1); // start playing
    }
    catch(error){ // this is of type HBError
      console.log(error.toString()); // you have to use .toString() to convert it into a readable string
    }
  • readAll(data: Uint8Array): ReplayData

    Reads all of the given binary replay data into a new ReplayData structure and returns it.

    Parameters:

    • data: Must be an Uint8Array containing the binary contents of a .hbr file. (Currently, only version 3 is supported.)

    Caution: Any internal error will be thrown and should be caught using a try-catch block.

    Return value: An instance of the ReplayData structure.

    Example:

    try{
      var replayData = Replay.readAll(data);
      // ...
      // Do something with the replay data.
    }
    catch(error){ // this is of type HBError
      console.log(error.toString()); // you have to use .toString() to convert it into a readable string
    }
  • trim(replayData: ReplayData, params?: { beginFrameNo?: int, endFrameNo?: int }): void

    Trims the given ReplayData between given frame numbers beginFrameNo and endFrameNo, both of which can be omitted and are inclusive. If omitted, beginFrameNo defaults to 0 and endFrameNo defaults to replayData.totalFrames-1

    Parameters:

    • replayData: The ReplayData structure that needs to be trimmed.
    • params: An optional object that may contain beginFrameNo and endFrameNo integer keys.

    Return value: void.

    Example:

    try{
      var replayData = Replay.readAll(data);
      Replay.trim(replayData, {beginFrameNo: 1000, endFrameNo: 5000});
      // Now the replayData only contains the frames between 1000 and 5000.
      // ...
      // Do something with the replay data.
    }
    catch(error){ // this is of type HBError
      console.log(error.toString()); // you have to use .toString() to convert it into a readable string
    }
  • trimAsync(replayData: ReplayData, params?: { beginFrameNo?: int, endFrameNo?: int }): Promise(void)

    Trims the given ReplayData between given frame numbers beginFrameNo and endFrameNo, both of which can be omitted and are inclusive. If omitted, beginFrameNo defaults to 0 and endFrameNo defaults to replayData.totalFrames-1.

    Parameters:

    • replayData: The ReplayData structure that needs to be trimmed.
    • params: An optional object that may contain beginFrameNo and endFrameNo integer keys.

    Return value: A Promise that is resolved when the trimming job is finished.

    Example:

    try{
      var replayData = Replay.readAll(data);
      Replay.trimAsync(replayData, {beginFrameNo: 1000, endFrameNo: 5000}).then(()=>{
        // Now the replayData only contains the frames between 1000 and 5000.
        // ...
        // Do something with the replay data.
      });
    }
    catch(error){ // this is of type HBError
      console.log(error.toString()); // you have to use .toString() to convert it into a readable string
    }
  • writeAll(data: ReplayData): Uint8Array

    Writes the contents of a ReplayData structure into a new Uint8Array and returns it.

    Parameters:

    • data: Must be an instance of the ReplayData structure.

    Caution: Any internal error will be thrown and should be caught using a try-catch block.

    Return value: A new Uint8Array that contains the binary representation of the given ReplayData instance.

    Example:

    try{
      var data = Replay.readAll(replayData);
      // ...
      // Do something with the data.
    }
    catch(error){ // this is of type HBError
      console.log(error.toString()); // you have to use .toString() to convert it into a readable string
    }
  • ReplayData
⚠️ **GitHub.com Fallback** ⚠️