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

97 lines
3.0 KiB
JavaScript
Raw Normal View History

2024-06-30 21:12:58 -04:00
/**
* @typedef {Object} Stats User stats
* @property {Uint8} u8 Physical attack damage + Equipment Load
* @property {Uint8} u8 HP + Dmg mitigation for physical damage, how much stamina you have
* @property {Uint8} u8 Use/build steampunk gadgets + be able to read specific logical papers
* @property {Uint8} u8 Number of magic / special attack / skills you can remember at one time.
* @property {Uint8} u8 how good you can talk, persuade, etc.
*/
2024-05-29 20:47:19 -04:00
class Stats {
/**
* Physical attack damage + Equipment Load
2024-06-30 21:12:58 -04:00
* @return {Uint8} gets the value of Strength
*/
2024-05-29 20:47:19 -04:00
get Strength() {
return this._data.getUint8(0, true);
}
2024-06-30 21:12:58 -04:00
/**
* Physical attack damage + Equipment Load
* @param {Uint8} sets the value of Strength
*/
2024-05-29 20:47:19 -04:00
set Strength(v) {
return this._data.setUint8(0, v, true);
}
/**
* HP + Dmg mitigation for physical damage, how much stamina you have
2024-06-30 21:12:58 -04:00
* @return {Uint8} gets the value of Endurance
*/
2024-05-29 20:47:19 -04:00
get Endurance() {
return this._data.getUint8(1, true);
}
2024-06-30 21:12:58 -04:00
/**
* HP + Dmg mitigation for physical damage, how much stamina you have
* @param {Uint8} sets the value of Endurance
*/
2024-05-29 20:47:19 -04:00
set Endurance(v) {
return this._data.setUint8(1, v, true);
}
/**
* Use/build steampunk gadgets + be able to read specific logical papers
2024-06-30 21:12:58 -04:00
* @return {Uint8} gets the value of Intelligence
*/
2024-05-29 20:47:19 -04:00
get Intelligence() {
return this._data.getUint8(2, true);
}
2024-06-30 21:12:58 -04:00
/**
* Use/build steampunk gadgets + be able to read specific logical papers
* @param {Uint8} sets the value of Intelligence
*/
2024-05-29 20:47:19 -04:00
set Intelligence(v) {
return this._data.setUint8(2, v, true);
}
/**
* Number of magic / special attack / skills you can remember at one time.
2024-06-30 21:12:58 -04:00
* @return {Uint8} gets the value of Wisdom
*/
2024-05-29 20:47:19 -04:00
get Wisdom() {
return this._data.getUint8(3, true);
}
2024-06-30 21:12:58 -04:00
/**
* Number of magic / special attack / skills you can remember at one time.
* @param {Uint8} sets the value of Wisdom
*/
2024-05-29 20:47:19 -04:00
set Wisdom(v) {
return this._data.setUint8(3, v, true);
}
/**
* how good you can talk, persuade, etc.
2024-06-30 21:12:58 -04:00
* @return {Uint8} gets the value of Charisma
*/
2024-05-29 20:47:19 -04:00
get Charisma() {
return this._data.getUint8(4, true);
}
2024-06-30 21:12:58 -04:00
/**
* how good you can talk, persuade, etc.
* @param {Uint8} sets the value of Charisma
*/
2024-05-29 20:47:19 -04:00
set Charisma(v) {
return this._data.setUint8(4, v, true);
}
/**
2024-06-30 21:12:58 -04:00
* Constructs a new Stats
*
* @param {{Strength: Uint8, Endurance: Uint8, Intelligence: Uint8, Wisdom: Uint8, Charisma: Uint8, }} init The arguments to construct the object.
* @param {Uint8Array} ptr The pointer to the C struct.
*/
2024-05-29 20:47:19 -04:00
constructor(init = {}, ptr = undefined) {
this._size = 5;
2024-06-30 21:12:58 -04:00
this._ptr = ptr || new Uint8Array(this._size);
this._data = new DataView(this._ptr.buffer);
2024-05-29 20:47:19 -04:00
for (const key of Object.keys(init)) {
this[key] = init[key];
}
}
}
export default Stats