add id to BattleReplay
This commit is contained in:
@@ -705,6 +705,7 @@ export function toApiEditorSnapshot(snapshot: EditorSnapshot): EditorSnapshot {
|
||||
cloned.replays = cloned.replays.map((replay) => {
|
||||
const geometryId = typeof replay?.geometry_id === "string" ? replay.geometry_id : "";
|
||||
return {
|
||||
id: geometryId,
|
||||
geometry_id: geometryId,
|
||||
target_geometry_ids: normalizeReplayTargetGeometryIds(replay as unknown, geometryId),
|
||||
detail: Array.isArray(replay?.detail) ? replay.detail : [],
|
||||
@@ -721,8 +722,14 @@ function normalizeReplaySnapshots(value: unknown): BattleReplay[] | undefined {
|
||||
}
|
||||
|
||||
function normalizeReplaySnapshot(replay: BattleReplay): BattleReplay {
|
||||
const geometryId = typeof replay?.geometry_id === "string" ? replay.geometry_id : "";
|
||||
const geometryId =
|
||||
typeof replay?.geometry_id === "string" && replay.geometry_id.trim().length > 0
|
||||
? replay.geometry_id
|
||||
: typeof (replay as unknown as { id?: unknown })?.id === "string"
|
||||
? (replay as unknown as { id: string }).id
|
||||
: "";
|
||||
return {
|
||||
id: geometryId,
|
||||
geometry_id: geometryId,
|
||||
target_geometry_ids: normalizeReplayTargetGeometryIds(replay, geometryId),
|
||||
detail: Array.isArray(replay.detail)
|
||||
|
||||
@@ -716,6 +716,7 @@ function createReplaySessionSeed(
|
||||
selectedIds: (string | number)[]
|
||||
): BattleReplay {
|
||||
return {
|
||||
id: geometryId,
|
||||
geometry_id: geometryId,
|
||||
target_geometry_ids: buildReplaySeedTargetIds(
|
||||
sourceDraft.features.find((feature) => String(feature.properties.id) === geometryId),
|
||||
@@ -733,6 +734,7 @@ function normalizeReplaySessionSeed(
|
||||
selectedIds: (string | number)[]
|
||||
): BattleReplay {
|
||||
const nextReplay = deepClone(replay);
|
||||
nextReplay.id = geometryId;
|
||||
const triggerFeature = sourceDraft.features.find((feature) => String(feature.properties.id) === geometryId);
|
||||
const seedTargetIds = buildReplaySeedTargetIds(triggerFeature, geometryId, selectedIds);
|
||||
nextReplay.target_geometry_ids = normalizeReplayTargetGeometryIds(
|
||||
|
||||
Reference in New Issue
Block a user