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

44 lines
1.3 KiB
JavaScript

/**
* @typedef {Object} Phenomenon Kinda like an action, cant remember
* @property {string} Name Name of the phenomenon
*/
class Phenomenon {
/**
* Name of the phenomenon
* @return {string} gets the value of Name
*/
get Name() {
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 64)));
}
/**
* Name of the phenomenon
* @param {string} v sets the value of Name
*/
set Name(v) {
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);
}
/**
* 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;
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