2024-06-02 09:42:35 -04:00
|
|
|
import Vector3 from "./Vector3"
|
2024-05-29 20:47:19 -04:00
|
|
|
import Stats from "./Stats"
|
2024-06-02 09:42:35 -04:00
|
|
|
import DerivedStats from "./DerivedStats"
|
2024-05-29 20:47:19 -04:00
|
|
|
import Skills from "./Skills"
|
2024-05-27 18:26:44 -04:00
|
|
|
class Entity {
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Name of the entity
|
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
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-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Vector3 of the entity in space
|
|
|
|
*/
|
|
|
|
get Vector3() {
|
|
|
|
return new Vector3({}, new Uint8Array(this._ptr.slice(24, 36)));
|
|
|
|
}
|
|
|
|
set Vector3(v) {
|
|
|
|
this._data.set(v.bytes(), 24);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Base stats
|
|
|
|
*/
|
2024-05-29 20:47:19 -04:00
|
|
|
get Stats() {
|
2024-06-02 09:42:35 -04:00
|
|
|
return new Stats({}, new Uint8Array(this._ptr.slice(36, 41)));
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-05-29 20:47:19 -04:00
|
|
|
set Stats(v) {
|
2024-06-02 09:42:35 -04:00
|
|
|
this._data.set(v.bytes(), 36);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Stats that are derived from skills and base stats
|
|
|
|
*/
|
|
|
|
get DerivedStats() {
|
|
|
|
return new DerivedStats({}, new Uint8Array(this._ptr.slice(41, 49)));
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
set DerivedStats(v) {
|
|
|
|
this._data.set(v.bytes(), 41);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Stuff that your character can do
|
|
|
|
*/
|
2024-05-29 20:47:19 -04:00
|
|
|
get Skills() {
|
2024-06-02 09:42:35 -04:00
|
|
|
return new Skills({}, new Uint8Array(this._ptr.slice(49, 65)));
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-05-29 20:47:19 -04:00
|
|
|
set Skills(v) {
|
2024-06-02 09:42:35 -04:00
|
|
|
this._data.set(v.bytes(), 49);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* get the struct representation of the object
|
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
get bytes() {
|
|
|
|
return new Uint8Array(this._ptr);
|
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
constructor(init = {}, ptr = undefined) {
|
2024-06-02 09:42:35 -04:00
|
|
|
this._size = 65;
|
2024-05-27 18:26:44 -04:00
|
|
|
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
|