Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when left-click the flagged block, will not trigger explosion #261

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vitepress/composables/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ export class GamePlay {
this.generateMines(this.board, block);
this.state.value.mineGenerated = true;
}

if (block.revealed)
return;

if (block.flagged) {
block.flagged = !block.flagged;
return;
}

block.revealed = true;
if (block.mine) {
this.onGameOver('lost');
Expand Down
17 changes: 11 additions & 6 deletions .vitepress/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// import { defineConfig } from 'vitepress'
import { withMermaid } from "vitepress-plugin-mermaid-xyxsw";
import { transformerTwoslash } from '@shikijs/vitepress-twoslash';
import PanguPlugin from 'markdown-it-pangu';
import { fileURLToPath, URL } from 'node:url';
import VueMacros from 'unplugin-vue-macros/vite';
import { VitePWA } from 'vite-plugin-pwa';
import { main_sidebar, main_sidebar_old, chapter2_old, chapter3_old, chapter4_old, chapter5_old, chapter6_old, chapter7_old, chapter8_old, chapter9_old } from './sidebar.js';
import { withMermaid } from "vitepress-plugin-mermaid-xyxsw";
import { nav } from './nav.js';
import PanguPlugin from 'markdown-it-pangu'
import { fileURLToPath, URL } from 'node:url'
import VueMacros from 'unplugin-vue-macros/vite'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
import { chapter2_old, chapter3_old, chapter4_old, chapter5_old, chapter6_old, chapter7_old, chapter8_old, chapter9_old, generateSidebar, main_sidebar, main_sidebar_old } from './sidebar.js';

// https://vitepress.dev/reference/site-config
export default withMermaid({
Expand Down Expand Up @@ -51,6 +51,11 @@ export default withMermaid({

sidebar: {
'/': main_sidebar(),
'/1.杭电生存指南/': generateSidebar('1.杭电生存指南', ['static']),
'/2.编程模块/': generateSidebar('2.编程模块', ['static']),
'/3.AI模块/': generateSidebar('3.AI模块', ['static']),
'/4.WEB模块/': generateSidebar('4.WEB模块', ['static']),
'/5.安全模块/': generateSidebar('5.安全模块', ['static']),
'/2023旧版内容/': main_sidebar_old(),
'/2023旧版内容/2.高效学习/': chapter2_old(),
'/2023旧版内容/3.编程思维体系构建/': chapter3_old(),
Expand Down
56 changes: 56 additions & 0 deletions .vitepress/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import fs from 'fs';
import path from 'path';

export function main_sidebar() {
return [
{
Expand Down Expand Up @@ -518,3 +521,56 @@ export function chapter9_old() {
}
]
}

// Function to extract numeric prefix as an array of numbers
function getNumericPrefix(fileName) {
const match = fileName.match(/^(\d+(\.\d+)?(?:\.\d+)*)/);
if (match) {
return match[0].split('.').map(Number); // Convert to array of numbers
}
return [];
}

// Function to compare two numeric prefixes
function compareNumericPrefixes(a, b) {
const prefixA = getNumericPrefix(a);
const prefixB = getNumericPrefix(b);

for (let i = 0; i < Math.max(prefixA.length, prefixB.length); i++) {
const numA = prefixA[i] || 0;
const numB = prefixB[i] || 0;
if (numA !== numB) {
return numA - numB;
}
}
return 0;
}

// Function to generate sidebar items
/**
*
* @param {String} dir the start folder to scan
* @param {String[]} excludeDir exclude unwanted folder
* @returns
*/
export function generateSidebar(dir, excludeDir = []) {
const files = fs.readdirSync(dir);
const sortedFiles = files.sort(compareNumericPrefixes);

return sortedFiles.map((file) => {
const fullPath = path.join(dir, file);
if (fs.statSync(fullPath).isDirectory()) {
if (excludeDir.includes(file)) {
return null; // Skip excluded directories
}
return {
text: file,
collapsed: true,
items: generateSidebar(fullPath, excludeDir),
};
} else if (file.endsWith('.md')) {
return { text: file.replace('.md', ''), link: `/${fullPath.replace('.md', '')}` };
}
}).filter(Boolean);
}