48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
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);
|
|
}
|
|
get Stats() {
|
|
return new Stats({}, new Uint8Array(this._ptr.slice(24, 30)));
|
|
}
|
|
set Stats(v) {
|
|
this._data.set(v.bytes(), 24);
|
|
}
|
|
get HiddenStats() {
|
|
return new HiddenStats({}, new Uint8Array(this._ptr.slice(30, 35)));
|
|
}
|
|
set HiddenStats(v) {
|
|
this._data.set(v.bytes(), 30);
|
|
}
|
|
get Skills() {
|
|
return new Skills({}, new Uint8Array(this._ptr.slice(35, 54)));
|
|
}
|
|
set Skills(v) {
|
|
this._data.set(v.bytes(), 35);
|
|
}
|
|
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) {
|
|
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];
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Entity |