Add symbol size migration: update outdated defaults on load
When loading saved state, symbols with known outdated default sizes (e.g., photoeye 56x20) are migrated to current defaults (30x14). Only exact matches of old defaults are migrated — user-resized symbols keep their custom dimensions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
006692de32
commit
b0648f06b6
@ -1,4 +1,14 @@
|
||||
import type { PlacedSymbol, EpcWaypoint } from './types.js';
|
||||
import { SYMBOLS } from './symbols.js';
|
||||
|
||||
/** Map of symbolId → current default {w, h} for migration */
|
||||
const DEFAULT_SIZES = new Map(SYMBOLS.map(s => [s.id, { w: s.w, h: s.h }]));
|
||||
|
||||
/** Known outdated defaults: symbolId → [{oldW, oldH}] */
|
||||
const OUTDATED_SIZES: Record<string, { w: number; h: number }[]> = {
|
||||
photoeye: [{ w: 56, h: 20 }],
|
||||
photoeye_v: [{ w: 56, h: 20 }],
|
||||
};
|
||||
|
||||
/** JSON shape stored in localStorage / exported JSON files */
|
||||
export interface SerializedSymbol {
|
||||
@ -38,6 +48,18 @@ export function serializeSymbol(sym: PlacedSymbol): SerializedSymbol {
|
||||
}
|
||||
|
||||
export function deserializeSymbol(data: SerializedSymbol, id: number): PlacedSymbol {
|
||||
let { w, h } = data;
|
||||
|
||||
// Migrate outdated default sizes to current defaults
|
||||
const outdated = OUTDATED_SIZES[data.symbolId];
|
||||
if (outdated) {
|
||||
const current = DEFAULT_SIZES.get(data.symbolId);
|
||||
if (current && outdated.some(o => o.w === w && o.h === h)) {
|
||||
w = current.w;
|
||||
h = current.h;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
symbolId: data.symbolId,
|
||||
@ -46,8 +68,8 @@ export function deserializeSymbol(data: SerializedSymbol, id: number): PlacedSym
|
||||
file: data.file?.replace('_no_comm.svg', '.svg') || data.file,
|
||||
x: data.x,
|
||||
y: data.y,
|
||||
w: data.w,
|
||||
h: data.h,
|
||||
w,
|
||||
h,
|
||||
w2: data.w2,
|
||||
rotation: data.rotation || 0,
|
||||
mirrored: data.mirrored || false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user