forked from robx/pzprjs
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMenuConfig.js
More file actions
388 lines (353 loc) · 11.2 KB
/
Copy pathMenuConfig.js
File metadata and controls
388 lines (353 loc) · 11.2 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// MenuConfig.js v3.4.1
(function() {
//---------------------------------------------------------------------------
// ★MenuConfigクラス UI側の設定値を管理する
//---------------------------------------------------------------------------
var Config = pzpr.Puzzle.prototype.Config.prototype;
// メニュー描画/取得/html表示系
// Menuクラス
ui.menuconfig = {
list: null, // MenuConfigの設定内容を保持する
puzzle: null,
//---------------------------------------------------------------------------
// menuconfig.init() MenuConfigの初期化を行う
// menuconfig.add() 初期化時に設定を追加する
//---------------------------------------------------------------------------
init: function() {
this.list = {};
/* 正解自動判定機能 */
this.add("autocheck_mode", "simple", {
option: ["off", "simple", "guarded"]
});
/* per-solve autocheck status, turned off when complete */
this.add("autocheck_once", ui.puzzle.playeronly, {
volatile: true
});
this.add("keypopup", false); /* キーポップアップ (数字などのパネル入力) */
this.add("adjsize", true); /* 自動横幅調節 */
this.add(
"cellsizeval",
ui.windowWidth() <= 960 ? 36 : 48
); /* セルのサイズ設定用 */
this.add(
"fullwidth",
ui.windowWidth() < 600
); /* キャンバスを横幅いっぱいに広げる */
this.add("toolarea", true); /* ツールエリアの表示 */
this.add("inputmode", "auto", { volatile: true }); /* inputMode */
this.add("auxeditor_inputmode", "auto", { volatile: true });
this.add("lrinvert", false, {
volatile: true
}); /* マウスの左右ボタンを反転する設定 */
//Autosave feature. Not on by default, but persists once enabled
this.add("autosave", false, {
volatile: false
});
this.add("language", pzpr.lang, { option: ["en", "ja"] }); /* 言語設定 */
/* puzzle.configを一括で扱うため登録 */
this.puzzle = ui.puzzle;
for (var name in ui.puzzle.config.list) {
var item = ui.puzzle.config.list[name],
extoption = { puzzle: true };
for (var field in item.extoption) {
extoption[field] = item[field];
}
this.add(name, item.defval, extoption);
}
this.add("mode", !ui.puzzle.playmode ? "edit" : "play", {
option: ["edit", "play"],
puzzle: true
});
},
add: function(name, defvalue, extoption) {
Config.add.call(this, name, defvalue, extoption);
if (!!extoption && extoption.puzzle) {
var item = this.list[name];
item.volatile = item.puzzle = true;
}
},
//---------------------------------------------------------------------------
// menuconfig.sync() URL形式などによって変化する可能性がある設定値を同期する
//---------------------------------------------------------------------------
sync: function() {
var dirty = this.isDirty;
var idname = [];
switch (ui.puzzle.pid) {
case "yajilin":
case "lixloop":
case "retsurin":
idname = ["yajilin_out", "disptype_yajilin"];
break;
case "yajilin-regions":
idname = "yajilin_out";
break;
case "bosanowa":
idname = "disptype_bosanowa";
break;
case "interbd":
case "outofsight":
idname = "disptype_interbd";
break;
case "arukone":
idname = "dontpassallcell";
break;
case "aquarium":
idname = "aquarium_regions";
break;
case "country":
idname = "country_empty";
break;
case "voxas":
idname = "voxas_tatami";
break;
case "tren":
case "news":
idname = "tren_new";
break;
case "nuriuzu":
idname = "nuriuzu_connect";
break;
case "pentopia":
case "distopia":
idname = "pentopia_transparent";
break;
case "koburin":
idname = ["yajilin_out", "disptype_yajilin", "koburin_minesweeper"];
break;
case "akichi":
idname = "akichi_maximum";
break;
case "magnets":
idname = "magnets_anti";
break;
case "context":
idname = "context_marks";
break;
case "heyapin":
idname = "heyapin_overlap";
break;
case "bdwalk":
idname = "bdwalk_height";
break;
case "balloon":
idname = "balloon_adjacent";
break;
case "aqre":
idname = "aqre_borders";
break;
case "fillomino":
idname = "fillomino_tri";
break;
case "trizone":
idname = "trizone_ghost";
break;
case "slither":
case "tslither":
case "swslither":
case "myopia":
case "lineofsight":
idname = "slither_full";
break;
case "mashu":
case "geradeweg":
case "disloop":
case "midloop":
case "ovotovata":
case "balance":
case "turnaround":
case "turnrun":
case "icewalk":
case "waterwalk":
case "firewalk":
case "forestwalk":
case "morningwalk":
case "roboticwalk":
case "wataridori":
case "bhaibahan":
case "bwloop":
idname = "loop_full";
break;
}
if (typeof idname === "string") {
idname = [idname];
}
for (var i in idname) {
this.set(idname[i], ui.puzzle.getConfig(idname[i]));
}
this.set("variant", ui.puzzle.getConfig("variant"));
this.set("lrinvert", ui.puzzle.mouse.inversion);
this.set("autocmp", ui.puzzle.getConfig("autocmp"));
this.set("autoerr", ui.puzzle.getConfig("autoerr"));
this.isDirty = dirty;
},
//---------------------------------------------------------------------------
// menuconfig.getCurrentName() 指定されたidを現在使用している名前に変換する
//---------------------------------------------------------------------------
getCurrentName: Config.getCurrentName,
getNormalizedName: Config.getNormalizedName,
//---------------------------------------------------------------------------
// menuconfig.get() 各フラグの設定値を返す
// menuconfig.get() 各フラグの設定値を返す
// menuconfig.reset() 各フラグの設定値を初期化する
//---------------------------------------------------------------------------
get: Config.get,
set: function(argname, newval) {
var names = this.getNormalizedName(argname),
idname = names.name;
if (!this.list[idname]) {
return;
}
if (idname === "mode" || idname === "inputmode") {
ui.auxeditor.close();
}
if (idname === "mode") {
ui.puzzle.setMode(newval);
newval = !ui.puzzle.playmode ? "edit" : "play";
} else if (idname === "inputmode") {
ui.puzzle.mouse.setInputMode(newval);
newval = ui.puzzle.mouse.inputMode;
} else if (idname === "auxeditor_inputmode") {
ui.auxeditor.puzzle.mouse.setInputMode(newval);
newval = ui.auxeditor.puzzle.mouse.inputMode;
}
newval = this.setproper(names, newval);
if (idname === "language") {
pzpr.lang = newval;
} else if (this.list[idname].puzzle) {
ui.puzzle.setConfig(argname, newval);
}
if (
!this.list[idname].volatile ||
(ui.puzzle.config.list[argname] &&
!ui.puzzle.config.list[argname].volatile)
) {
this.isDirty = true;
}
this.configevent(idname, newval);
},
reset: Config.reset,
//---------------------------------------------------------------------------
// menuconfig.restore() 保存された各種設定値を元に戻す
// menuconfig.save() 各種設定値を保存する
//---------------------------------------------------------------------------
restore: function() {
/* 設定が保存されている場合は元に戻す */
ui.puzzle.config.init();
this.init();
var json_puzzle = localStorage.getItem("pzprv3_config:puzzle");
var json_menu = localStorage.getItem("pzprv3_config:ui");
if (!!json_puzzle) {
this.setAll(JSON.parse(json_puzzle));
}
if (!!json_menu) {
this.setAll(JSON.parse(json_menu));
}
this.isDirty = false;
},
isDirty: false,
save: function() {
if (!this.isDirty) {
return;
}
try {
pzpr.util.store(
"pzprv3_config:puzzle",
JSON.stringify(ui.puzzle.saveConfig())
);
pzpr.util.store("pzprv3_config:ui", JSON.stringify(this.getAll()));
} catch (ex) {
console.warn(ex);
}
this.isDirty = false;
},
//---------------------------------------------------------------------------
// menuconfig.getList() 現在有効な設定値のリストを返す
//---------------------------------------------------------------------------
getList: Config.getList,
getexec: function(name) {
if (!this.list[name]) {
return false;
}
if (name === "mode") {
return !ui.puzzle.playeronly;
} else if (this.list[name].puzzle) {
return ui.puzzle.validConfig(name);
}
return true;
},
//---------------------------------------------------------------------------
// menuconfig.getAll() 全フラグの設定値を返す
// menuconfig.setAll() 全フラグの設定値を設定する
//---------------------------------------------------------------------------
getAll: Config.getAll,
setAll: function(setting) {
for (var key in setting) {
this.set(key, setting[key]);
}
this.list.autocheck_once.val = this.list.autocheck_mode.val !== "off";
},
//---------------------------------------------------------------------------
// menuconfig.setproper() 設定値の型を正しいものに変換して設定変更する
// menuconfig.valid() 設定値が有効なパズルかどうかを返す
//---------------------------------------------------------------------------
setproper: Config.setproper,
valid: function(idname) {
if (!this.list[idname]) {
return false;
}
if (idname === "keypopup") {
return ui.keypopup.paneltype[1] !== 0 || ui.keypopup.paneltype[3] !== 0;
} else if (idname === "mode") {
return !ui.puzzle.playeronly;
} else if (idname === "timer") {
return ui.puzzle.playeronly;
} else if (idname === "inputmode") {
return (
ui.puzzle.mouse.getInputModeList("play").length > 1 ||
(!ui.puzzle.playeronly &&
ui.puzzle.mouse.getInputModeList("edit").length > 1)
);
} else if (idname === "autocheck_mode" || idname === "autocheck_once") {
return ui.puzzle.playeronly && !ui.puzzle.getConfig("variant");
} else if (this.list[idname].puzzle) {
return ui.puzzle.validConfig(idname);
}
return true;
},
//---------------------------------------------------------------------------
// config.configevent() 設定変更時の動作を記述する (modeはlistener.onModeChangeで変更)
//---------------------------------------------------------------------------
configevent: function(idname, newval) {
if (idname === "autosave") {
var saveIcon = document.getElementById("saveicon");
saveIcon.style.display = newval ? null : "none";
}
if (!ui.menuarea.menuitem) {
return;
}
ui.setdisplay(idname);
switch (idname) {
case "keypopup":
ui.keypopup.display();
break;
case "adjsize":
case "cellsizeval":
case "fullwidth":
ui.adjustcellsize();
break;
case "autocheck_mode":
this.list.autocheck_once.val = newval !== "off";
break;
case "timer":
ui.toolarea.display();
break;
case "language":
ui.displayAll();
break;
case "lrinvert":
ui.puzzle.mouse.setInversion(newval);
break;
}
}
};
})();