-
Notifications
You must be signed in to change notification settings - Fork 1
/
Constructor.js
56 lines (50 loc) · 1.5 KB
/
Constructor.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
/*
Constructor represents a grid used for collecting and manipulative 2D vectors.
It stores a map of vectors for quickly inserting and removing vectors to pass to the Palette when making a Polyomino
*/
if(ps.flags.SHOW_LOGS) console.log("Creating the Constructor.");
ps.Constructor = function() {
let that = this;
/*
Initalization function
*/
that.init = function() {
that.vectors = new HashMap();
}
/*
Add a new vector to the Constructor'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 constructor." );
}
/*
Delete a vector from the Constructor'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 constructor." );
}
/*
Clears the Constructor of all vectors.
*/
that.clear = function() {
that.vectors.clear();
that.updateButtons();
}
/*
Update any buttons that can only be updated from the Constructor remotely
*/
that.updateButtons = function() {
if( that.vectors.size === 0 ) {
ps.buttonToDisabled($("#polyomino-constructor-save"));
} else {
ps.buttonToAccent($("#polyomino-constructor-save"));
}
}
// init
that.init();
}