Files
the-beacon/reference/guardrails.js
Alexander Whitestone 88224b5d4d
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Successful in 11s
Smoke Test / smoke (pull_request) Failing after 21s
fix: chore: move dormant prototypes to reference/ directory (closes #197)
2026-04-15 22:31:08 -04:00

38 lines
1.1 KiB
JavaScript

/**
* DORMANT PROTOTYPE — moved from scripts/guardrails.js
*
* Why dormant: Has inline test code at the bottom — not production-ready
*
* To integrate (future):
* 1. Remove inline test code
* 2. Add <script src="reference/guardrails.js"> to index.html
* 3. Wire into game engine lifecycle
* 4. Add tests
*/
/**
* Symbolic Guardrails for The Beacon
* Ensures game logic consistency.
*/
class Guardrails {
static validateStats(stats) {
const required = ['hp', 'maxHp', 'mp', 'maxMp', 'level'];
required.forEach(r => {
if (!(r in stats)) throw new Error(`Missing stat: ${r}`);
});
if (stats.hp > stats.maxHp) return { valid: false, reason: 'HP exceeds MaxHP' };
return { valid: true };
}
static validateDebuff(debuff, stats) {
if (debuff.type === 'drain' && stats.hp <= 1) {
return { valid: false, reason: 'Drain debuff on critical HP' };
}
return { valid: true };
}
}
// Test
const playerStats = { hp: 50, maxHp: 100, mp: 20, maxMp: 50, level: 1 };
console.log('Stats check:', Guardrails.validateStats(playerStats));