import Vector3 from "./Vector3" import Stats from "./Stats" import DerivedStats from "./DerivedStats" import Skills from "./Skills" /** * @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 */ class Entity { /** * Name of the entity * @return {string} gets the value of Name */ get Name() { return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 24))); } /** * Name of the entity * @param {string} v sets the value of Name */ set Name(v) { 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); } /** * Vector3 of the entity in space * @return {Vector3} gets the value of Vector3 */ get Vector3() { return new Vector3({}, new Uint8Array(this._ptr.slice(24, 36))); } /** * Vector3 of the entity in space * @param {Vector3} sets the value of Vector3 */ set Vector3(v) { this._ptr.set(v._ptr, 24); } /** * Base stats * @return {Stats} gets the value of Stats */ get Stats() { return new Stats({}, new Uint8Array(this._ptr.slice(36, 41))); } /** * Base stats * @param {Stats} sets the value of Stats */ set Stats(v) { this._ptr.set(v._ptr, 36); } /** * Stats that are derived from skills and base stats * @return {DerivedStats} gets the value of DerivedStats */ get DerivedStats() { return new DerivedStats({}, new Uint8Array(this._ptr.slice(41, 49))); } /** * Stats that are derived from skills and base stats * @param {DerivedStats} sets the value of DerivedStats */ set DerivedStats(v) { this._ptr.set(v._ptr, 41); } /** * Stuff that your character can do * @return {Skills} gets the value of Skills */ get Skills() { return new Skills({}, new Uint8Array(this._ptr.slice(49, 65))); } /** * Stuff that your character can do * @param {Skills} sets the value of Skills */ set Skills(v) { this._ptr.set(v._ptr, 49); } /** * 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. */ constructor(init = {}, ptr = undefined) { this._size = 65; 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 Entity