-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathField.js
63 lines (54 loc) · 1.45 KB
/
Field.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
*/
if (ps.flags.SHOW_LOGS) console.log("Creating the Field.");
ps.Field = function () {
let that = this;
/*
Initalization function
*/
that.init = function () {
that.vectors = new HashMap();
}
/*
Add a new vector to the Field's HashMap
*/
that.add = function (x, y) {
let temp = new ps.Vec2(x, y);
that.vectors.set(temp.hash, temp);
that.updateButtons();
if (ps.flags.SHOW_LOGS) console.log(temp.toString() + " was added to the field.");
}
/*
Delete a vector from the Field's HashMap
*/
that.delete = function(x,y) {
that.vectors.delete( ps.hashCoords({x: x, y: y}) );
that.updateButtons();
if(ps.flags.SHOW_LOGS) console.log( "<" + x + ", " + y + "> was deleted from the field." );
}
/*
Clears the Field of all vectors.
*/
that.clear = function () {
that.vectors.clear();
that.updateButtons();
}
that.toString = function () {
console.log("Field vectors in the order the HashMap is holding them:\n");
that.vectors.forEach(function (vector) {
console.log(vector + "\n");
});
}
/*
Update any buttons that can only be updated from the Field remotely
*/
that.updateButtons = function () {
if (that.vectors.size === 0) {
ps.buttonToDisabled($("#polyomino-field-solve"));
} else {
ps.buttonToAccent($("#polyomino-field-solve"));
}
}
// initalize
that.init();
}