Skip to content

fix(server): zone-to-gap transition updates entity zone#74

Merged
ComBba merged 3 commits intomainfrom
fix/zone-to-gap-transition
Feb 12, 2026
Merged

fix(server): zone-to-gap transition updates entity zone#74
ComBba merged 3 commits intomainfrom
fix/zone-to-gap-transition

Conversation

@ComBba
Copy link
Copy Markdown
Contributor

@ComBba ComBba commented Feb 12, 2026

Summary

  • Fix bug where entity's currentZone was not updated when moving from a zone to a gap (non-zone area)
  • Previously, the UI would show stale zone information when player left a zone

Changes

  • EntitySchema: Change currentZone type from ZoneId to string with empty default
  • EntitySchema: Add clearZone() method for explicit zone clearing
  • EntitySchema: Update setZone() to accept null (converts to empty string)
  • ZoneSystem: Call clearZone() when entity leaves zone to gap area

Root Cause

In ZoneSystem.update(), the entity zone was only updated when entering a new zone:

if (currentZone !== null) {
  entity.setZone(currentZone);  // Only called when in a zone
}

When moving to a gap (currentZone === null), the entity's zone was never cleared.

Testing

  • All 958 tests pass
  • TypeScript compiles without errors

Summary by CodeRabbit

릴리스 노트

  • 버그 수정
    • 존(Zone) 진입·퇴출 알림 및 배너 표시가 더 일관되게 작동하도록 개선
    • 존 전환 시 중복 알림/이벤트 발생 문제 해결
    • 엔티티가 존을 떠날 때 상태가 명확히 초기화되어 존 추적 정확도 향상

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

Walkthrough

클라이언트의 GameScene에서 previousZone nullable 처리를 명확히 하고, 서버의 EntitySchema에 zone 타입·메서드 변경(nullable 지원 및 clearZone 추가)을 도입하며 ZoneSystem에서 엔티티가 존을 벗길 때 clearZone 호출을 일관되게 적용했습니다.

Changes

Cohort / File(s) Summary
클라이언트: GameScene
packages/client/src/game/scenes/GameScene.ts
previousZone을 `ZoneId
서버: Entity 스키마
packages/server/src/schemas/EntitySchema.ts
currentZone 타입을 ZoneIdstring(기본 '')으로 변경. `setZone(zone: ZoneId
서버: ZoneSystem
packages/server/src/zone/ZoneSystem.ts
엔티티가 존을 떠날 때(또는 currentZone null) entity.clearZone()를 호출하도록 로직 통일. entityZones 업데이트 및 삭제 흐름을 else 분기에서 정렬하여 사이드 이펙트 일관성 확보.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

world

Poem

🐰 존을 훌쩍 넘는 토끼가 말하네,
깃발은 펄럭이고 배너는 반짝여,
null과 문자열 사이 길을 닦았더니,
발자국은 더 또렷해졌구나. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 주요 변경 사항과 정확하게 일치합니다. 'zone-to-gap transition updates entity zone'은 핵심 문제(엔티티가 존에서 간격으로 이동할 때 currentZone이 초기화되지 않던 버그)를 명확하게 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/zone-to-gap-transition

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
packages/server/src/zone/ZoneSystem.ts (1)

165-185: removeEntity의 API 설계 일관성 개선 검토

removeEntityEntitySchema 객체를 받지 않아 clearZone()을 호출하지 못하는 것은 맞습니다. 하지만 현재 코드베이스의 실제 사용 패턴에서는 문제가 되지 않습니다:

  • update() 메서드 내: 엔티티가 영역을 벗어날 때 clearZone()이 이미 호출되고(150줄) 이후 removeEntity가 호출되므로 stale 상태가 발생하지 않음
  • GameRoom.onLeave() 호출: 엔티티가 removeEntity 직후 상태에서 즉시 삭제되므로(347줄) 이후 참조 불가능

API 일관성을 위해 removeEntity가 엔티티 객체를 선택 파라미터로 받도록 하거나, 내부에서 clearZone()을 호출하도록 개선할 수 있지만, 현재 동작상 문제는 없습니다.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @ComBba, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug that caused an entity's zone information to become outdated when it moved from a designated zone into an undefined, non-zoned area. The changes ensure that the server-side currentZone property on entities is consistently and accurately maintained, reflecting whether an entity is within a zone or not. This improved data consistency directly translates to a more reliable and accurate user interface, where zone entry and exit notifications are now correctly displayed for all transitions, including those to 'gap' areas.

Highlights

  • Bug Fix: Resolved an issue where an entity's currentZone was not updated when moving from a defined zone to a non-zone area (gap), leading to stale UI information.
  • Schema Update: Modified the EntitySchema to change the currentZone type from ZoneId to string and set its default value to an empty string, allowing it to represent a 'no zone' state.
  • Zone Management API: Introduced a clearZone() method in EntitySchema for explicitly clearing an entity's zone and updated setZone() to gracefully handle null input by converting it to an empty string.
  • Server-Side Logic: Integrated the new clearZone() method into the ZoneSystem to ensure that an entity's zone is correctly cleared when it transitions out of any defined zone.
  • Client-Side UI: Enhanced the GameScene to accurately display 'Left zone' notifications when an entity moves from a zone to a gap, improving the user experience.
Changelog
  • packages/client/src/game/scenes/GameScene.ts
    • Modified checkZoneChange to correctly detect and display 'Left zone' notifications when an entity moves from a zone to a non-zone area.
    • Added 'Entered zone' notifications for clarity when an entity enters a zone from a non-zone area.
  • packages/server/src/schemas/EntitySchema.ts
    • Changed the currentZone property type from ZoneId to string and updated its default value from 'plaza' to an empty string.
    • Added a new clearZone() method to explicitly set currentZone to an empty string.
    • Updated the setZone() method to accept ZoneId | null and assign an empty string if null is provided.
  • packages/server/src/zone/ZoneSystem.ts
    • Modified the update method to call entity.clearZone() when an entity is no longer detected within any zone, ensuring its currentZone is reset.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/server/src/zone/ZoneSystem.ts (1)

132-134: ⚠️ Potential issue | 🟠 Major

updateEntityZone에서도 동일한 갭 전환 버그가 존재합니다.

update() 메서드에서는 entity.clearZone()을 호출하도록 수정했지만, updateEntityZone() 메서드의 else 분기(Line 132-134)에서는 entity가 전달되어도 clearZone()을 호출하지 않습니다. 동일한 패턴의 버그가 남아있습니다.

🐛 제안된 수정
       } else {
+        if (entity) {
+          entity.clearZone();
+        }
         this.entityZones.delete(entityId);
       }
🧹 Nitpick comments (3)
packages/server/src/schemas/EntitySchema.ts (1)

97-98: currentZone 타입이 string으로 약화되어 타입 안전성이 저하됩니다.

이전에는 ZoneId 타입이었지만 이제 string으로 변경되어 임의의 문자열이 할당 가능합니다. "존 없음" 상태를 표현하면서 타입 안전성을 유지하려면 ZoneId | ''를 사용하는 것이 좋습니다.

♻️ 제안된 수정
  `@type`('string')
- currentZone: string = '';
+ currentZone: ZoneId | '' = '';
packages/client/src/game/scenes/GameScene.ts (2)

753-756: currentZone 추출 시 타입 캐스팅이 취약합니다.

서버에서 currentZone은 이제 string이고 빈 문자열('')로 "존 없음"을 나타냅니다. 하지만 as unknown as { currentZone?: ZoneId } 캐스팅과 ?? nullundefinednull로 변환하고 ''는 변환하지 않습니다. 현재는 ''가 falsy이기 때문에 아래 조건문에서 우연히 올바르게 동작하지만, 의도를 명확히 하면 유지보수성이 높아집니다.

♻️ 제안된 수정
- const currentZone = (entity as unknown as { currentZone?: ZoneId }).currentZone ?? null;
+ const rawZone = (entity as unknown as { currentZone?: string }).currentZone;
+ const currentZone: ZoneId | null = rawZone ? (rawZone as ZoneId) : null;

이렇게 하면 빈 문자열도 명시적으로 null로 변환되어, 타입과 런타임 동작이 일치합니다.


787-787: previousZonenull 할당 시 타입 불일치 가능성이 있습니다.

previousZoneZoneId | undefined로 선언되어 있지만(Line 56), currentZonenull일 때 this.previousZone = currentZonenull이 할당됩니다. nullundefined와 다르므로 strict TypeScript에서는 타입 에러가 될 수 있습니다. previousZone 타입을 ZoneId | null로 변경하거나, 할당 시 currentZone ?? undefined를 사용하세요.

♻️ 옵션 1: 타입 변경
- private previousZone?: ZoneId;
+ private previousZone: ZoneId | null = null;

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively fixes a bug where an entity's zone information was not updated when moving from a zoned area to a non-zoned area. The changes to EntitySchema to use an empty string for 'no zone' and the corresponding updates in ZoneSystem are well-implemented. The client-side logic in GameScene is also correctly updated to handle these changes and reflect them in the UI. I've included one suggestion to refactor a part of the client-side code for improved clarity and maintainability. Overall, this is a solid fix.

- EntitySchema: change currentZone type to string, default empty
- EntitySchema: add clearZone() method for explicit zone clearing
- EntitySchema: setZone() now accepts null (converts to empty string)
- ZoneSystem: call clearZone() when entity leaves zone to gap area

Previously, when a player moved from a zone to a gap (non-zone area),
the currentZone property was never updated, causing the client to
display stale zone information in the UI.
Address CodeRabbit review feedback - updateEntityZone had the same
gap transition bug where entity.clearZone() was not called when
moving to a non-zone area.
- Change previousZone type from ZoneId | undefined to ZoneId | null
- Convert empty string currentZone to null for proper zone detection
- Cast valid zone strings back to ZoneId type for UI components

Addresses CodeRabbit review feedback on type safety.
@ComBba ComBba force-pushed the fix/zone-to-gap-transition branch from 4f7c43d to 3aa8bef Compare February 12, 2026 03:21
@ComBba ComBba merged commit 848b885 into main Feb 12, 2026
10 checks passed
@ComBba ComBba deleted the fix/zone-to-gap-transition branch February 12, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant