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
function _player_panel(div, callback) {
var panel = document.createElement("div");
panel.className = "player-panel";
var btn;
for (var i = 0; i < 5; i++) {
btn = document.createElement("button");
btn.textContent = _label.PLAYER[i];
btn.addEventListener(_pointer.PRESSED, mouse_down);
btn.addEventListener(_pointer.RELEASED, mouse_up);
panel.appendChild(btn);
}
var ta_comment = document.createElement("textarea");
panel.appendChild(ta_comment);
div.appendChild(panel);
var kyokumen_changed = callback;
var kyokumen_list = null;
var pos;
var count;
var play_timer = null;
function stop_player_timer() {
if (play_timer == null) return;
clearTimeout(play_timer);
play_timer = null;
}
var long_timer = null;
function stop_long_timer() {
if (long_timer == null) return;
clearTimeout(long_timer);
long_timer = null;
}
var step;
function mouse_down(e) {
stop_player_timer();
stop_long_timer();
var index = _label.PLAYER.indexOf(e.target.textContent);
if (index == 2) return; // 停止
step = index - 2;
long_timer = setTimeout(jump_pos, 1000);
}
var speed = 500;
function mouse_up(e) {
if (long_timer == null) return;
stop_long_timer();
if (step == -2 || step == 2) {
step = Math.sign(step);
play_timer = setInterval(next, speed);
}
next();
}
function jump_pos() {
long_timer = null;
if (step == -2) pos = 0;
else if (step == 2) pos = count;
else {
for (pos += step; pos >= 0 && pos <= count; pos += step) {
if (kyokumen_list[pos].sasite.comment != "")
break;
}
}
step = 0;
next();
}
function next() {
if (kyokumen_list == null) return;
pos += step;
if (pos <= 0 || pos >= count)
stop_player_timer();
pos = Math.min(Math.max(pos, 0), count);
var kyokumen = kyokumen_list[pos];
var sasite = kyokumen.sasite;
ta_comment.value = sasite.comment;
kyokumen_changed(pos, kyokumen, sasite);
}
this.set_data = function(data) {
var sasite_node = data[_key.SASITE];
var kyokumen = data[_key.KYOKUMEN];
kyokumen_list = [kyokumen];
var sasite_list;
var sasite;
while ((sasite_list = sasite_node.get_next_sasite()) != null) {
sasite = sasite_list[0];
kyokumen_list.push(
kyokumen = kyokumen.get_next_kyokumen(sasite));
sasite_node.move_sasite(sasite);
}
count = kyokumen_list.length - 1;
pos = 0;
step = 0;
next();
}
this.set_speed = function(val) {
speed = val;
if (play_timer == null) return;
clearInterval(play_timer);
play_timer = setInterval(next, speed);
}
}