compare: observe nation history in turn snapshots
This commit is contained in:
@@ -190,6 +190,7 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
$nationIds = comparisonIntegerList($observe['nationIds'] ?? [], 'nationIds');
|
$nationIds = comparisonIntegerList($observe['nationIds'] ?? [], 'nationIds');
|
||||||
$logAfterId = $observe['logAfterId'] ?? 0;
|
$logAfterId = $observe['logAfterId'] ?? 0;
|
||||||
$messageAfterId = $observe['messageAfterId'] ?? 0;
|
$messageAfterId = $observe['messageAfterId'] ?? 0;
|
||||||
|
$includeNationHistoryLogs = $observe['includeNationHistoryLogs'] ?? false;
|
||||||
$generalCooldownSelectors = comparisonGeneralCooldownSelectors(
|
$generalCooldownSelectors = comparisonGeneralCooldownSelectors(
|
||||||
$observe['generalCooldowns'] ?? [],
|
$observe['generalCooldowns'] ?? [],
|
||||||
'generalCooldowns',
|
'generalCooldowns',
|
||||||
@@ -202,9 +203,17 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
$observe['diplomacyPairs'] ?? [],
|
$observe['diplomacyPairs'] ?? [],
|
||||||
'diplomacyPairs',
|
'diplomacyPairs',
|
||||||
);
|
);
|
||||||
if (!is_int($logAfterId) || $logAfterId < 0 || !is_int($messageAfterId) || $messageAfterId < 0) {
|
if (
|
||||||
|
!is_int($logAfterId)
|
||||||
|
|| $logAfterId < 0
|
||||||
|
|| !is_int($messageAfterId)
|
||||||
|
|| $messageAfterId < 0
|
||||||
|
) {
|
||||||
throw new \InvalidArgumentException('logAfterId and messageAfterId must be non-negative integers');
|
throw new \InvalidArgumentException('logAfterId and messageAfterId must be non-negative integers');
|
||||||
}
|
}
|
||||||
|
if (!is_bool($includeNationHistoryLogs)) {
|
||||||
|
throw new \InvalidArgumentException('includeNationHistoryLogs must be a boolean');
|
||||||
|
}
|
||||||
|
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
$game = KVStorage::getStorage($db, 'game_env');
|
$game = KVStorage::getStorage($db, 'game_env');
|
||||||
@@ -486,6 +495,24 @@ function comparisonTurnStateSnapshot(array $request): array
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($includeNationHistoryLogs && $nationIds !== []) {
|
||||||
|
foreach ($db->query(
|
||||||
|
'SELECT id, nation_id, year, month, text FROM world_history WHERE nation_id IN %li ORDER BY id',
|
||||||
|
$nationIds,
|
||||||
|
) as $row) {
|
||||||
|
$logs[] = comparisonPickRow($row, [
|
||||||
|
'id' => 'id',
|
||||||
|
'nationId' => 'nation_id',
|
||||||
|
'year' => 'year',
|
||||||
|
'month' => 'month',
|
||||||
|
'text' => 'text',
|
||||||
|
]) + [
|
||||||
|
'scope' => 'nation',
|
||||||
|
'category' => 'history',
|
||||||
|
'generalId' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$messages = array_map(
|
$messages = array_map(
|
||||||
static fn(array $row): array => comparisonPickRow(
|
static fn(array $row): array => comparisonPickRow(
|
||||||
|
|||||||
Reference in New Issue
Block a user