@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
54 lines (44 loc) • 1.19 kB
JavaScript
import { BaseMatcher } from "../BaseMatcher.js";
import { NullDescription } from "../NullDescription.js";
import { AllOf } from "./AllOf.js";
import { AnyOf } from "./AnyOf.js";
export class CombinableMatcher extends BaseMatcher {
/**
* @type {Matcher}
*/
#matcher
/**
*
* @param {Matcher} matcher
*/
constructor(matcher) {
super();
this.#matcher = matcher;
}
matches(item, mismatch_description) {
if (!this.#matcher.matches(item, NullDescription.INSTANCE)) {
this.#matcher.describeMismatch(item, mismatch_description);
return false;
}
return true;
}
describeTo(description) {
description.appendDescriptionOf(this.#matcher);
}
/**
*
* @param {Matcher} other
* @return {CombinableMatcher}
*/
and(other) {
return new CombinableMatcher(new AllOf([this.#matcher, other]))
}
/**
*
* @param {Matcher} other
* @return {CombinableMatcher}
*/
or(other) {
return new CombinableMatcher(new AnyOf([this.#matcher, other]));
}
}