Skip to content

Commit 33c2baf

Browse files
committed
fix: 修复了编辑消息时身份列表不同步的问题
- 现在编辑单条消息的 playerName/account 时会自动刷新身份/系统规则列表
1 parent 8a65c54 commit 33c2baf

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/stores/editorStore.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineStore } from 'pinia';
22
import { useLogStore } from '@/stores/logStore';
33
import { useHistoryStore } from '@/stores/historyStore';
4+
import { useStyleStore } from '@/stores/styleStore';
45
import { generateId } from '@/utils/id';
56
import type { Chunk, Message } from '@/types/log';
67

@@ -11,6 +12,7 @@ function hasKeys<T extends object>(value: Partial<T>) {
1112
export const useLogEditorStore = defineStore('logEditor', () => {
1213
const logStore = useLogStore();
1314
const historyStore = useHistoryStore();
15+
const styleStore = useStyleStore();
1416

1517
function runEdit(
1618
hasChange: boolean | (() => boolean),
@@ -145,13 +147,26 @@ export const useLogEditorStore = defineStore('logEditor', () => {
145147
if (!message) return;
146148

147149
const safeUpdates = sanitizeMessageUpdates(updates);
150+
const shouldSyncIdentities =
151+
('playerName' in safeUpdates &&
152+
!Object.is(message.playerName, safeUpdates.playerName)) ||
153+
('account' in safeUpdates &&
154+
!Object.is(message.account, safeUpdates.account));
155+
148156
runEdit(
149157
hasKeys(safeUpdates) && hasEntityUpdates(message, safeUpdates),
150158
() => {
151159
Object.assign(message, safeUpdates);
152160
},
153161
{
154-
normalize: () => logStore.normalizeMessages(chunk),
162+
normalize: () => {
163+
logStore.normalizeMessages(chunk);
164+
if (shouldSyncIdentities) {
165+
styleStore.syncSystemRulesFromMessages(
166+
logStore.allMessages,
167+
);
168+
}
169+
},
155170
},
156171
);
157172
}

0 commit comments

Comments
 (0)