You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tobspr_shapez.io/src/js/core/explained_result.js

41 lines
913 B

export class ExplainedResult {
constructor(result = true, reason = null, additionalProps = {}) {
/** @type {boolean} */
this.result = result;
/** @type {string} */
this.reason = reason;
// Copy additional props
for (const key in additionalProps) {
this[key] = additionalProps[key];
}
}
isGood() {
return !!this.result;
}
isBad() {
return !this.result;
}
static good() {
return new ExplainedResult(true);
}
static bad(reason, additionalProps) {
return new ExplainedResult(false, reason, additionalProps);
}
static requireAll(...args) {
for (let i = 0; i < args.length; ++i) {
const subResult = args[i].call();
if (!subResult.isGood()) {
return subResult;
}
}
return this.good();
}
}