將製作ejcees(中國象棋打譜程式)

分享和讨论Javascript相关的话题
回复
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4998
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

附件
ejcees20260407arrange99977752.7z
(46.25 KiB) 已下载 2 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4998
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

更改前面的一個需求:當處於「文本導出」狀態或點擊複製按鈕時,如果不處於範圍選取狀態,只有engine的範圍是從開頭到currentStep,其它三個仍然跟之前一樣導出全部。

只需給出所要修改的地方 ,所有的代碼和注釋都要使用英文。
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4998
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

gemini pro:

代码: 全选

Here are the modifications to implement the requested feature. We will add a parameter to the `getGamePath` function to conditionally limit the end step, and then apply this parameter only when generating the Engine format.

### 1. Update the `getGamePath` function
Find the `getGamePath()` function definition and replace it completely with the following code. This adds the `limitToCurrentStep` parameter, defaulting to `false` for `cn`, `en`, and `url` formats to export the full depth, but allowing the Engine format to stop at `currentStepIndex`.

**Replace this block:**
```javascript
        // Extract the linear path corresponding to the currently selected branch
        function getGamePath() {
            let newStart = 0;
            // Modification: Default end is now currentStepIndex instead of full depth
            let newEnd = currentStepIndex;
            let newHistory = {
                fen: historyFEN.fen,
                move: null,
                lastMove: null,
                c: historyFEN.c,
                v: []
            };
            
            if (isRangeMode) {
                // Restore original full depth default if in range mode but end isn't picked yet
                newEnd = getPathDepth(historyFEN, currentBranch) - 1;
// ... (rest of the function)
```

**With this:**
```javascript
        // Extract the linear path corresponding to the currently selected branch
        function getGamePath(limitToCurrentStep = false) {
            let newStart = 0;
            // Modification: Default to currentStepIndex only if explicitly requested (for engine format)
            let newEnd = limitToCurrentStep ? currentStepIndex : getPathDepth(historyFEN, currentBranch) - 1;
            let newHistory = {
                fen: historyFEN.fen,
                move: null,
                lastMove: null,
                c: historyFEN.c,
                v: []
            };
            if (isRangeMode) {
                if (rangeStart === null && rangeEnd === null) {
                    newStart = currentStepIndex;
                    newEnd = currentStepIndex;
                } else if (rangeStart !== null && rangeEnd !== null && rangeStart === rangeEnd) {
                    newStart = rangeStart;
                    newEnd = rangeEnd;
                } else if (rangeStart !== null && rangeEnd === null) {
                    newStart = rangeStart;
                } else if (rangeStart !== null && rangeEnd !== null && rangeStart !== rangeEnd) {
                    newStart = Math.min(rangeStart, rangeEnd);
                    newEnd = Math.max(rangeStart, rangeEnd);
                }
                const startNode = getNodeAtStep(newStart);
                newHistory = {
                    fen: startNode.fen,
                    move: null,
                    lastMove: null,
                    c: startNode.c,
                    v: []
                };
            }
            let curr = newHistory;
            for (let i = newStart + 1; i <= newEnd; i++) {
                const node = getNodeAtStep(i);
                let newNode = {
                    fen: node.fen,
                    move: node.move,
                    lastMove: node.lastMove,
                    c: node.c,
                    v: []
                };
                curr.v.push(newNode);
                curr = newNode;
            }
            return newHistory;
        }
```

### 2. Update `performCopy` to pass `true` for Engine format
Locate the global `performCopy()` function that you added in the previous step. Find the `else if (fmt === 'engine') {` block and update the `getGamePath` call.

**Replace this line:**
```javascript
            } else if (fmt === 'engine') {
                let path = getGamePath();
```

**With this:**
```javascript
            } else if (fmt === 'engine') {
                // Modification: Pass true to limit engine format to currentStepIndex
                let path = getGamePath(true);
```

### 3. Update `renderExportTextUI` to pass `true` for Engine format
Locate the `renderExportTextUI()` function (around the area where the `urlTextToggled` is defined). Find the section where the Engine text is generated and update the `getGamePath` call.

**Replace this block:**
```javascript
            const urlText = generateUrlHash(false);
            const urlTextToggled = generateUrlHash(true);

            // Generate UCCI Engine Format String
            let path = getGamePath();
```

**With this:**
```javascript
            const urlText = generateUrlHash(false);
            const urlTextToggled = generateUrlHash(true);

            // Generate UCCI Engine Format String
            // Modification: Pass true to limit engine format to currentStepIndex
            let path = getGamePath(true);
```
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4998
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

增加功能:當不處於「編輯局面、編輯評論、導出文本、改動間隔及移動時間」狀態時,按下空白鍵,就等於是按下「自動播放」按鈕。

代码: 全选

Here is the modification to add the **Spacebar** as a shortcut for the **Auto Play** button.

### Update the `keydown` Event Listener
Locate the main keyboard event listener `document.addEventListener('keydown', (e) => {` (around line `1854`). Insert the logic for the Spacebar inside the main block, ensuring it only triggers when the specified states are inactive.

**Search for this section:**
```javascript
        document.addEventListener('keydown', (e) => {
            if (isExportTextMode || isEditingComment || isEditMode || isEditingSettings) return;
```

**Replace that specific check and add the Spacebar logic like this:**
```javascript
        document.addEventListener('keydown', (e) => {
            // Check if any modal or edit mode is active
            const isExportModalOpen = document.querySelector('.ejcees-export-modal') !== null;
            const isRestrictedMode = isExportTextMode || isEditingComment || isEditMode || isEditingSettings || isExportModalOpen;

            // Feature: Spacebar for Auto Play
            if (e.code === 'Space' || e.key === ' ') {
                if (!isRestrictedMode) {
                    e.preventDefault(); // Prevent page scrolling
                    const autoPlayBtn = document.getElementById('btn-auto-play');
                    if (autoPlayBtn) {
                        autoPlayBtn.click();
                    }
                    return;
                }
            }

            if (isRestrictedMode) return;

            if (e.ctrlKey) {
                // ... (existing Ctrl shortcut logic)
```

### Explanation of the change:
* **`e.code === 'Space'`**: This reliably detects the spacebar across different keyboard layouts.
* **`e.preventDefault()`**: This is crucial because the default browser behavior for the spacebar is to scroll the page down; this line prevents that.
* **State Check**: It uses the same logic as your other shortcuts to ensure you don't accidentally toggle auto-play while typing a comment or editing settings.
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4998
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

附件
ejcees20260407engineStep99977753.7z
(46.37 KiB) 尚未被下载
https://ejsoon.vip/
弈趣極光:享受思維樂趣
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 2 访客