Skip to content

Commit

Permalink
Merge pull request #11 from Nervonment/v0.3.x
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
Nervonment authored Jun 14, 2024
2 parents 9127c3c + 9fe8455 commit 7fbc1d6
Show file tree
Hide file tree
Showing 12 changed files with 826 additions and 617 deletions.
23 changes: 22 additions & 1 deletion app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useEffect, useState } from "react";
export default function Home() {
const [difficulty, setDifficulty] = useState(2);
const [markingAssist, setMarkingAssist] = useState(false);
const [beginWithMarks, setBeginWithMarks] = useState(false);
const [appVersion, setAppversion] = useState("");
const [updateDialogOpen, setUpdateDialogOpen] = useState(false);
const [updateManifest, setUpdateManifest] = useState({});
Expand All @@ -34,6 +35,7 @@ export default function Home() {
useEffect(() => {
invoke('get_difficulty').then((difficulty) => setDifficulty(difficulty));
invoke('get_marking_assist').then((markingAssist) => setMarkingAssist(markingAssist));
invoke('get_begin_with_marks').then((beginWithMarks) => setBeginWithMarks(beginWithMarks));
}, []);

useEffect(() => {
Expand Down Expand Up @@ -105,7 +107,7 @@ export default function Home() {
</div>
</PopoverTrigger>
<PopoverContent>
<p className="text-sm">开启标记辅助后,开局时会自动标记上所有候选数字</p>
<p className="text-sm">开启标记辅助后,每个格子中的候选数会自动更新</p>
</PopoverContent>
</Popover>
<Switch
Expand All @@ -116,6 +118,25 @@ export default function Home() {
}}
/>
</div>
<div className="flex justify-between items-center">
<Popover>
<PopoverTrigger asChild>
<div className="flex items-center gap-1 cursor-pointer">
<Label className="font-bold flex items-center gap-1">开局标记所有候选数<HelpCircle size={16} /></Label>
</div>
</PopoverTrigger>
<PopoverContent>
<p className="text-sm">开启后,开局时会自动标记上所有候选数字</p>
</PopoverContent>
</Popover>
<Switch
checked={beginWithMarks}
onCheckedChange={(checked) => {
setBeginWithMarks(checked);
invoke('set_begin_with_marks', { beginWithMarks: checked });
}}
/>
</div>
<div className="flex justify-between items-center">
<Label className="font-bold">颜色模式</Label>
<DropdownMenu>
Expand Down
16 changes: 10 additions & 6 deletions app/start/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function Start() {
const [usedAssist, setUsedAssist] = useState(false);

const markingAssistRef = useRef(false); // 是否开启标记辅助
const beginWithMarksRef = useRef(false); // 是否开启开局标记

const historyRef = useRef([]);
const futureRef = useRef([]);
Expand All @@ -57,13 +58,15 @@ export default function Start() {
useEffect(() => {
invoke('get_difficulty').then((difficulty) => setDifficulty(difficulty));
invoke('get_marking_assist').then((markingAssist) => { markingAssistRef.current = markingAssist; setUsedAssist(markingAssist); });
invoke('get_begin_with_marks').then((beginWithMarks) => { beginWithMarksRef.current = beginWithMarks; });
}, []);

const init = useCallback((grid) => {
setGrid(grid);
setMaxCandidates(getMaxCandidates(grid));
if (markingAssistRef.current) {
setMarkedCandidates(Array.from({ length: 9 }, (v) => Array.from({ length: 9 }, (v) => Array.from({ length: 10 }, (v) => true))));
if (beginWithMarksRef.current) {
setMarkedCandidates(getMaxCandidates(grid));
// setMarkedCandidates(Array.from({ length: 9 }, (v) => Array.from({ length: 9 }, (v) => Array.from({ length: 10 }, (v) => true))));
} else {
setMarkedCandidates(Array.from({ length: 9 }, (v) => Array.from({ length: 9 }, (v) => Array.from({ length: 10 }, (v) => false))));
}
Expand Down Expand Up @@ -226,8 +229,9 @@ export default function Start() {
}
// 标记候选数
else {
// 只能标记 maxCandidates[r][c] 中的数字
if (grid[r][c].value == 0 && (maxCandidates[r][c][num] || event.key == ' ')) {
// 没有开启标记辅助时,可以标记任意数字
// 开启时,只能标记 maxCandidates[r][c] 中的数字
if (grid[r][c].value == 0 && (!markingAssistRef.current || maxCandidates[r][c][num] || event.key == ' ')) {
if (event.key == ' ') { // 按空格键
if (!markedCandidates[r][c].every((is, num) => num == 0 || !is)) {
pushHistory(grid, markedCandidates);
Expand Down Expand Up @@ -271,7 +275,7 @@ export default function Start() {
if (!finished && grid)
invoke('get_hint', {
grid: grid.map((row) => row.map((cell) => cell.value)),
candidates: maskedCandidates
candidates: markingAssistRef.current ? maskedCandidates : markedCandidates
}).then((hint) => {
setUsedHint(true);
setHint(hint[0]);
Expand Down Expand Up @@ -309,7 +313,7 @@ export default function Start() {
<>
<SudokuGrid
grid={grid}
candidates={maskedCandidates}
candidates={markingAssistRef.current ? maskedCandidates : markedCandidates}
handleMouseEnter={handleMouseEnter}
handleMouseLeave={handleMouseLeave}
visualElements={hint ? hint.visual_elements : null}
Expand Down
12 changes: 1 addition & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,4 @@ export const difficultyDesc = [
"😖困难",
"🤯地狱",
"🎣钓鱼"
];

export const hintColor = {
"TextDefault": "",
"House1": "#ffcf33",
"House2": "#f67b46",
"Cell1": "#ff4c8e",
"NumToFill": "#ff4c8e",
"CandidateToReserve": "#7cbd14",
"CandidateToRemove": "hsl(var(--destructive))"
};
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sudoxide",
"version": "0.3.0",
"version": "0.3.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Loading

0 comments on commit 7fbc1d6

Please sign in to comment.