refactor(game): invalidate field-level read-model projections
This commit is contained in:
@@ -9,24 +9,48 @@ export interface RealtimeReadModelChanges {
|
||||
generalIds: number[];
|
||||
cityIds: number[];
|
||||
nationIds: number[];
|
||||
/** Entity IDs whose map projection changed. Absent on older daemons. */
|
||||
mapGeneralIds?: number[];
|
||||
mapCityIds?: number[];
|
||||
mapNationIds?: number[];
|
||||
/** Generals whose name/nation projection used by front status changed. */
|
||||
frontStatusGeneralIds?: number[];
|
||||
/** Nations whose viewer-specific notice projection changed. */
|
||||
frontStatusNationIds?: number[];
|
||||
/** Generals whose viewer-specific front-status projection changed. */
|
||||
frontStatusActorIds?: number[];
|
||||
/** Generals whose name/icon projection shown in their own lobby changed. */
|
||||
lobbyGeneralIds?: number[];
|
||||
reservedGeneralIds: number[];
|
||||
recordGeneralIds: number[];
|
||||
worldChanged: boolean;
|
||||
globalRecordsChanged: boolean;
|
||||
worldHistoryChanged: boolean;
|
||||
contactsChanged: boolean;
|
||||
/** A global front-status source such as the active survey changed. */
|
||||
frontStatusChanged?: boolean;
|
||||
lobbyChanged?: boolean;
|
||||
}
|
||||
|
||||
export const createEmptyRealtimeReadModelChanges = (): RealtimeReadModelChanges => ({
|
||||
generalIds: [],
|
||||
cityIds: [],
|
||||
nationIds: [],
|
||||
mapGeneralIds: [],
|
||||
mapCityIds: [],
|
||||
mapNationIds: [],
|
||||
frontStatusGeneralIds: [],
|
||||
frontStatusNationIds: [],
|
||||
frontStatusActorIds: [],
|
||||
lobbyGeneralIds: [],
|
||||
reservedGeneralIds: [],
|
||||
recordGeneralIds: [],
|
||||
worldChanged: false,
|
||||
globalRecordsChanged: false,
|
||||
worldHistoryChanged: false,
|
||||
contactsChanged: false,
|
||||
frontStatusChanged: false,
|
||||
lobbyChanged: false,
|
||||
});
|
||||
|
||||
const mergeIds = (left: readonly number[], right: readonly number[]): number[] =>
|
||||
@@ -39,24 +63,42 @@ export const mergeRealtimeReadModelChanges = (
|
||||
generalIds: mergeIds(left.generalIds, right.generalIds),
|
||||
cityIds: mergeIds(left.cityIds, right.cityIds),
|
||||
nationIds: mergeIds(left.nationIds, right.nationIds),
|
||||
mapGeneralIds: mergeIds(left.mapGeneralIds ?? left.generalIds, right.mapGeneralIds ?? right.generalIds),
|
||||
mapCityIds: mergeIds(left.mapCityIds ?? left.cityIds, right.mapCityIds ?? right.cityIds),
|
||||
mapNationIds: mergeIds(left.mapNationIds ?? left.nationIds, right.mapNationIds ?? right.nationIds),
|
||||
frontStatusGeneralIds: mergeIds(
|
||||
left.frontStatusGeneralIds ?? (left.contactsChanged ? left.generalIds : []),
|
||||
right.frontStatusGeneralIds ?? (right.contactsChanged ? right.generalIds : [])
|
||||
),
|
||||
frontStatusNationIds: mergeIds(
|
||||
left.frontStatusNationIds ?? left.nationIds,
|
||||
right.frontStatusNationIds ?? right.nationIds
|
||||
),
|
||||
frontStatusActorIds: mergeIds(left.frontStatusActorIds ?? [], right.frontStatusActorIds ?? []),
|
||||
lobbyGeneralIds: mergeIds(left.lobbyGeneralIds ?? left.generalIds, right.lobbyGeneralIds ?? right.generalIds),
|
||||
reservedGeneralIds: mergeIds(left.reservedGeneralIds, right.reservedGeneralIds),
|
||||
recordGeneralIds: mergeIds(left.recordGeneralIds, right.recordGeneralIds),
|
||||
worldChanged: left.worldChanged || right.worldChanged,
|
||||
globalRecordsChanged: left.globalRecordsChanged || right.globalRecordsChanged,
|
||||
worldHistoryChanged: left.worldHistoryChanged || right.worldHistoryChanged,
|
||||
contactsChanged: left.contactsChanged || right.contactsChanged,
|
||||
frontStatusChanged: Boolean(left.frontStatusChanged) || Boolean(right.frontStatusChanged),
|
||||
lobbyChanged: (left.lobbyChanged ?? left.contactsChanged) || (right.lobbyChanged ?? right.contactsChanged),
|
||||
});
|
||||
|
||||
export const hasRealtimeReadModelChanges = (changes: RealtimeReadModelChanges): boolean =>
|
||||
changes.generalIds.length > 0 ||
|
||||
changes.cityIds.length > 0 ||
|
||||
changes.nationIds.length > 0 ||
|
||||
(changes.frontStatusActorIds?.length ?? 0) > 0 ||
|
||||
changes.reservedGeneralIds.length > 0 ||
|
||||
changes.recordGeneralIds.length > 0 ||
|
||||
changes.worldChanged ||
|
||||
changes.globalRecordsChanged ||
|
||||
changes.worldHistoryChanged ||
|
||||
changes.contactsChanged;
|
||||
changes.contactsChanged ||
|
||||
Boolean(changes.frontStatusChanged) ||
|
||||
Boolean(changes.lobbyChanged);
|
||||
|
||||
export interface TurnCompletedEvent {
|
||||
type: 'turnCompleted';
|
||||
|
||||
Reference in New Issue
Block a user