2024-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* @typedef {Object} Phenomenon Kinda like an action, cant remember
|
|
|
|
* @property {string} Name Name of the phenomenon
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
class Phenomenon {
|
|
|
|
/**
|
|
|
|
* Name of the phenomenon
|
2024-06-30 21:12:58 -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, 64)));
|
|
|
|
}
|
2024-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Name of the phenomenon
|
|
|
|
* @param {string} v sets the value of Name
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set Name(v) {
|
2024-06-30 21:12:58 -04:00
|
|
|
if (v.length > 64) {
|
|
|
|
throw new Error("input is larger than buffer size of 64");
|
|
|
|
}
|
|
|
|
const tmp = new Uint8Array(new ArrayBuffer(64));
|
|
|
|
tmp.set(this._encoder.encode(v))
|
|
|
|
this._ptr.set(tmp.buffer, 0);
|
2024-06-02 09:42:35 -04:00
|
|
|
}
|
|
|
|
/**
|
2024-06-30 21:12:58 -04:00
|
|
|
* Constructs a new Phenomenon
|
|
|
|
*
|
|
|
|
* @param {{Name: string, }} init The arguments to construct the object.
|
|
|
|
* @param {Uint8Array} ptr The pointer to the C struct.
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
constructor(init = {}, ptr = undefined) {
|
|
|
|
this._size = 64;
|
2024-06-30 21:12:58 -04:00
|
|
|
this._ptr = ptr || new Uint8Array(this._size);
|
|
|
|
this._data = new DataView(this._ptr.buffer);
|
2024-06-02 09:42:35 -04:00
|
|
|
|
|
|
|
this._encoder = new TextEncoder();
|
|
|
|
this._decoder = new TextDecoder();
|
|
|
|
for (const key of Object.keys(init)) {
|
|
|
|
this[key] = init[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Phenomenon
|