Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,30 @@ static TrackableType<?> trackableTypeFor(byte typeTag) {
* set so the receiver decodes a detached CardView from the carried name
* and image key. When {@code tracker} is null, the snapshot check is
* skipped (used by the client encoder, which has no game-state awareness).
*
* <p>In non-event mode, CardViews missing from the tracker pass through
* unchanged so Java serializes the full object inline (covers ephemeral
* choice copies that never enter a tracked zone).
*/
static Object replace(Object obj, Tracker tracker, boolean eventMode) {
if (obj instanceof TrackableObject trackable) {
byte tag = typeTagFor(trackable);
if (tag < 0) return obj;

if (!eventMode || tag == TYPE_PLAYER_VIEW) {
if (tag == TYPE_PLAYER_VIEW) {
return new IdRef(tag, trackable.getId());
}

if (!eventMode) {
if (tracker != null) {
TrackableType<?> type = trackableTypeFor(tag);
if (type != null && tracker.getObj(type, trackable.getId()) != null) {
return new IdRef(tag, trackable.getId());
}
}
return obj; // ephemeral or tracker-less encoder — serialize the full object
}

boolean preserveSnapshot = false;
if (tracker != null) {
TrackableType<?> type = trackableTypeFor(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ protected void beforeCall(final ChannelHandlerContext ctx, final ProtocolMethod

/**
* This method is used to recursively update the <b>tracker</b>
* references on all objects and their props.
* references on all objects and their props, and register them in the
* id lookup so inline-serialized CardViews are findable by IdRef
* in subsequent messages.
*
* @param objs
*/
Expand All @@ -135,6 +137,7 @@ private void updateTrackers(final Object[] objs) {
if (obj instanceof TrackableObject trackableObject) {
if (trackableObject.getTracker() == null) {
trackableObject.setTracker(this.tracker);
registerInTracker(trackableObject);
// walk the props
EnumMap props = trackableObject.getProps();
if (props != null) {
Expand All @@ -153,6 +156,18 @@ private void updateTrackers(final Object[] objs) {
}
}

private void registerInTracker(final TrackableObject obj) {
if (obj instanceof CardView cv) {
if (tracker.getObj(TrackableTypes.CardViewType, cv.getId()) == null) {
tracker.putObj(TrackableTypes.CardViewType, cv.getId(), cv);
}
} else if (obj instanceof PlayerView pv) {
if (tracker.getObj(TrackableTypes.PlayerViewType, pv.getId()) == null) {
tracker.putObj(TrackableTypes.PlayerViewType, pv.getId(), pv);
}
}
}

private void replicateProps(final Object[] objs) {
for (Object obj: objs) {
if (obj instanceof PlayerView pv) {
Expand Down
Loading