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

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-05-29 20:47:19 -04:00
import Stats from "./Stats"
import HiddenStats from "./HiddenStats"
import Skills from "./Skills"
class Entity {
get Name() {
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24)));
}
set Name(v) {
this._data.set(this._encoder.encode(v), 0);
}
2024-05-29 20:47:19 -04:00
get Stats() {
return new Stats({}, new Uint8Array(this._ptr.slice(24, 30)));
}
2024-05-29 20:47:19 -04:00
set Stats(v) {
this._data.set(v.bytes(), 24);
}
2024-05-29 20:47:19 -04:00
get HiddenStats() {
return new HiddenStats({}, new Uint8Array(this._ptr.slice(30, 35)));
}
2024-05-29 20:47:19 -04:00
set HiddenStats(v) {
this._data.set(v.bytes(), 30);
}
2024-05-29 20:47:19 -04:00
get Skills() {
return new Skills({}, new Uint8Array(this._ptr.slice(35, 54)));
}
2024-05-29 20:47:19 -04:00
set Skills(v) {
this._data.set(v.bytes(), 35);
}
2024-05-29 20:47:19 -04:00
sql_insert(Name, Stats, HiddenStats, Skills) {
return `INSERT INTO Entity (Name, Stats, HiddenStats, Skills) VALUES (${Name}, ${Stats}, ${HiddenStats}, ${Skills}) RETURNING id;`
}
get bytes() {
return new Uint8Array(this._ptr);
}
constructor(init = {}, ptr = undefined) {
2024-05-27 20:19:37 -04:00
this._size = 54;
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];
}
}
2024-05-27 19:26:24 -04:00
}
export default Entity