Skip to content
Open
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
110 changes: 109 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,10 @@ a:hover {
.book-travel-status-hud__collapse:focus-visible,
.book-travel-status-hud__compact-button:focus-visible,
.book-travel-hud-text-button:focus-visible,
.book-travel-hud-details > summary:focus-visible {
.book-travel-hud-details > summary:focus-visible,
.book-travel-panel-toggle:focus-visible,
.book-travel-style-preset-add:focus-visible,
.book-travel-style-preset-remove:focus-visible {
outline: 2px solid #d97757;
outline-offset: 2px;
}
Expand All @@ -1183,6 +1186,30 @@ a:hover {
padding: 2px 18px 24px;
}

.book-travel-session-controls .book-travel-hud-section:first-child {
padding-top: 8px;
}

.book-travel-hud-checks {
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 10px;
}

.book-travel-hud-check {
display: flex;
align-items: flex-start;
gap: 8px;
color: #33312e;
font-size: 13px;
line-height: 1.4;
}

.book-travel-hud-check input {
margin-top: 2px;
}

.book-travel-hud-section {
padding: 17px 0;
border-bottom: 1px solid #e8e2da;
Expand All @@ -1200,6 +1227,75 @@ a:hover {
letter-spacing: 0.03em;
}

.book-travel-panel-toggle {
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 0;
border: 0;
background: transparent;
color: inherit;
cursor: pointer;
font: inherit;
letter-spacing: inherit;
text-align: left;
}

.book-travel-panel-toggle:hover,
.book-travel-style-preset-add:hover,
.book-travel-style-preset-remove:hover {
color: #b85f43;
}

.book-travel-style-preset-list {
display: flex;
flex-direction: column;
gap: 12px;
}

.book-travel-style-preset-row {
display: flex;
align-items: center;
gap: 8px;
}

.book-travel-style-preset-row > .ant-select {
flex: 1 1 auto;
min-width: 0;
}

.book-travel-style-preset-add-row {
margin-top: 8px;
}

.book-travel-style-preset-add,
.book-travel-style-preset-remove {
display: inline-flex;
align-items: center;
justify-content: center;
border: 1px solid #e3dcd4;
border-radius: 8px;
background: #fcfaf7;
color: #756e67;
cursor: pointer;
font: inherit;
}

.book-travel-style-preset-remove {
width: 32px;
height: 32px;
flex: 0 0 32px;
}

.book-travel-style-preset-add {
gap: 6px;
margin-top: 8px;
padding: 6px 10px;
font-size: 12px;
}

.book-travel-hud-section__body {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -1625,6 +1721,18 @@ a:hover {
overflow-y: auto;
}

.book-travel-setup-picker h3 {
margin: 0 0 8px;
color: #33312e;
font-size: 14px;
font-weight: 600;
}

.book-travel-setup-picker .book-travel-style-preset-add,
.book-travel-setup-picker .book-travel-style-preset-remove {
background: #ffffff;
}

.book-travel-setup-card,
.adventure-setup-card {
display: flex;
Expand Down
55 changes: 55 additions & 0 deletions src/__tests__/book-travel-materials-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,59 @@ describe('BookTravelMaterials page', () => {
expect(useBookTravelStore.getState().assembledMaterials[0].title).toBe('新素材标题');
});
});

it('refreshes checked character cards into the assembled material', async () => {
usePartnerStore.setState({
characterCards: [
{
id: 'cc-new',
name: '沈霜',
type: 'character_card',
content: '旧正文',
fields: { skills: '新剑法', userRelationType: '好友' },
worldBookId: 'wb-1',
},
],
});
const materialId = useBookTravelStore.getState().saveAssembledMaterial({
title: '旧素材标题',
materials: {
outline: { id: '/outline/旧.md', title: '旧.md', content: '旧大纲' },
worldBook: { id: 'wb-1', title: '云州世界书', content: '世界书正文' },
characterCards: [
{ id: 'cc-1', title: '沈霜', content: '旧设定' },
{ id: 'cc-2', title: '陆衡', content: '陆衡旧设定' },
],
},
assembledWorldModel: {
originalTimeline: ['旧线'],
selectedCharacterProfiles: ['沈霜:旧摘要', '陆衡:不动'],
},
stableMemory: null,
volatileMemory: null,
entryPoints: [],
recommendedUserCharacters: [],
});
useBookTravelStore.getState().loadAssembledMaterial(materialId);

render(<BookTravelMaterials />);

fireEvent.click(screen.getByLabelText('刷新人设 沈霜'));
fireEvent.click(screen.getByRole('button', { name: '刷新人设' }));

await waitFor(() => {
const material = useBookTravelStore.getState().assembledMaterials[0];
expect(material.materials.characterCards[0].id).toBe('cc-new');
expect(material.materials.characterCards[0].content).toContain('新剑法');
expect(material.materials.characterCards[0].content).not.toContain('好友');
expect(material.materials.characterCards[1].content).toBe('陆衡旧设定');
expect(material.materials.outline.content).toBe('旧大纲');
expect(material.assembledWorldModel).toMatchObject({
originalTimeline: ['旧线'],
selectedCharacterProfiles: ['沈霜:姓名:沈霜 新剑法', '陆衡:不动'],
});
});
expect(useBookTravelStore.getState().selectedCharacterCards[0].id).toBe('cc-new');
expect(useBookTravelStore.getState().enabledCharacterCardIds).toEqual(['cc-new', 'cc-2']);
});
});
84 changes: 83 additions & 1 deletion src/__tests__/book-travel-materials.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { resolveOutlineMaterial, resolvePartnerMaterials } from '../utils/bookTravelMaterials';
import { refreshAssembledCharacterCards, resolveOutlineMaterial, resolvePartnerMaterials, filterBookTravelRequestContext } from '../utils/bookTravelMaterials';
import { usePartnerStore } from '../stores/usePartnerStore';

vi.mock('../utils/runtime', () => ({
Expand Down Expand Up @@ -94,4 +94,86 @@ describe('book-travel material resolution', () => {
expect(ccContent).not.toContain('与用户关系底线');
expect(ccContent).not.toContain('关键事件');
});

it('refreshes a selected character by world book and name, including a regenerated card id', () => {
usePartnerStore.setState({
worldBooks: [{ id: 'wb-1', name: '云州世界书', type: 'world_book', content: '世界书正文' }],
characterCards: [
{
id: 'cc-new',
name: '沈霜',
type: 'character_card',
content: '旧正文',
fields: { skills: '新剑法', userRelationType: '好友' },
worldBookId: 'wb-1',
},
{
id: 'cc-other-book',
name: '沈霜',
type: 'character_card',
content: '其他世界书',
fields: { skills: '不该写入' },
worldBookId: 'wb-2',
},
],
});

const refreshed = refreshAssembledCharacterCards(
[
{ id: 'cc-1', title: '沈霜', content: '旧设定' },
{ id: 'cc-2', title: '陆衡', content: '陆衡旧设定' },
],
'wb-1',
['cc-1', 'missing'],
{ originalTimeline: ['旧线'], selectedCharacterProfiles: ['沈霜:旧摘要', '陆衡:不动'] },
);

expect(refreshed.worldBookMissing).toBe(false);
expect(refreshed.characterCards[0]).toMatchObject({ id: 'cc-new', title: '沈霜' });
expect(refreshed.characterCards[0].content).toContain('新剑法');
expect(refreshed.characterCards[0].content).not.toContain('好友');
expect(refreshed.characterCards[0].content).not.toContain('不该写入');
expect(refreshed.characterCards[1].content).toBe('陆衡旧设定');
expect(refreshed.missingIds).toEqual(['missing']);
expect(refreshed.assembledWorldModel).toMatchObject({
originalTimeline: ['旧线'],
selectedCharacterProfiles: ['沈霜:姓名:沈霜 新剑法', '陆衡:不动'],
});
});

it('does not refresh characters when the bound world book is gone', () => {
usePartnerStore.setState({
worldBooks: [],
characterCards: [
{ id: 'cc-new', name: '沈霜', type: 'character_card', content: '新正文', worldBookId: 'wb-1' },
],
});

const refreshed = refreshAssembledCharacterCards(
[{ id: 'cc-1', title: '沈霜', content: '旧设定' }],
'wb-1',
['cc-1'],
{ selectedCharacterProfiles: ['沈霜:旧摘要'] },
);

expect(refreshed.worldBookMissing).toBe(true);
expect(refreshed.refreshedCards).toEqual([]);
expect(refreshed.characterCards[0].content).toBe('旧设定');
});

it('drops unchecked character cards and their profile lines from the request context', () => {
const filtered = filterBookTravelRequestContext(
[
{ id: 'cc-1', title: '沈霜', content: '沈霜完整设定' },
{ id: 'cc-2', title: '陆衡', content: '陆衡完整设定' },
],
['cc-1'],
{ selectedCharacterProfiles: ['沈霜:冷', '陆衡:稳', '旁白:无人认领'] },
);

expect(filtered.characterCards).toEqual([{ id: 'cc-1', title: '沈霜', content: '沈霜完整设定' }]);
expect(filtered.assembledWorldModel).toMatchObject({
selectedCharacterProfiles: ['沈霜:冷'],
});
});
});
29 changes: 29 additions & 0 deletions src/__tests__/book-travel-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('useBookTravelStore', () => {
selectedMaterialId: null,
savedProgresses: [],
activeSavedProgressId: null,
characterPanelOpen: true,
stylePresetPanelOpen: true,
});
});

Expand Down Expand Up @@ -215,4 +217,31 @@ describe('useBookTravelStore', () => {
useBookTravelStore.getState().resetSession();
expect(useBookTravelStore.getState().activeSavedProgressId).toBeNull();
});

it('keeps multiple style presets and panel visibility outside the saved progress', () => {
useBookTravelStore.setState({
selectedMaterialId: 'material-1',
selectedEntryPointId: 'entry-1',
userCharacter: { name: '林晚', identity: '替嫁者', goal: '改写死局' },
selectedStylePresetIds: ['preset-b', 'preset-a', 'preset-b'],
});
useBookTravelStore.getState().setCharacterPanelOpen(false);
useBookTravelStore.getState().setStylePresetPanelOpen(false);

const progressId = useBookTravelStore.getState().saveProgress({ mode: 'create', title: '多预设进度' });
const snapshot = useBookTravelStore.getState().savedProgresses[0].snapshot;
expect(snapshot.selectedStylePresetIds).toEqual(['preset-b', 'preset-a']);
expect(snapshot).not.toHaveProperty('characterPanelOpen');
expect(snapshot).not.toHaveProperty('stylePresetPanelOpen');

useBookTravelStore.getState().resetSession();
expect(useBookTravelStore.getState().characterPanelOpen).toBe(false);
expect(useBookTravelStore.getState().stylePresetPanelOpen).toBe(false);
expect(useBookTravelStore.getState().selectedStylePresetIds).toEqual([]);

useBookTravelStore.getState().loadSavedProgress(progressId);
expect(useBookTravelStore.getState().selectedStylePresetIds).toEqual(['preset-b', 'preset-a']);
expect(useBookTravelStore.getState().characterPanelOpen).toBe(false);
expect(useBookTravelStore.getState().stylePresetPanelOpen).toBe(false);
});
});
Loading