import Login from "./Login" import Vector3 from "./Vector3" /** * @typedef {Object} User The user object * @property {string} Name Name of the user * @property {Login} Login user login info * @property {Vector3} Vector3 last logout position of user */ class User { /** * Name of the user * @return {string} gets the value of Name */ get Name() { return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24))); } /** * Name of the user * @param {string} v sets the value of Name */ set Name(v) { if (v.length > 24) { throw new Error("input is larger than buffer size of 24"); } const tmp = new Uint8Array(new ArrayBuffer(24)); tmp.set(this._encoder.encode(v)) this._ptr.set(tmp.buffer, 0); } /** * user login info * @return {Login} gets the value of Login */ get Login() { return new Login({}, new Uint8Array(this._ptr.slice(24, 344))); } /** * user login info * @param {Login} sets the value of Login */ set Login(v) { this._ptr.set(v._ptr, 24); } /** * last logout position of user * @return {Vector3} gets the value of Position */ get Position() { return new Vector3({}, new Uint8Array(this._ptr.slice(344, 356))); } /** * last logout position of user * @param {Vector3} sets the value of Position */ set Position(v) { this._ptr.set(v._ptr, 344); } /** * Constructs a new User * * @param {{Name: string, Login: Login, Position: Vector3, }} init The arguments to construct the object. * @param {Uint8Array} ptr The pointer to the C struct. */ constructor(init = {}, ptr = undefined) { this._size = 356; this._ptr = ptr || new Uint8Array(this._size); this._data = new DataView(this._ptr.buffer); this._encoder = new TextEncoder(); this._decoder = new TextDecoder(); for (const key of Object.keys(init)) { this[key] = init[key]; } } } export default User