@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
39 lines (30 loc) • 931 B
JavaScript
import { BaseMatcher } from "../BaseMatcher.js";
import { Matcher } from "../Matcher.js";
import { NullDescription } from "../NullDescription.js";
export class AllOf extends BaseMatcher {
/**
* @type {Matcher[]}
*/
#matchers;
/**
*
* @param {Matcher[]} matchers
*/
constructor(matchers) {
super();
this.#matchers = matchers;
}
matches(item, mismatch_description) {
for (const matcher of this.#matchers) {
if (!matcher.matches(item, NullDescription.INSTANCE)) {
mismatch_description.appendDescriptionOf(matcher).appendText(" ");
matcher.describeMismatch(item, mismatch_description);
return false;
}
}
return true;
}
describeTo(description) {
description.appendList("(", ' and ', ")", this.#matchers);
}
}