Skip to content

Commit

Permalink
Add Patchwork
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep authored Aug 14, 2023
1 parent a32fa4d commit a3256ae
Show file tree
Hide file tree
Showing 12 changed files with 305 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src-ui/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
<main>
<div style="margin-bottom: 5px;"><b>Latest types</b> (<em><a href="/list.html" target="_parent">all types</a></em>)</div>
<ul>
<li><a href="/p?patchwork" target="_parent">Patchwork パッチワーク</a></li>
<li><a href="/p?myopia" target="_parent">Myopia</a></li>
<li><a href="/p?sashikazune" target="_parent">Sashikazune さしカズね</a></li>
<li><a href="/p?brownies" target="_parent">Brownies ブラウニー</a></li>
<li><a href="/p?tetrochain" target="_parent">Tetrochain テトロチェーン</a></li>
<li><a href="/p?bdwalk" target="_parent">Building Walk ビルウォーク <small>(rules update)</small></a></li>
<li><a href="/p?heyapin" target="_parent">Heyapin へやピン</a></li>
<li><a href="/p?invlitso" target="_parent">Inverse LITSO</a></li>
<li><a href="/p?battleship" target="_parent">Battleship</a></li>
</ul>
</main>
</body>
Binary file added src-ui/img/patchwork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src-ui/js/ui/KeyPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ ui.keypopup = {
maxi: [10, 0],
tetrochain: [10, 0],
brownies: [127, 0],
sashikazune: [10, 0]
sashikazune: [10, 0],
patchwork: [10, 0]
},

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -397,6 +398,11 @@ ui.keypopup = {
cap = "□";
} else if (pid === "rectslider") {
cap = "■";
} else if (pid === "patchwork") {
cap = {
text: "■",
color: "rgb(204,204,204)"
};
} else if (
pid === "kurotto" ||
pid === "bonsan" ||
Expand Down
1 change: 1 addition & 0 deletions src-ui/js/ui/Misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function toBGimage(pid) {
"oneroom",
"ovotovata",
"oyakodori",
"patchwork",
"pencils",
"pentopia",
"ququ",
Expand Down
1 change: 1 addition & 0 deletions src-ui/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ <h2 id="title"><span lang="ja">パズルの種類のリスト</span><span lang="
<li data-pid="cocktail"></li>
<li data-pid="kuroclone"></li>
<li data-pid="martini"></li>
<li data-pid="patchwork"></li>
</ul>
</div>
<div class="lists blocks">
Expand Down
1 change: 1 addition & 0 deletions src/pzpr/variety.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
oyakodori: [0, 0, "おやこどり", "Oyakodori", "kaero"],
paintarea: [1, 0, "ペイントエリア", "Paintarea"],
parquet: [0, 0, "Parquet", "Parquet"],
patchwork: [0, 0, "パッチワーク", "Patchwork"],
pencils: [0, 0, "ペンシルズ", "Pencils"],
pentominous: [0, 0, "Pentominous", "Pentominous", "fillomino"],
pentopia: [0, 0, "Pentopia", "Pentopia", "statuepark"],
Expand Down
3 changes: 2 additions & 1 deletion src/res/failcode.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"bkNotRect": "There is a room whose shape is not a rectangle.",
"bkNotRect3.shikaku": "An area whose size is not a multiple of three is not a rectangle.",
"bkNotSeqNum.renban": "The numbers in the room are not consecutive.",
"bkNotSquare.squarejam": "An area is not a square.",
"bkNotSquare": "An area is not a square.",
"bkNotSquare.tatamibari": "A tatami is not a square.",
"bkNotSymmRoom.fillomino": "An area is not point symmetric.",
"bkNotSymRoom.ayeheya": "The room is not point symmetric.",
Expand Down Expand Up @@ -316,6 +316,7 @@
"cbSameNum.nanro": "Adjacent blocks have the same number.",
"cbShade.shimaguni": "Countries in different marine areas are adjacent.",
"cbShade": "Shaded cells are adjacent over a border.",
"cbUnshade": "Unshaded cells are adjacent over a border.",
"ceAddLine": "A cell with given lines has extra lines.",
"ceDark.lightup": "A cell is not shined.",
"ceDirection.compass": "The number of cells in the direction is wrong.",
Expand Down
2 changes: 1 addition & 1 deletion src/res/failcode.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
"nmLoop.snakepit": "スネークに端がありません。",
"nmMidpoint.snakepit": "灰色のマスがスネークの端になっています。",
"nmSame2x2.snakepit": "スネークが自分自身とタテヨコに接しています。",
"bkNotSquare.squarejam": "領域が正方形ではありません。",
"bkNotSquare": "領域が正方形ではありません。",
"anShadeNe.yajisoko": "箱の数が正しくありません。",
"bkSideNe.squarejam": "数字と領域の大きさが異なります。",
"laOnNum.yajisoko": "線が箱を通り過ぎています。",
Expand Down
40 changes: 20 additions & 20 deletions src/variety-common/Graphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,31 +1116,31 @@ pzpr.classmgr.makeCommon({
var LTin = cell.bx > 2,
RTin = cell.bx < 2 * this.board.cols - 2;

var isUP = !UPin || adb.top.ques === 1;
var isDN = !DNin || adb.bottom.ques === 1;
var isLT = !LTin || adb.left.ques === 1;
var isRT = !RTin || adb.right.ques === 1;
var isUP = !UPin || adb.top.isBorder();
var isDN = !DNin || adb.bottom.isBorder();
var isLT = !LTin || adb.left.isBorder();
var isRT = !RTin || adb.right.isBorder();

var isUL =
!UPin ||
!LTin ||
cell.relbd(-2, -1).ques === 1 ||
cell.relbd(-1, -2).ques === 1;
isUP ||
isLT ||
cell.relbd(-2, -1).isBorder() ||
cell.relbd(-1, -2).isBorder();
var isUR =
!UPin ||
!RTin ||
cell.relbd(2, -1).ques === 1 ||
cell.relbd(1, -2).ques === 1;
isUP ||
isRT ||
cell.relbd(2, -1).isBorder() ||
cell.relbd(1, -2).isBorder();
var isDL =
!DNin ||
!LTin ||
cell.relbd(-2, 1).ques === 1 ||
cell.relbd(-1, 2).ques === 1;
isDN ||
isLT ||
cell.relbd(-2, 1).isBorder() ||
cell.relbd(-1, 2).isBorder();
var isDR =
!DNin ||
!RTin ||
cell.relbd(2, 1).ques === 1 ||
cell.relbd(1, 2).ques === 1;
isDN ||
isRT ||
cell.relbd(2, 1).isBorder() ||
cell.relbd(1, 2).isBorder();

g.beginPath();

Expand Down
7 changes: 5 additions & 2 deletions src/variety-common/MouseInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ pzpr.classmgr.makeCommon({
this.inputData = cell.qans !== 1 ? 1 : 0;
} else if (this.inputMode === "unshade") {
this.inputData = cell.qsub !== 1 ? 2 : 0;
} else if (this.puzzle.getConfig("use") === 1) {
} else if (
this.puzzle.getConfig("use") === 1 &&
this.pid !== "patchwork"
) {
if (this.btn === "left") {
this.inputData = cell.qans !== 1 ? 1 : 0;
} else if (this.btn === "right") {
this.inputData = cell.qsub !== 1 ? 2 : 0;
}
} else if (this.puzzle.getConfig("use") === 2) {
} else {
if (!cell.allowShade()) {
this.inputData = cell.qsub !== 1 ? 2 : 0;
} else if (!cell.allowUnshade()) {
Expand Down
213 changes: 213 additions & 0 deletions src/variety/patchwork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
//
// patchwork.js
//
(function(pidlist, classbase) {
if (typeof module === "object" && module.exports) {
module.exports = [pidlist, classbase];
} else {
pzpr.classmgr.makeCustom(pidlist, classbase);
}
})(["patchwork"], {
//---------------------------------------------------------
// マウス入力系
MouseEvent: {
inputModes: {
edit: ["number", "undef", "clear"],
play: ["border", "shade", "unshade", "subline"]
},
mouseinput_auto: function() {
if (this.puzzle.playmode) {
if (this.mousestart || this.mousemove) {
if (this.btn === "right") {
this.inputQsubLine();
} else if (this.isBorderMode()) {
this.inputborder();
} else {
this.inputShade();
}
} else if (this.notInputted()) {
if (this.isBorderMode()) {
var border = this.getborder();
if (!border.isnull) {
border.setQsub(border.qsub === 1 ? 0 : 1);
border.draw();
}
} else if (this.btn === "right") {
this.inputShade();
}
}
} else if (this.puzzle.editmode) {
this.inputqnum();
}
}
},

//---------------------------------------------------------
// キーボード入力系
KeyEvent: {
enablemake: true
},

Cell: {
numberRemainsUnshaded: true,
minnum: 0,
maxnum: function() {
return this.board.cols * this.board.rows - 1;
}
},

Board: {
hasborder: 1
},

AreaRoomGraph: {
enabled: true
},

//---------------------------------------------------------
// 画像表示系

Graphic: {
hideHatena: true,
icecolor: "rgb(204,204,204)",
shadecolor: "#222222",
bordercolor_func: "qans",

paint: function() {
this.drawBGCells();
this.drawShadedCells();
this.drawDashedGrid();

this.drawQuesNumbers();

this.drawBorders();
this.drawBorderQsubs();

this.drawBoxBorders(false);
this.drawChassis();
this.drawTarget();
},

getBGCellColor: function(cell) {
if (cell.error === 1 || cell.qinfo === 1) {
if (cell.isNum()) {
return this.erricecolor;
} else {
return this.errbcolor1;
}
} else if (cell.isNum()) {
return this.icecolor;
} else if (cell.qsub === 1) {
return this.bcolor;
}
return null;
}
},

//---------------------------------------------------------
// URLエンコード/デコード処理
Encode: {
decodePzpr: function(type) {
this.decodeNumber16();
},
encodePzpr: function(type) {
this.encodeNumber16();
}
},

//---------------------------------------------------------
FileIO: {
decodeData: function() {
this.decodeCellQnumAns();
this.decodeBorderAns();
},
encodeData: function() {
this.encodeCellQnumAns();
this.encodeBorderAns();
}
},

//---------------------------------------------------------
// 正解判定処理実行部
AnsCheck: {
checklist: [
"checkSideAreaShadeCell",
"checkShadeCellCount",
"checkSideAreaUnshadeCell",
"checkRoomSquare",
"checkBorderDeadend+",
"doneShadingDecided"
],

checkShadeCellCount: function() {
var rooms = this.board.roommgr.components;
for (var r = 0; r < rooms.length; r++) {
var clist = rooms[r].clist,
d = clist.getRectSize();

if (d.rows !== d.cols || d.rows * d.cols !== d.cnt) {
continue;
}

var count = clist.filter(function(cell) {
return cell.isShade();
}).length;

for (var i = 0; i < clist.length; i++) {
var cell = clist[i];
var qnum = cell.qnum;
if (qnum < 0) {
continue;
}
if (qnum !== count) {
this.failcode.add("bkShadeNe");
if (this.checkOnly) {
return;
}
clist.seterr(1);
}
}
}
},

checkRoomSquare: function() {
this.checkAllArea(
this.board.roommgr,
function(w, h, a, n) {
return w === h && w * h === a;
},
"bkNotSquare"
);
},

checkSideAreaShadeCell: function() {
this.checkSideAreaCell(
function(cell1, cell2) {
return (
!cell1.isNum() &&
!cell2.isNum() &&
cell1.isShade() &&
cell2.isShade()
);
},
false,
"cbShade"
);
},

checkSideAreaUnshadeCell: function() {
this.checkSideAreaCell(
function(cell1, cell2) {
return (
!cell1.isNum() &&
!cell2.isNum() &&
!cell1.isShade() &&
!cell2.isShade()
);
},
false,
"cbUnshade"
);
}
}
});
Loading

1 comment on commit a3256ae

@vercel
Copy link

@vercel vercel bot commented on a3256ae Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pzprjs – ./

pzprjs-git-main-robx.vercel.app
pzprjs.vercel.app
pzprjs-robx.vercel.app

Please sign in to comment.