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

76 lines
2.1 KiB
JavaScript
Raw Permalink 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
2024-06-13 01:08:44 -04:00
* @property {Login} Login user login info
* @property {Vector3} Vector3 last logout position of user
2024-06-12 23:05:45 -04:00
*/
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) {
2024-06-13 01:08:44 -04:00
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
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) {
2024-06-13 01:08:44 -04:00
this._ptr.set(v._ptr, 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) {
2024-06-13 01:08:44 -04:00
this._ptr.set(v._ptr, 344);
}
/**
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.
2024-06-13 01:08:44 -04:00
* @param {Uint8Array} ptr The pointer to the C struct.
*/
constructor(init = {}, ptr = undefined) {
this._size = 356;
2024-06-13 01:08:44 -04:00
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