Closed jdoleary closed 1 week ago
Events must be deep cloned when a unit is serializes so that the serialized unit doesn't share the same object.
I could do something like:
export function cloneEvents(unit: IUnit): IUnit { const { onDealDamageEvents, onTakeDamageEvents, onDeathEvents, onAgroEvents, onTurnStartEvents, onTurnEndEvents, onDrawSelectedEvents, onTeleportEvents, ...rest } = unit; return { ...rest, // Deep copy array so that serialized units don't share the object onDealDamageEvents: [...onDealDamageEvents], onTakeDamageEvents: [...onTakeDamageEvents], onDeathEvents: [...onDeathEvents], onAgroEvents: [...onAgroEvents], onTurnStartEvents: [...onTurnStartEvents], onTurnEndEvents: [...onTurnEndEvents], onDrawSelectedEvents: [...onDrawSelectedEvents], onTeleportEvents: [...onTeleportEvents], } }
and then write a test but maybe I ought to just JSON.stringify the whole ...rest object?
Maybe refactor events arrays to just be one array?
Done in #828
Events must be deep cloned when a unit is serializes so that the serialized unit doesn't share the same object.
I could do something like:
and then write a test but maybe I ought to just JSON.stringify the whole ...rest object?