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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
_util.onload(function() {
try {
var divs = document.getElementsByClassName("kifu-editor");
[].forEach.call(divs, function(div) { new _kifu_editor(div); });
} catch (e) {
alert(e.name + ": " + e.message);
}
});
function _kifu_editor(div) {
div.classList.add("shogi-container");
var params = [
[_label.KYOUCHOU, 0, _str.SURU, true, _str.SHINAI, false],
[_label.HANTEN, 1, _str.SURU, true, _str.SHINAI, false],
[_label.TEBAN, 0, _str.KOUGO, true, _str.JIYUU, false],
[_label.SPEED, 2, _str.HAYAI, 100, _str.FUTSUU, 200, _str.OSOI, 400]
];
var setting = new _setting_panel(div, params, function(index, val) {
switch (index) {
case 0: view.set_kyouchou(val == "true"); break;
case 1: view.set_hanten(val == "true"); break;
case 2: view.set_teban(val == "true"); break;
case 3: controller.set_speed(parseInt(val)); break;
}
if (index <= 1) view.clean_and_draw();
if (index == 1 && view.on_banmen_edit()) komabako.draw();
else if (index == 2) view.clean_and_draw(true);
});
var view = new _edit_view(div);
var kyokumen = _kyokumen.get_hirate_kyokumen();
view.set_kyokumen(kyokumen);
var panel = _util.add_panel(div);
var data = {};
var kifu_io = new _kifu_io();
_util.add_menu(panel, _label.MAIN, function(index) {
if (index == 1) { // 盤面編集
var b_kifu = !controller.get_sasite_tree().is_empty();
if (b_kifu && !confirm(_war.LOST_KIFU))
return;
if (b_kifu) controller.set_sasite_tree(new _sasite_tree());
view.get_kyokumen().sasite = _sasite.get_empty_sasite();
fill_komabako();
komabako.draw();
view.banmen_edit_start();
} else if (index == 2) { // 棋譜編集
setting.show();
view.kifu_edit_start();
} else if (index == 3) { // 棋譜読書
data[_key.PLAYER] = view.get_player_names();
data[_key.MOCHIGOMA] = view.get_mochigoma_mode();
data[_key.KYOKUMEN] = controller.get_start_kyokumen();
data[_key.SASITE] = controller.get_sasite_tree();
ta_kifu.value = kifu_io.data_kifu(data);
}
_util.change_panel(div, index + 1);
});
function fill_mochigoma() {
var mode = view.get_mochigoma_mode();
if (mode == 0) return;
var kyokumen = view.get_kyokumen();
if (mode == 1) kyokumen.sente = [0, 0, 0, 0, 0, 0, 0];
else kyokumen.gote = [0, 0, 0, 0, 0, 0, 0];
var hako = kyokumen.get_komabako().slice(0, 7);
if (mode == 1) kyokumen.sente = hako;
else kyokumen.gote = hako;
}
function fill_komabako() {
var mode = view.get_mochigoma_mode();
var kyokumen = view.get_kyokumen();
if (mode == 1) kyokumen.sente = [0, 0, 0, 0, 0, 0, 0];
else if (mode == 2) kyokumen.gote = [0, 0, 0, 0, 0, 0, 0];
komabako.set_hako(kyokumen.get_komabako());
}
panel = _util.add_panel(div);
_util.add_menu(panel, _label.INFO, function(index) {
if (index < 2) {
var kyokumen = controller.get_start_kyokumen();
var b_hirate = kyokumen.equals(_kyokumen.get_hirate_kyokumen());
var b_empty = kyokumen.equals(_kyokumen.get_empty_kyokumen());
var b_kifu = !controller.get_sasite_tree().is_empty();
if ((index == 0 && b_hirate) || (index == 1) && b_empty) return;
if ((!b_kifu && (b_hirate || b_empty)) ||
confirm((b_kifu) ? _war.LOST_KIFU : _war.LOST_KYOKUMEN)) {
if (b_kifu) controller.set_sasite_tree(new _sasite_tree());
view.set_kyokumen((index == 0) ?
_kyokumen.get_hirate_kyokumen() :
_kyokumen.get_empty_kyokumen());
view.clean_and_draw();
}
} else if (index == 2) { // 残り全部
view.set_mochigoma_mode((view.get_mochigoma_mode() + 2) % 3);
view.clean_and_draw();
} else if (index == 3) { // 設定終了
fill_mochigoma();
_util.change_panel(div, 0);
}
});
var table = document.createElement("table");
var tr, td;
var text;
var texts = new Array();
var val;
var names;
function set_texts() {
names = view.get_player_names();
for (var i = 0; i < 4; i++)
texts[i].value = names[i];
}
function text_changed(e) {
var target = e.target;
var s = target.value;
if (s.indexOf(",") != -1) {
target.value = s.replace(/,/g, "");
return;
}
names[texts.indexOf(target)] = s;
view.clean_and_draw();
}
for (var i = 0; i < 3; i++) {
tr = document.createElement("tr");
for (var j = 0; j < 3; j++) {
td = document.createElement("td");
tr.appendChild(td);
val = _label.NAMES[i][j];
if ((typeof val) == "string") {
_util.set_text(td, val);
continue;
}
text = document.createElement("input");
text.type = "text";
text.maxLength = parseInt(val);
text.addEventListener("input", text_changed);
text.addEventListener("change", text_changed);
texts.push(text);
td.appendChild(text);
}
table.appendChild(tr);
}
set_texts();
panel.appendChild(table);
panel = _util.add_panel(div);
var komabako = new _komabako(panel, view);
komabako.draw();
view.set_komabako_callback(komabako.draw);
view.clean_and_draw();
var pain = document.createElement("div");
_util.add_menu(pain, _label.BANMEN, function(index) {
if (index == 0) { // 盤面反転
setting.toggle_hanten();
} else if (index == 1) { // 編集終了
view.edit_end();
fill_mochigoma();
controller.update();
_util.change_panel(div, 0);
}
});
panel.appendChild(pain);
panel = _util.add_panel(div);
var controller = new _controller_panel(panel, view, function(count, kyokumen, sasite) {
var s = (count == 0) ? "開始局面" : count + "手目";
var end;
if (!sasite.is_empty_sasite()) {
end = sasite.option & 0xf000;
if (end != 0) s += " " + _util.opt_moji(end);
if (count == 0 || end != 0)
s += "(" + sasite.to_string() + "まで)";
else s += " " + sasite.to_string();
}
setting.set_sasite(s);
view.set_kyokumen(kyokumen);
view.clean_and_draw(true);
});
controller.update();
view.set_sasite_callback(function(sasite) {
setTimeout(controller.update, 0, sasite);
});
_util.add_menu(panel, _label.KIFU, function(index) {
controller.stop_repeat_timer();
if (index == 0) { // 削除
if (!controller.can_remove() ||
!confirm(_war.REMOVE_AFTER)) return;
controller.remove_after();
} else if (index == 1) { // 開始局面
if (!controller.can_remove() ||
!confirm(_war.REMOVE_BEFORE)) return;
controller.remove_before();
} else if (index == 2) { // 終局情報
var sasite = view.get_kyokumen().sasite;
var end = sasite.option & 0xf000;
if (end == 0) end = 0x1000;
else end = (end << 1) & 0xf000;
sasite.option &= ~0xf000;
sasite.option |= end;
controller.update();
} else if (index == 3) { // 編集終了
view.edit_end();
view.clean_and_draw(true);
setting.close();
setting.hide();
_util.change_panel(div, 0);
}
});
panel = _util.add_panel(div);
_util.add_menu(panel, _label.IO, function(index) {
if (index == 0) { // 棋譜読込
try {
data = kifu_io.data_from_kifu(ta_kifu.value);
} catch (e) {
alert(e.message + ": " + kifu_io.get_err_info());
return;
}
view.set_player_names(data[_key.PLAYER]);
set_texts();
view.set_mochigoma_mode(data[_key.MOCHIGOMA]);
view.set_kyokumen(data[_key.KYOKUMEN]);
controller.set_sasite_tree(data[_key.SASITE]);
controller.update();
_util.change_panel(div, 0);
}
else if (index == 1) { // 中止
_util.change_panel(div, 0);
}
});
var ta_kifu = document.createElement("textarea");
panel.appendChild(ta_kifu);
_util.change_panel(div, 0);
}