將製作ejcees(中國象棋打譜程式)
Re: 將製作ejcees(中國象棋打譜程式)
一個不小的改動,這回文本導出的不再是全部的棋譜,而是只到currentStep的棋譜。
https://ejsoon.vip/wp-content/uploads/2 ... 77752.html
- 附件
-
ejcees20260407arrange99977752.7z- (46.25 KiB) 已下载 2 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
只需給出所要修改的地方 ,所有的代碼和注釋都要使用英文。
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
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/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
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/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
更改導出範圍,engine只到currentStep,而其它三個都是全部導出。space播放和停止動畫。
https://ejsoon.vip/wp-content/uploads/2 ... 77753.html
- 附件
-
ejcees20260407engineStep99977753.7z- (46.37 KiB) 尚未被下载
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
在线用户
正浏览此版面之用户: 没有注册用户 和 2 访客
