raylib-wasm-transpiler/tools/js-class-c-struct-transpiler/test/build/User.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

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
*/
class User {
/**
* Name of the user
2024-06-12 23:05:45 -04:00
* @return {string} gets the value of Name
*/
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
*/
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
*/
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
*/
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
*/
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
*/
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.
*/
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.
*/
constructor(init = {}, ptr = undefined) {
this._size = 356;
2024-06-12 23:05:45 -04:00
this._ptr = ptr?.buffer || new ArrayBuffer(this._size);
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