Skip to content

Commit f84f91b

Browse files
authored
diamond: Add more aux marks
1 parent 5d87dfa commit f84f91b

2 files changed

Lines changed: 122 additions & 11 deletions

File tree

src/variety/diamond.js

Lines changed: 110 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use: true,
1010
inputModes: {
1111
edit: ["number", "clear", "info-blk"],
12-
play: ["diamond", "peke", "unshade", "info-blk"]
12+
play: ["diamond", "peke", "unshade", "dot", "info-blk"]
1313
},
1414

1515
decIC: function(cell) {
@@ -18,6 +18,14 @@
1818

1919
mouseinput_auto: function() {
2020
if (this.puzzle.playmode) {
21+
if (this.mousestart) {
22+
this.isInputtingDot = this.puzzle.key.isALT;
23+
}
24+
if (this.isInputtingDot) {
25+
this.inputdot();
26+
return;
27+
}
28+
2129
if (this.mousestart && this.btn === "right") {
2230
var cell = this.getcell();
2331
if (cell.isNum() || this.getpos(0.25).equals(cell)) {
@@ -59,8 +67,38 @@
5967
mouseinput_other: function() {
6068
if (this.inputMode === "diamond") {
6169
this.inputcross(1);
70+
} else if (this.inputMode === "dot") {
71+
this.inputdot();
6272
}
6373
},
74+
inputdot: function() {
75+
if (!this.mousestart) {
76+
return;
77+
}
78+
79+
var pos = this.getpos(0.15);
80+
if (this.prevPos.equals(pos)) {
81+
return;
82+
}
83+
84+
var dot = pos.getDot();
85+
if (!dot) {
86+
return;
87+
}
88+
if (this.inputData === null) {
89+
if (this.puzzle.getConfig("use") === 1) {
90+
var fixed = this.btn === "left" ? 2 : 3;
91+
this.inputData = dot.getDot() === fixed ? 0 : fixed;
92+
} else if (this.btn === "left") {
93+
this.inputData = { 2: 3, 3: -1 }[dot.getDot()] || 2;
94+
} else if (this.btn === "right") {
95+
this.inputData = { 3: 2, 2: -1 }[dot.getDot()] || 3;
96+
}
97+
}
98+
dot.setDot(Math.max(0, this.inputData));
99+
dot.draw();
100+
this.prevPos = pos;
101+
},
64102
inputpeke: function() {
65103
this.inputcross(2);
66104
},
@@ -145,7 +183,7 @@
145183
},
146184

147185
getDiamond: function() {
148-
return this.qans ? 1 : this.qsub ? 2 : 0;
186+
return this.qans ? 1 : this.qsub === 1 ? 2 : 0;
149187
},
150188
overlapsDiamond: function(lenient) {
151189
var self = this;
@@ -189,20 +227,23 @@
189227

190228
this.setQans(val === 1 ? 1 : 0);
191229
this.setQsub(val === 2 ? 1 : 0);
192-
193-
if (val === 1) {
194-
this.dotCells().each(function(cell) {
195-
cell.setQsub(0);
196-
});
197-
}
198230
},
199231
dotCells: function() {
200232
var bx = this.bx,
201233
by = this.by;
202234
return this.board.cellinside(bx - 1, by - 1, bx + 1, by + 1);
203235
}
204236
},
205-
237+
Border: {
238+
overlapsDiamond: function() {
239+
for (var i = 0; i < 2; i++) {
240+
if (this.sidecross[i].qans === 1) {
241+
return true;
242+
}
243+
}
244+
return false;
245+
}
246+
},
206247
Cell: {
207248
minnum: 0,
208249
maxnum: 4,
@@ -237,10 +278,16 @@
237278
var bx = this.bx,
238279
by = this.by;
239280
return this.board.crossinside(bx - 1, by - 1, bx + 1, by + 1);
281+
},
282+
/* Check if a regular qsub=1 should be drawn here */
283+
isDot: function() {
284+
return this.qsub === 1 && this.allowUnshade();
240285
}
241286
},
242287
Board: {
288+
hasborder: 1,
243289
hascross: 1,
290+
hasdots: 1,
244291
addExtraInfo: function() {
245292
this.diamondgraph = this.addInfoList(this.klass.AreaDiamondGraph);
246293
},
@@ -337,12 +384,40 @@
337384
}
338385
},
339386

387+
Dot: {
388+
getTrial: function() {
389+
return this.piece.trial;
390+
},
391+
getDot: function() {
392+
return this.piece.qsub;
393+
},
394+
isHidden: function() {
395+
if (this.piece.allowUnshade && !this.piece.allowUnshade()) {
396+
return true;
397+
}
398+
if (this.piece.group === "border" && this.piece.overlapsDiamond()) {
399+
return true;
400+
}
401+
return this.piece.qans === 1;
402+
},
403+
setDot: function(val) {
404+
if (val && this.isHidden()) {
405+
return;
406+
}
407+
408+
this.puzzle.opemgr.disCombine = true;
409+
this.piece.setQsub(val);
410+
this.puzzle.opemgr.disCombine = false;
411+
}
412+
},
413+
340414
Graphic: {
341415
hideHatena: true,
342416

343417
fgcellcolor_func: "qnum",
344418
fontShadecolor: "white",
345419
pekecolor: "rgb(127,127,255)",
420+
altpekecolor: "rgb(80,80,127)",
346421

347422
paint: function() {
348423
this.drawBGCells();
@@ -355,10 +430,25 @@
355430

356431
this.drawDiamonds();
357432
this.drawDotCells();
433+
this.drawDots();
358434

359435
this.drawTarget();
360436
},
361437

438+
getDotFillColor: function(dot) {
439+
var value = dot.isHidden() ? 0 : dot.getDot();
440+
if (value === 2) {
441+
return dot.getTrial() ? this.trialcolor : this.altpekecolor;
442+
}
443+
return value === 3 ? "white" : null;
444+
},
445+
getDotOutlineColor: function(dot) {
446+
if (!dot.isHidden() && dot.getDot() === 3) {
447+
return dot.getTrial() ? this.trialcolor : this.altpekecolor;
448+
}
449+
return null;
450+
},
451+
362452
drawBaseMarks: function() {
363453
var bd = this.board;
364454
var g = this.vinc("cross_mark", "auto", true);
@@ -420,7 +510,7 @@
420510
return cell.qcmp === 1 ? this.qcmpcolor : this.fontShadecolor;
421511
},
422512
drawDiamonds: function() {
423-
var g = this.vinc("dot", "auto");
513+
var g = this.vinc("diamond", "auto");
424514

425515
var d = this.range;
426516
var size = this.cw * 0.2;
@@ -438,7 +528,7 @@
438528
px = bx * this.bw,
439529
py = by * this.bh;
440530

441-
g.vid = "s_dot_" + dot.id;
531+
g.vid = "s_diamond_" + dot.id;
442532
var outline = this.getDiamondColor(dot);
443533
var value = dot.getDiamond();
444534
if (value === 1) {
@@ -492,12 +582,21 @@
492582
this.decodeCross(function(cross, ca) {
493583
cross.setDiamond(+ca, true);
494584
}, true);
585+
this.decodeDotFile();
495586
},
496587
encodeData: function() {
497588
this.encodeCellQnumAns();
498589
this.encodeCross(function(cross) {
499590
return cross.getDiamond() + " ";
500591
}, true);
592+
593+
if (
594+
this.board.dots.find(function(dot) {
595+
return dot.getDot() >= 2;
596+
})
597+
) {
598+
this.encodeDotFile();
599+
}
501600
}
502601
},
503602
AnsCheck: {

test/script/diamond.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ ui.debug.addDebugData("diamond", {
7272
{
7373
input: ["playmode,diamond", "mouse,right,6,2", "mouse,right,6,4"],
7474
result: "pzprv3/diamond/3/4/. . . . /. . . . /. . . . /1 0 0 /0 2 1 /"
75+
},
76+
{
77+
input: [
78+
"playmode,auto",
79+
"mouse,alt+left,3,1",
80+
"mouse,alt+left,4,1",
81+
"mouse,alt+left,5,1",
82+
"mouse,alt+left,4,2",
83+
"mouse,alt+right,5,2"
84+
],
85+
result:
86+
"pzprv3/diamond/3/4/. . . . /. . . . /. . . . /1 0 0 /0 2 1 /...22../...23../......./...1.../......./"
7587
}
7688
]
7789
});

0 commit comments

Comments
 (0)