interfaces replay - wxyz-abcd/node-haxball GitHub Wiki
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 sections2,4.1and5of our event callbacks documentation. In addition, it is possible to use a render callback that has the same signature as defined in section3of ourRendererdocumentation. -
options: An object that may contain the following keys:-
requestAnimationFrame: Override function forrequestAnimationFrame. (null= use library's defaultrequestAnimationFrame.) -
cancelAnimationFrame: Override function forcancelAnimationFrame. (null= use library's defaultcancelAnimationFrame.)
-
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
ReplayDatastructure 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
ReplayDatabetween given frame numbersbeginFrameNoandendFrameNo, both of which can be omitted and are inclusive. If omitted,beginFrameNodefaults to0andendFrameNodefaults toreplayData.totalFrames-1Parameters:
-
replayData: The ReplayData structure that needs to be trimmed. -
params: An optional object that may containbeginFrameNoandendFrameNointeger 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
ReplayDatabetween given frame numbersbeginFrameNoandendFrameNo, both of which can be omitted and are inclusive. If omitted,beginFrameNodefaults to0andendFrameNodefaults toreplayData.totalFrames-1.Parameters:
-
replayData: The ReplayData structure that needs to be trimmed. -
params: An optional object that may containbeginFrameNoandendFrameNointeger 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
ReplayDatastructure into a newUint8Arrayand 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 }
-