-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfocus_engine.js
88 lines (83 loc) · 1.91 KB
/
focus_engine.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var FOCUS_ENGINE = new Studio.Plugin({
options: {
waitTime: 12, // frames
menu : null
},
init: function(a) {
stage.enableKeyboardInput();
this.wait = this.waitTime;
this.cur = 0;
this.wait = 0;
this.currentMenu = null;
this.active = true
this.loop = true;
if(this.options.menu){
this.setCurrentMenu(this.options.menu)
}
},
setCurrentMenu : function(menu, id){
this.currentMenu = menu;
this.cur = id || 0;
for(var i =0; i != menu.length; i++){
if(menu[i].reset) {
menu[i].reset();
menu[i]._focused = false;
}
}
if(menu[this.cur].focus){
menu[this.cur].focus();
}
},
_check_index : function(){
if(this.cur<0) {
if(!this.loop) {
this.cur = 0
}else{
this.cur = this.currentMenu.length-1
}
}
if(this.cur>=this.currentMenu.length){
if(!this.loop) {
this.cur = this.currentMenu.length-1
}else{
this.cur = 0
}
}
},
action: function(stage) {
// the action fires at the end of every stage loop.
// a = stage
this.wait--;
if(this.wait>0) return;
var old = this.cur;
if(stage.keys[38] || stage.keys["UP"]){
this.wait = this.options.waitTime;
this.cur--;
}
if(stage.keys[40] || stage.keys["DOWN"]){
this.wait = this.options.waitTime;
this.cur++;
}
this._check_index()
if(this.cur != old){
if(this.currentMenu[old].reset){
this.currentMenu[old].reset();
this.currentMenu[old]._focused = false;
}
if(this.currentMenu[this.cur].focus){
this.currentMenu[this.cur].focus();
this.currentMenu[this.cur]._focused = true;
}
}else{
if(!this.currentMenu[this.cur]._focused && this.currentMenu[this.cur].focus){
this.currentMenu[this.cur].focus();
this.currentMenu[this.cur]._focused = true;
}
}
if(stage.keys[13] || stage.keys[32] || stage.keys["A"]){
this.currentMenu[this.cur].action();
this.wait = this.options.waitTime*2;
this.currentMenu[this.cur].reset();
}
}
})