-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcell.js
41 lines (38 loc) · 913 Bytes
/
cell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Cell {
constructor(i, j, value) {
this.i = i;
this.j = j;
// Is an array passed in?
if (value instanceof Array) {
// Set options to the provided array
this.options = value;
} else {
// Fill array with all the options
this.options = [];
for (let i = 0; i < value; i++) {
this.options[i] = i;
}
}
this.collapsed = this.options.length == 1;
}
draw(w, h) {
if (this.collapsed) {
let index = this.options[0];
image(tiles[index].img, this.i * w, this.j * h, w, h);
} else {
noFill();
stroke(51);
rect(this.i * w, this.j * h, w, h);
}
}
validOptions(dir) {
let validOptions = new Set();
for (let option of this.options) {
let valid = tiles[option].compatibles(dir);
for (let opt of valid) {
validOptions.add(opt);
}
}
return validOptions;
}
}