2024-06-02 09:42:35 -04:00
|
|
|
import Login from "./Login"
|
|
|
|
import Vector3 from "./Vector3"
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
class User {
|
|
|
|
/**
|
|
|
|
* Name of the user
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {string} gets the value of Name
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get Name() {
|
|
|
|
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24)));
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* Name of the user
|
|
|
|
* @param {string} v sets the value of Name
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set Name(v) {
|
|
|
|
this._data.set(this._encoder.encode(v), 0);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* user login info
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {Login} gets the value of Login
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get Login() {
|
|
|
|
return new Login({}, new Uint8Array(this._ptr.slice(24, 344)));
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* user login info
|
|
|
|
* @param {Login} sets the value of Login
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set Login(v) {
|
|
|
|
this._data.set(v.bytes(), 24);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* last logout position of user
|
2024-06-12 23:05:45 -04:00
|
|
|
* @return {Vector3} gets the value of Position
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get Position() {
|
|
|
|
return new Vector3({}, new Uint8Array(this._ptr.slice(344, 356)));
|
|
|
|
}
|
2024-06-12 23:05:45 -04:00
|
|
|
/**
|
|
|
|
* last logout position of user
|
|
|
|
* @param {Vector3} sets the value of Position
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set Position(v) {
|
|
|
|
this._data.set(v.bytes(), 344);
|
|
|
|
}
|
|
|
|
/**
|
2024-06-12 23:05:45 -04:00
|
|
|
* Get the struct representation of the object
|
|
|
|
* @return {Uint8Array} u8 array of the C struct.
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get bytes() {
|
|
|
|
return new Uint8Array(this._ptr);
|
|
|
|
}
|
|
|
|
/**
|
2024-06-12 23:05:45 -04:00
|
|
|
* Constructs a new User
|
|
|
|
*
|
|
|
|
* @param {{Name: string, Login: Login, Position: Vector3, }} init The arguments to construct the object.
|
|
|
|
* @param {ArrayBuffer} ptr The pointer to the C struct.
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
constructor(init = {}, ptr = undefined) {
|
|
|
|
this._size = 356;
|
2024-06-12 23:05:45 -04:00
|
|
|
this._ptr = ptr?.buffer || new ArrayBuffer(this._size);
|
2024-06-02 09:42:35 -04:00
|
|
|
this._data = new DataView(this._ptr);
|
|
|
|
|
|
|
|
this._encoder = new TextEncoder();
|
|
|
|
this._decoder = new TextDecoder();
|
|
|
|
for (const key of Object.keys(init)) {
|
|
|
|
this[key] = init[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default User
|