1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00
tobspr_shapez.io/src/ts/core/explained_result.ts

33 lines
859 B
TypeScript
Raw Normal View History

2022-11-18 01:33:12 +00:00
export class ExplainedResult {
public result: boolean = result;
public reason: string = reason;
constructor(result = true, reason = null, additionalProps = {}) {
// Copy additional props
2022-11-18 15:20:54 +00:00
for (const key in additionalProps) {
2022-11-18 01:33:12 +00:00
this[key] = additionalProps[key];
}
}
2022-11-18 15:20:54 +00:00
isGood() {
2022-11-18 01:33:12 +00:00
return !!this.result;
}
2022-11-18 15:20:54 +00:00
isBad() {
2022-11-18 01:33:12 +00:00
return !this.result;
}
2022-11-18 15:20:54 +00:00
static good() {
2022-11-18 01:33:12 +00:00
return new ExplainedResult(true);
}
2022-11-18 15:20:54 +00:00
static bad(reason, additionalProps) {
2022-11-18 01:33:12 +00:00
return new ExplainedResult(false, reason, additionalProps);
}
2022-11-18 15:20:54 +00:00
static requireAll(...args) {
for (let i = 0; i < args.length; ++i) {
const subResult = args[i].call();
2022-11-18 01:33:12 +00:00
if (!subResult.isGood()) {
return subResult;
}
}
return this.good();
}
}