@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
46 lines (34 loc) • 968 B
JavaScript
import { CellFilter } from "./CellFilter.js";
import { assert } from "../../core/assert.js";
/**
* Converts {@link CellMatcher} output to 0 or 1
*/
export class CellFilterCellMatcher extends CellFilter {
constructor() {
super();
/**
*
* @type {CellMatcher}
*/
this.matcher = null;
}
initialize(grid, seed) {
this.matcher.initialize(grid, seed);
}
/**
*
* @param {CellMatcher} matcher
* @returns {CellFilterCellMatcher}
*/
static from(matcher) {
assert.defined(matcher, 'matcher');
assert.equal(matcher.isCellMatcher, true, 'matcher.isCellMatcher');
const r = new CellFilterCellMatcher();
r.matcher = matcher;
return r;
}
execute(grid, x, y, rotation) {
const isMatch = this.matcher.match(grid, x, y, rotation);
return isMatch ? 1 : 0;
}
}