-
Notifications
You must be signed in to change notification settings - Fork 3
/
DualController.js
70 lines (51 loc) · 1.89 KB
/
DualController.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
64
65
66
67
68
69
70
/*
Copyright 2011 Brandon Lockaby
This file is part of JSPDP.
https://github.com/brandon-lockaby/JSPDP
JSPDP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
JSPDP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JSPDP. If not, see <http:https://www.gnu.org/licenses/>.
*/
JSPDP.DualController = function() {
}
var proto = (JSPDP.DualController.prototype = new JSPDP.TableauUI());
proto.init = function(settings) {
JSPDP.TableauUI.prototype.init.call(this, settings);
this.keyboardCursor = new JSPDP.KeyboardCursor().init(settings);
this.touchController = new JSPDP.TouchController().init(settings);
this.touchController.onSelect.subscribe(this.handleSelect.bind(this));
this.tableau.onSwap.subscribe(this.handleSwap.bind(this));
return this;
};
proto.handleSelect = function(selection) {
var row = selection.tableau_pos.row;
var col = selection.tableau_pos.col;
if(col > 0 && col > this.keyboardCursor.position.col) {
--col;
}
if(!this.tableau.bounds(row, col + 1)) --col;
if(!this.tableau.bounds(row, col)) return;
this.keyboardCursor.moveTo(row, col);
};
proto.handleSwap = function(panels) {
var row = panels[0].row;
var col = panels[0].col;
if(panels[1].col < col) col = panels[1].col;
this.keyboardCursor.moveTo(row, col);
};
proto.refresh = function() {
this.keyboardCursor.refresh();
};
proto.update = function() {
return this.keyboardCursor.update();
};
proto.draw = function(ctx) {
this.keyboardCursor.draw(ctx);
};