53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
|
import Login from "./Login"
|
||
|
import Vector3 from "./Vector3"
|
||
|
class User {
|
||
|
/**
|
||
|
* Name of the user
|
||
|
*/
|
||
|
get Name() {
|
||
|
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24)));
|
||
|
}
|
||
|
set Name(v) {
|
||
|
this._data.set(this._encoder.encode(v), 0);
|
||
|
}
|
||
|
/**
|
||
|
* user login info
|
||
|
*/
|
||
|
get Login() {
|
||
|
return new Login({}, new Uint8Array(this._ptr.slice(24, 344)));
|
||
|
}
|
||
|
set Login(v) {
|
||
|
this._data.set(v.bytes(), 24);
|
||
|
}
|
||
|
/**
|
||
|
* last logout position of user
|
||
|
*/
|
||
|
get Position() {
|
||
|
return new Vector3({}, new Uint8Array(this._ptr.slice(344, 356)));
|
||
|
}
|
||
|
set Position(v) {
|
||
|
this._data.set(v.bytes(), 344);
|
||
|
}
|
||
|
/**
|
||
|
* get the struct representation of the object
|
||
|
*/
|
||
|
get bytes() {
|
||
|
return new Uint8Array(this._ptr);
|
||
|
}
|
||
|
/**
|
||
|
* constructor
|
||
|
*/
|
||
|
constructor(init = {}, ptr = undefined) {
|
||
|
this._size = 356;
|
||
|
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
|