raylib-wasm-transpiler/server/components/Phenomenon.js

44 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-06-30 21:12:58 -04:00
/**
* @typedef {Object} Phenomenon Kinda like an action, cant remember
* @property {string} Name Name of the phenomenon
*/
class Phenomenon {
/**
* Name of the phenomenon
2024-06-30 21:12:58 -04:00
* @return {string} gets the value of Name
*/
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
*/
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-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.
*/
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);
this._encoder = new TextEncoder();
this._decoder = new TextDecoder();
for (const key of Object.keys(init)) {
this[key] = init[key];
}
}
}
export default Phenomenon