forked from robx/pzprjs
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathConfig.js
More file actions
628 lines (605 loc) · 17.4 KB
/
Copy pathConfig.js
File metadata and controls
628 lines (605 loc) · 17.4 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
// Config.js v3.4.1
(function() {
//---------------------------------------------------------------------------
// ★Configクラス 設定値の値などを保持する
//---------------------------------------------------------------------------
var Config = (pzpr.Puzzle.prototype.Config = function(puzzle) {
this.puzzle = puzzle;
this.init();
});
Config.prototype = {
list: null /* 設定値 */,
//---------------------------------------------------------------------------
// config.init() 各設定値を初期化する
// config.add() 初期化時に設定を追加する
//---------------------------------------------------------------------------
init: function() {
this.list = {};
var touchDevice = pzpr.env.API.lowaccuracy || pzpr.env.API.touchevent;
/* 盤面表示設定 */
this.add("font", 1, {
option: [1, 2]
}); /* 文字の描画 1:ゴシック 2:明朝 */
this.add("cursor", true); /* カーソルの表示 */
this.add("trialmarker", true); /* show trial marker */
this.add("timer", true); /* show timer */
this.add("irowake", false, { variety: true }); /* 線の色分け */
this.add("irowakeblk", false, { variety: true }); /* 黒マスの色分け */
this.add("dispmove", true); /* 線で動かすパズルで実際に動いたように描画 */
this.add("disptype_yajilin", 1, {
option: [1, 2]
}); /* yajilin: 表示形式 */
this.add("disptype_bosanowa", 1, {
option: [1, 2, 3]
}); /* bosanowa: 表示形式 */
this.add("disptype_interbd", 3, {
option: [1, 2, 3]
}); /* interbd: Clue display mode */
this.add("snakebd", false); /* hebi: へびの境界線を表示する */
this.add(
"ensquare",
true
); /* tajmahal: Only draw given from square centers */
this.add("context_marks", true);
this.add("dispqnumbg", false); /* yinyang: 問題のまるに背景色をつける */
this.add("undefcell", true); /* shugaku: 未確定マスはグレー表示にする */
this.add("mouseonly", false); /* lollipops: Alternative mouse input */
this.add(
"patchwork_leftaux",
true
); /* patchwork: Alternative mouse input */
this.add("squarecell", true); /* セルは正方形にする */
/* 入力方法設定 */
this.add("use", !touchDevice ? 1 : 2, {
option: [1, 2]
}); /* 黒マスの入力方法 */
this.add("use_tri", 1, {
option: [1, 2, 3]
}); /* shakashaka: 三角形の入力方法 */
this.add(
"support_tri",
true
); /* shakashaka: 三角形の入力補助 (for 2つ以上の壁に接したCell) */
this.add("bgcolor", false); /* slither 背景色入力 */
this.add(
"singlenum",
!touchDevice
); /* hanare: 部屋に回答数字を一つだけ入力 */
this.add("singleregion", true); /* parquet: Unshade all other regions */
this.add("enline", true); /* kouchoku: 線は点の間のみ引ける */
this.add("lattice", true); /* kouchoku: 格子点チェック */
/* 回答お助け機能 */
this.add("autocmp", true, {
variety: true
}); /* 数字 or kouchokuの正解の点をグレーにする */
this.add("autoerr", false, {
variety: true
}); /* hitori:ひとくれの重複した数字を表示, gokigen,wagiri:斜線の色分け */
/* 正解判定 */
this.add("multierr", false); /* エラー判定で複数エラーを出力する */
this.add(
"forceallcell",
false
); /* fillomino: すべての数字が入っている時のみ正解とする */
/* puzzle variant rules; must defaut to false */
this.add("dontpassallcell", false, {
variant: true,
volatile: true
}); /* arukone: don't require passing all cells */
this.add("aquarium_regions", false, {
variant: true,
volatile: true
}); /* aquarium: Rule variation for disconnected cells in one region */
this.add("country_empty", false, { variant: true, volatile: true });
this.add("voxas_tatami", false, {
variant: true,
volatile: true
}); /* voxas: Rule variation for disallowing crossing borders */
this.add("tren_new", false, {
variant: true,
volatile: true
}); /* tren: Rule variation for connecting unused cells */
this.add("nuriuzu_connect", false, {
variant: true,
volatile: true
}); /* nuriuzu: Rule variation for shaded connectivity */
this.add("balloon_adjacent", false, {
variant: true,
volatile: true
}); /* balloon: Disallow strings being adjacent */
this.add("bdwalk_height", false, {
variant: true,
volatile: true
}); /* bdwalk: Rule variation for allowing any height */
this.add("pentopia_transparent", false, {
variant: true,
volatile: true
}); /* pentopia: Allow shading clues */
this.add("yajilin_out", false, {
variant: true,
volatile: true
}); /* yajilin: All shaded cells are outside the loop */
this.add("koburin_minesweeper", false, {
variant: true,
volatile: true
}); /* koburin: Orthogonal and diagonal clues */
this.add("akichi_maximum", false, {
variant: true,
volatile: true
}); /* akichi: Numbers don't need to be attained */
this.add("magnets_anti", false, {
variant: true,
volatile: true
}); /* magnets: Adjacent poles of different magnets must be equal */
this.add("heyapin_overlap", false, {
variant: true,
volatile: true
}); /* heyapin: Pins must overlap at least 2 regions */
this.add("aqre_borders", false, {
variant: true,
volatile: true
}); /* Borders must touch exactly one shaded cell */
this.add("fillomino_tri", false, {
variant: true,
volatile: true
}); /* Maximum number is 3 */
this.add("trizone_ghost", false, {
variant: true,
volatile: true
}); /* Groups may have no number */
this.add("lapaz_liar", false, {
variant: true,
volatile: true
}); /* Clues may be erased by shading over them */
this.add("slither_full", false, {
variant: true,
volatile: true
}); /* All vertices must be visited */
this.add("loop_full", false, {
variant: true,
volatile: true
}); /* All cells must be visited */
/* generic variant */
this.add("variant", false, { variant: true, volatile: true });
this.add("variantid", "", { volatile: true });
/* EDITORのみ */
this.add("discolor", false); /* tentaisho: 色分け無効化 */
/* その他の特殊項目(保存なし) */
this.add("uramashu", false, { volatile: true }); /* 裏ましゅにする */
},
add: function(name, defvalue, extoption) {
if (!extoption) {
extoption = {};
}
var item = {
val: defvalue,
defval: defvalue,
volatile: !!(extoption.volatile || extoption.variant),
extoption: extoption // stored for the benefit of ui.MenuConfig
};
if (!!extoption.option) {
item.option = extoption.option;
}
if (!!extoption.variety) {
item.variety = {};
}
if (!!extoption.variant) {
item.variant = true;
}
this.list[name] = item;
},
//---------------------------------------------------------------------------
// config.getCurrentName() 以前のconfig名から現在使用している名称を取得する
// config.getNormalizedName() Config名が@付きだった場合varietyのpidを返す
//---------------------------------------------------------------------------
getCurrentName: function(name) {
switch (name) {
case "color_qanscolor":
name = "color_shadecolor";
break;
case "autocmp_area":
if (this.getexec("autocmp")) {
name = "autocmp";
}
break;
case "autocmp_border":
if (this.getexec("autocmp")) {
name = "autocmp";
}
break;
}
return name;
},
getNormalizedName: function(argname) {
var info = { name: argname };
if (argname.match(/\@/)) {
var splitted = argname.split(/\@/);
info.name = splitted[0];
var pid = pzpr.variety.toPID(splitted[1]);
if (!!pid) {
info.pid = pid;
}
}
info.name = this.getCurrentName(info.name);
return info;
},
//---------------------------------------------------------------------------
// config.get() 各フラグの設定値を返す
// config.set() 各フラグの設定値を設定する
// config.reset()各フラグの設定値を初期値に戻す
//---------------------------------------------------------------------------
get: function(argname) {
var names = this.getNormalizedName(argname),
name = names.name;
var item = this.list[name];
if (!item) {
return null;
}
if (!!item.variety) {
var pid = names.pid !== void 0 ? names.pid : this.puzzle.pid;
if (item.variety[pid] !== void 0) {
return item.variety[pid];
}
}
return item.val;
},
set: function(argname, newval) {
var names = this.getNormalizedName(argname),
name = names.name;
if (!this.list[name]) {
return;
}
newval = this.setproper(names, newval);
this.configevent(name, newval);
this.puzzle.emit("config", name, newval);
},
reset: function(argname) {
var names = this.getNormalizedName(argname);
var item = this.list[names.name];
if (!item) {
return;
}
if (!!item.variety && !names.pid) {
item.variety = {};
this.set(names.name, item.defval);
} else {
this.set(argname, item.defval);
}
},
//---------------------------------------------------------------------------
// config.getList() 現在有効な設定値のリストを返す
//---------------------------------------------------------------------------
getList: function() {
var conf = {};
for (var idname in this.list) {
if (this.getexec(idname)) {
conf[idname] = this.get(idname);
}
}
return conf;
},
getvariant: function(name) {
var item = this.list[name];
if (!item) {
return null;
}
return item.variant;
},
getVariants: function() {
var conf = {};
for (var key in this.list) {
var item = this.list[key];
if (!item.variant) {
continue;
}
if (this.getexec(key)) {
conf[key] = this.get(key);
}
}
return conf;
},
//---------------------------------------------------------------------------
// config.getAll() 全フラグの設定値を返す
// config.setAll() 全フラグの設定値を設定する
//---------------------------------------------------------------------------
getAll: function() {
var object = {};
for (var key in this.list) {
var item = this.list[key];
if (item.volatile) {
continue;
}
if (item.val !== item.defval) {
object[key] = item.val;
}
if (!item.variety) {
continue;
}
for (var pid in item.variety) {
if (item.variety[pid] !== item.defval) {
object[key + "@" + pid] = item.variety[pid];
}
}
}
return object;
},
setAll: function(settings) {
this.init();
for (var key in settings) {
this.set(key, settings[key]);
}
},
//---------------------------------------------------------------------------
// config.setproper() 設定値の型を正しいものに変換して設定変更する
//---------------------------------------------------------------------------
setproper: function(names, newval) {
var name = names.name;
var item = this.list[name];
switch (typeof item.defval) {
case "boolean":
newval = !!newval;
break;
case "number":
newval = +newval;
break;
case "string":
newval = "" + newval;
break;
}
if (!item.option || item.option.indexOf(newval) >= 0) {
if (!!item.variety) {
var pid = names.pid !== void 0 ? names.pid : this.puzzle.pid;
if (!!pid) {
item.variety[pid] = newval;
}
} else {
item.val = newval;
}
}
return newval;
},
//---------------------------------------------------------------------------
// config.getexec() 設定値を現在のパズルで有効かどうか返す
//---------------------------------------------------------------------------
getexec: function(name) {
var puzzle = this.puzzle,
pid = puzzle.pid,
EDITOR = !puzzle.playeronly,
exec = false;
switch (name) {
case "use":
exec = puzzle.mouse.use;
break;
case "use_tri":
exec = pid === "shakashaka";
break;
case "support_tri":
exec = pid === "shakashaka";
break;
case "dispmove":
exec = puzzle.board.linegraph.moveline;
break;
case "disptype_bosanowa":
exec = pid === "bosanowa";
break;
case "context_marks":
exec = pid === "context";
break;
case "disptype_yajilin":
exec =
pid === "yajilin" ||
pid === "koburin" ||
pid === "lixloop" ||
pid === "retsurin";
break;
case "disptype_interbd":
exec =
pid === "interbd" || (pid === "outofsight" && !puzzle.board.isMono);
break;
case "bgcolor":
exec = pid === "slither" || pid === "myopia" || pid === "swslither";
break;
case "irowake":
exec = puzzle.painter.irowake;
break;
case "irowakeblk":
exec = puzzle.painter.irowakeblk;
break;
case "snakebd":
exec = pid === "hebi";
break;
case "ensquare":
exec = pid === "tajmahal";
break;
case "dispqnumbg":
exec = pid === "yinyang";
break;
case "mouseonly":
exec = pid === "lollipops" || pid === "magnets";
break;
case "patchwork_leftaux":
exec = pid === "patchwork" || pid === "trizone";
break;
case "undefcell":
exec =
pid === "shugaku" || pid === "lightshadow" || pid === "nibunnogo";
break;
case "autocmp":
exec = !!puzzle.painter.autocmp;
break;
case "autoerr":
exec =
pid === "hitori" ||
pid === "gokigen" ||
pid === "wagiri" ||
pid === "narrow" ||
pid === "ubahn";
break;
case "singlenum":
exec = pid === "hanare" || pid === "putteria" || pid === "twinarea";
break;
case "singleregion":
exec = pid === "parquet";
break;
case "enline":
case "lattice":
exec = pid === "kouchoku" || pid === "angleloop";
break;
case "discolor":
exec = EDITOR && pid === "tentaisho";
break;
case "uramashu":
exec = pid === "mashu";
break;
case "forceallcell":
exec =
pid === "fillomino" ||
pid === "symmarea" ||
pid === "snakepit" ||
pid === "keywest" ||
pid === "topo";
break;
case "dontpassallcell":
exec = pid === "arukone";
break;
case "aquarium_regions":
exec = pid === "aquarium";
break;
case "country_empty":
exec = pid === "country";
break;
case "voxas_tatami":
exec = pid === "voxas";
break;
case "tren_new":
exec = pid === "tren" || pid === "news";
break;
case "nuriuzu_connect":
exec = pid === "nuriuzu";
break;
case "bdwalk_height":
exec = pid === "bdwalk";
break;
case "balloon_adjacent":
exec = pid === "balloon";
break;
case "pentopia_transparent":
exec = pid === "pentopia" || pid === "distopia";
break;
case "koburin_minesweeper":
exec = pid === "koburin";
break;
case "akichi_maximum":
exec = pid === "akichi";
break;
case "magnets_anti":
exec = pid === "magnets";
break;
case "heyapin_overlap":
exec = pid === "heyapin";
break;
case "aqre_borders":
exec = pid === "aqre";
break;
case "fillomino_tri":
exec = pid === "fillomino";
break;
case "yajilin_out":
exec =
[
"yajilin",
"yajilin-regions",
"koburin",
"lixloop",
"retsurin"
].indexOf(pid) >= 0;
break;
case "slither_full":
exec =
[
"slither",
"tslither",
"swslither",
"myopia",
"lineofsight"
].indexOf(pid) >= 0;
break;
case "lapaz_liar":
exec = pid === "lapaz";
break;
case "trizone_ghost":
exec = pid === "trizone";
break;
case "loop_full":
exec =
[
"mashu",
"geradeweg",
"disloop",
"midloop",
"ovotovata",
"balance",
"turnaround",
"turnrun",
"icewalk",
"waterwalk",
"firewalk",
"forestwalk",
"morningwalk",
"roboticwalk",
"wataridori",
"bhaibahan",
"bwloop",
"lring"
].indexOf(pid) >= 0;
break;
default:
exec = !!this.list[name];
}
return exec;
},
//---------------------------------------------------------------------------
// config.configevent() 設定変更時の動作を記述する
//---------------------------------------------------------------------------
configevent: function(name, newval) {
var puzzle = this.puzzle;
if (!puzzle.klass || !this.getexec(name)) {
return;
}
switch (name) {
case "irowake":
case "irowakeblk":
case "dispmove":
case "cursor":
case "trialmarker":
case "undefcell":
case "autocmp":
case "autoerr":
case "aquarium_regions":
case "koburin_minesweeper":
case "snakebd":
case "context_marks":
case "disptype_yajilin":
case "disptype_interbd":
case "dispqnumbg":
case "mouseonly":
puzzle.redraw();
break;
case "font":
puzzle.painter.initFont();
puzzle.redraw();
break;
case "multierr":
puzzle.checker.resetCache();
break;
case "disptype_bosanowa":
puzzle.setCanvasSizeByCellSize(); /* セルのサイズを変えないために、この関数を引数なしで呼び出す */
break;
case "uramashu":
puzzle.board.revCircleConfig(newval);
puzzle.redraw();
break;
}
}
};
})();