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

73 lines
1.8 KiB
JavaScript

import Vector3 from "./Vector3"
import Stats from "./Stats"
import DerivedStats from "./DerivedStats"
import Skills from "./Skills"
class Entity {
/**
* Name of the 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);
}
/**
* 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
*/
get Stats() {
return new Stats({}, new Uint8Array(this._ptr.slice(36, 41)));
}
set Stats(v) {
this._data.set(v.bytes(), 36);
}
/**
* Stats that are derived from skills and base stats
*/
get DerivedStats() {
return new DerivedStats({}, new Uint8Array(this._ptr.slice(41, 49)));
}
set DerivedStats(v) {
this._data.set(v.bytes(), 41);
}
/**
* Stuff that your character can do
*/
get Skills() {
return new Skills({}, new Uint8Array(this._ptr.slice(49, 65)));
}
set Skills(v) {
this._data.set(v.bytes(), 49);
}
/**
* get the struct representation of the object
*/
get bytes() {
return new Uint8Array(this._ptr);
}
/**
* constructor
*/
constructor(init = {}, ptr = undefined) {
this._size = 65;
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