UNPKG

unreal.js

Version:

A pak reader for games like VALORANT & Fortnite written in Node.JS

56 lines (55 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FWeightedRandomSampler = void 0; const FArchive_1 = require("../../reader/FArchive"); /** * FWeightedRandomSampler * @implements {IStructType} */ class FWeightedRandomSampler { /** DO NOT USE THIS CONSTRUCTOR, THIS IS FOR THE LIBRARY */ constructor(x, y, z) { if (x instanceof FArchive_1.FArchive) { const len1 = x.readInt32(); this.prob = new Array(len1); for (let i = 0; i < len1; ++i) { this.prob[i] = x.readFloat32(); } const len2 = x.readInt32(); this.alias = new Array(len2); for (let i = 0; i < len1; ++i) { this.alias[i] = x.readInt32(); } this.totalWeight = x.readFloat32(); } else { this.prob = x; this.alias = y; this.totalWeight = z; } } /** * Serializes this * @param {FArchiveWriter} Ar UE4 Writer to use * @returns {void} * @public */ serialize(Ar) { Ar.writeTArray(this.prob, (it) => Ar.writeFloat32(it)); Ar.writeTArray(this.alias, (it) => Ar.writeInt32(it)); Ar.writeFloat32(this.totalWeight); } /** * Turns this into json * @returns {any} Json * @public */ toJson() { return { prob: this.prob, alias: this.alias, totalWeight: this.totalWeight }; } } exports.FWeightedRandomSampler = FWeightedRandomSampler;