-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwitchBoard.pde
105 lines (76 loc) · 2.16 KB
/
SwitchBoard.pde
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.TreeMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Map<Integer, Board> _boards = new HashMap<Integer, Board>();
Board _board;
int _lastMillis = millis();
public void setup() {
size(1200, 700);
frameRate(60);
Configuration.loadBoards(_boards, this);
_board = _boards.get(3);
}
public void draw() {
background(204);
TextUtils text = new TextUtils().Align(LEFT, TOP);
text.Text("fps: " + round(frameRate), 5, 5);
drawBoardSelectionTexts();
_board.Display();
}
private void drawBoardSelectionTexts() {
TextUtils text = new TextUtils().Align(LEFT, TOP);
Integer x = 850;
Integer y = 5;
text.Text("Geladen boards:", x, y);
y += 15;
for (Map.Entry<Integer, Board> entry : _boards.entrySet()) {
Integer index = entry.getKey();
Board board = entry.getValue();
y += 15;
text.Text((index + 1) + ". " + board.Name(), x, y);
}
y += 30;
text.Text("Commando's:", x, y);
y += 30;
text.Text("s: Huidige board opslaan.", x, y);
}
private void saveBoard(Board board) {
if (_board.Name() == "") {
println("ERROR: Cannot save board without name!");
return;
}
String boardPath = "boards/" + board.Name() + ".json";
println("Saving board to: " + boardPath);
BoardSerializer boardSerializer = new BoardSerializer(board);
saveJSONObject(boardSerializer.toJSONObject(), boardPath);
}
public void keyTyped() {
Integer boardCount = _boards.size();
Integer result = int(key);
if (result == 115) {
println("Saving board: " + _board.Name());
saveBoard(_board);
return;
} else if (result < 49 || result > 49 + boardCount - 1) {
println("User error: invalid key pressed for number of loaded boards!");
return;
}
Integer selectedIndex = result - 49;
_board = _boards.get(selectedIndex);
}
public void mouseMoved() {
_board.MouseOverCheck(mouseX, mouseY);
}
public void mouseDragged() {
// _board.MouseOverCheck(mouseX, mouseY);
}
public void mousePressed() {
_board.MousePressed(mouseX, mouseY);
}
public void mouseReleased() {
_board.MouseReleased(mouseX, mouseY);
}
public void mouseClicked() {
_board.MouseClicked(mouseX, mouseY, mouseButton);
}