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-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* @typedef {Object} Entity Something that can exist in 3D space
|
|
|
|
* @property {string} Name Name of the entity
|
|
|
|
* @property {Vector3} Vector3 Vector3 of the entity in space
|
|
|
|
* @property {Stats} Stats Base stats
|
|
|
|
* @property {DerivedStats} DerivedStats Stats that are derived from skills and base stats
|
|
|
|
* @property {Skills} Skills Stuff that your character can do
|
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
class Entity {
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Name of the entity
|
2024-06-30 21:12:58 -04:00
|
|
|
* @return {string} gets the value of Name
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
get Name() {
|
|
|
|
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24)));
|
|
|
|
}
|
2024-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Name of the entity
|
|
|
|
* @param {string} v sets the value of Name
|
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
set Name(v) {
|
2024-06-30 21:12:58 -04:00
|
|
|
if (v.length > 24) {
|
|
|
|
throw new Error("input is larger than buffer size of 24");
|
|
|
|
}
|
|
|
|
const tmp = new Uint8Array(new ArrayBuffer(24));
|
|
|
|
tmp.set(this._encoder.encode(v))
|
|
|
|
this._ptr.set(tmp.buffer, 0);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Vector3 of the entity in space
|
2024-06-30 21:12:58 -04:00
|
|
|
* @return {Vector3} gets the value of Vector3
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get Vector3() {
|
|
|
|
return new Vector3({}, new Uint8Array(this._ptr.slice(24, 36)));
|
|
|
|
}
|
2024-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Vector3 of the entity in space
|
|
|
|
* @param {Vector3} sets the value of Vector3
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set Vector3(v) {
|
2024-06-30 21:12:58 -04:00
|
|
|
this._ptr.set(v._ptr, 24);
|
2024-06-02 09:42:35 -04:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Base stats
|
2024-06-30 21:12:58 -04:00
|
|
|
* @return {Stats} gets the value of Stats
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
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-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Base stats
|
|
|
|
* @param {Stats} sets the value of Stats
|
|
|
|
*/
|
2024-05-29 20:47:19 -04:00
|
|
|
set Stats(v) {
|
2024-06-30 21:12:58 -04:00
|
|
|
this._ptr.set(v._ptr, 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
|
2024-06-30 21:12:58 -04:00
|
|
|
* @return {DerivedStats} gets the value of DerivedStats
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
|
|
|
get DerivedStats() {
|
|
|
|
return new DerivedStats({}, new Uint8Array(this._ptr.slice(41, 49)));
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Stats that are derived from skills and base stats
|
|
|
|
* @param {DerivedStats} sets the value of DerivedStats
|
|
|
|
*/
|
2024-06-02 09:42:35 -04:00
|
|
|
set DerivedStats(v) {
|
2024-06-30 21:12:58 -04:00
|
|
|
this._ptr.set(v._ptr, 41);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
|
|
|
* Stuff that your character can do
|
2024-06-30 21:12:58 -04:00
|
|
|
* @return {Skills} gets the value of Skills
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
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-06-30 21:12:58 -04:00
|
|
|
/**
|
|
|
|
* Stuff that your character can do
|
|
|
|
* @param {Skills} sets the value of Skills
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
2024-06-30 21:12:58 -04:00
|
|
|
set Skills(v) {
|
|
|
|
this._ptr.set(v._ptr, 49);
|
2024-05-27 18:26:44 -04:00
|
|
|
}
|
2024-06-02 09:42:35 -04:00
|
|
|
/**
|
2024-06-30 21:12:58 -04:00
|
|
|
* Constructs a new Entity
|
|
|
|
*
|
|
|
|
* @param {{Name: string, Vector3: Vector3, Stats: Stats, DerivedStats: DerivedStats, Skills: Skills, }} init The arguments to construct the object.
|
|
|
|
* @param {Uint8Array} ptr The pointer to the C struct.
|
2024-06-02 09:42:35 -04:00
|
|
|
*/
|
2024-05-27 18:26:44 -04:00
|
|
|
constructor(init = {}, ptr = undefined) {
|
2024-06-02 09:42:35 -04:00
|
|
|
this._size = 65;
|
2024-06-30 21:12:58 -04:00
|
|
|
this._ptr = ptr || new Uint8Array(this._size);
|
|
|
|
this._data = new DataView(this._ptr.buffer);
|
2024-05-27 18:26:44 -04:00
|
|
|
|
|
|
|
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
|