11import { defineStore } from 'pinia' ;
22import { useLogStore } from '@/stores/logStore' ;
33import { useHistoryStore } from '@/stores/historyStore' ;
4+ import { useStyleStore } from '@/stores/styleStore' ;
45import { generateId } from '@/utils/id' ;
56import type { Chunk , Message } from '@/types/log' ;
67
@@ -11,6 +12,7 @@ function hasKeys<T extends object>(value: Partial<T>) {
1112export 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