Skip to content

Show structure levels - #1305

Merged
evanpelle merged 7 commits into
openfrontio:mainfrom
jrouillard:show-structure-levels
Jul 2, 2025
Merged

evanpelle merged 7 commits into
openfrontio:mainfrom
jrouillard:show-structure-levels

Conversation

@jrouillard

Copy link
Copy Markdown
Contributor

Description:

Show structure levels on the structureIconsLayer
Add new bitmap font (modified from this font: https://frostyfreeze.itch.io/pixel-bitmap-fonts-png-xml CC0 license)
image

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced
  • I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors

Please put your Discord username so you can be contacted if a bug or regression is found:

Vivacious Box

@coderabbitai

coderabbitai Bot commented Jun 29, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The StructureIconsLayer was refactored to use PIXI containers instead of sprites, enabling support for displaying unit levels as bitmap text overlays. Helper methods were added to modularize update logic. A new bitmap font XML was introduced, TypeScript was updated to recognize XML imports, and the webpack config was changed to treat XML as a font asset.

Changes

File(s) Change Summary
src/client/graphics/layers/StructureIconsLayer.ts Refactored StructureIconsLayer: replaced sprites with containers, added bitmap text for levels, modularized update logic, and updated method signatures.
resources/fonts/round_6x6_modified.xml Added new bitmap font XML descriptor for displaying unit levels.
src/global.d.ts Added TypeScript module declaration for importing .xml files as strings.
webpack.config.js Updated asset loader rule to include .xml files as font assets.

Sequence Diagram(s)

sequenceDiagram
    participant GameLoop
    participant StructureIconsLayer
    participant PIXI
    participant BitmapFont

    GameLoop->>StructureIconsLayer: tick()
    StructureIconsLayer->>StructureIconsLayer: handleActiveUnit(unit)
    StructureIconsLayer->>StructureIconsLayer: checkForOwnershipChange(render, unit)
    StructureIconsLayer->>StructureIconsLayer: checkForLevelChange(render, unit)
    alt New structure needed
        StructureIconsLayer->>StructureIconsLayer: addNewStructure(unit)
        StructureIconsLayer->>StructureIconsLayer: createPixiSprite(unit)
        StructureIconsLayer->>PIXI: Create Container & Sprite
        StructureIconsLayer->>BitmapFont: Add bitmap text if level > 1
    end
    StructureIconsLayer->>PIXI: Update container position/scale
    StructureIconsLayer->>StructureIconsLayer: handleInactiveUnit(unit)
    StructureIconsLayer->>PIXI: Remove container if needed
Loading

Possibly related PRs

  • openfrontio/OpenFrontIO#1287: Originally introduced StructureIconsLayer and added it to the renderer; this PR directly builds upon and modifies that code.

Suggested reviewers

  • scottanderson

Poem

In the land of icons, sprites are no more,
Containers now gather, with levels to show.
Bitmap fonts join, crisp and bright,
XML and TypeScript make the import right.
A modular layer, neat and clear—
Rendering structures, year after year!
🏗️✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-01T21_06_46_946Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1494c0e and 11d4fb9.

📒 Files selected for processing (1)
  • src/client/graphics/layers/StructureIconsLayer.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/graphics/layers/StructureIconsLayer.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: 🏗️ Build

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
resources/fonts/round_6x6.xml (1)

16-16: Minor: Standardize attribute spacing

Some lines have extra space before the width attribute.

-        <char id="67" x="32" y="0"  width="16" height="16" page="0" xadvance="14" xoffset="0" yoffset="0"/>
+        <char id="67" x="32" y="0" width="16" height="16" page="0" xadvance="14" xoffset="0" yoffset="0"/>

Also applies to: 19-19, 22-22, 25-25, 28-28, 31-31, 34-34, 37-37, 40-40, 43-43, 46-46

src/client/graphics/layers/StructureIconsLayer.ts (1)

252-263: Consider showing all unit levels for consistency

Currently only shows level for units > 1. Consider showing all levels for clarity.

-    if (unit.level() > 1) {
+    if (unit.level() > 0) {

Also consider making font size proportional to icon size:

-          fontSize: 8,
+          fontSize: Math.max(8, Math.floor(ICON_SIZE / 3)),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca522a5 and 928d7fc.

⛔ Files ignored due to path filters (1)
  • resources/fonts/round_6x6.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • resources/fonts/round_6x6.xml (1 hunks)
  • src/client/graphics/layers/StructureIconsLayer.ts (6 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: andrewNiziolek
PR: openfrontio/OpenFrontIO#1007
File: resources/lang/de.json:115-115
Timestamp: 2025-06-02T14:27:37.609Z
Learning: For OpenFrontIO project: When localization keys are renamed in language JSON files, the maintainers separate technical changes from translation content updates. They wait for community translators to update the actual translation values rather than attempting to translate in the same PR. This allows technical changes to proceed while ensuring accurate translations from native speakers.
src/client/graphics/layers/StructureIconsLayer.ts (1)
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
🧬 Code Graph Analysis (1)
src/client/graphics/layers/StructureIconsLayer.ts (1)
src/core/game/GameView.ts (2)
  • UnitView (45-142)
  • unit (531-533)
🔇 Additional comments (3)
src/client/graphics/layers/StructureIconsLayer.ts (3)

131-173: Clean refactoring with helper methods

Good separation of concerns. The helper methods improve readability and follow single responsibility principle.


264-270: Proper Container positioning and scaling

Good implementation maintaining existing offset logic and preventing oversized icons at high zoom.


320-331: Well-structured helper method

Clean encapsulation of structure addition logic. Properly initializes all properties.

Comment thread resources/fonts/round_6x6.xml Resolved
Comment thread resources/fonts/round_6x6.xml Resolved
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jun 29, 2025
@jrouillard
jrouillard marked this pull request as draft June 29, 2025 03:48
@scottanderson scottanderson added this to the v24 milestone Jun 29, 2025
@scottanderson scottanderson added Meta Minor balancing adjustment, mostly value changes, minor calculation changes. Feature - New UI/UX UI/UX changes including assets, menus, QoL, etc. Release Blocker This feature/bug is a priority to work on labels Jun 29, 2025
@scottanderson scottanderson linked an issue Jun 30, 2025 that may be closed by this pull request
@scottanderson

Copy link
Copy Markdown
Contributor

Fixes #1300

@jrouillard
jrouillard marked this pull request as ready for review July 1, 2025 21:03
@jrouillard jrouillard mentioned this pull request Jul 1, 2025
5 tasks done
@github-project-automation github-project-automation Bot moved this from Development to Final Review in OpenFront Release Management Jul 1, 2025
@evanpelle
evanpelle merged commit c5c04a8 into openfrontio:main Jul 2, 2025
@github-project-automation github-project-automation Bot moved this from Final Review to Complete in OpenFront Release Management Jul 2, 2025
evanpelle pushed a commit that referenced this pull request Jul 3, 2025
## Description:

REQUIRES THE LEVEL PR TO BE MERGED FIRST (as it is using the same layer)
#1305

#### Icons only zoom level

![image](https://github.com/user-attachments/assets/2ce30a5b-281c-425a-add6-55745c930859)

#### Icons and sprite zoom level

![image](https://github.com/user-attachments/assets/ad8018d7-0537-4baf-b97e-d38b0ccec6cd)

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

Vivacious Box

---------

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
@coderabbitai coderabbitai Bot mentioned this pull request Jul 24, 2025
5 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Minor balancing adjustment, mostly value changes, minor calculation changes. Release Blocker This feature/bug is a priority to work on UI/UX UI/UX changes including assets, menus, QoL, etc.

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

UI Show Unit Level

3 participants