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

73 lines
1.8 KiB
JavaScript
Raw Normal View History

import Vector3 from "./Vector3"
2024-05-29 20:47:19 -04:00
import Stats from "./Stats"
import DerivedStats from "./DerivedStats"
2024-05-29 20:47:19 -04:00
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
*/
2024-05-29 20:47:19 -04:00
get Stats() {
return new Stats({}, new Uint8Array(this._ptr.slice(36, 41)));
}
2024-05-29 20:47:19 -04:00
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
*/
2024-05-29 20:47:19 -04:00
get Skills() {
return new Skills({}, new Uint8Array(this._ptr.slice(49, 65)));
}
2024-05-29 20:47:19 -04:00
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];
}
}
2024-05-27 19:26:24 -04:00
}
export default Entity