8000 Robust optimization & fixing of hero-icon-images by Chaboi45 · Pull Request #7953 · codecombat/codecombat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Robust optimization & fixing of hero-icon-images #7953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Chaboi45
Copy link
Contributor
@Chaboi45 Chaboi45 commented Mar 31, 2025

The old method for loading hero icon images in main campaign involved using an old spritesheet(which contained the original heroes only) I reoptimized the process by loading hero images through user DB's hero thang ID, which means the code doesn't need updating in the future when more heroes are introduced.

Before
Screenshot 2025-03-31 at 18 13 35
Screenshot 2025-03-31 at 18 14 07

After
Screenshot 2025-03-31 at 14 58 34

Screenshot 2025-03-31 at 14 57 48

Summary by CodeRabbit

  • Style

    • Redesigned hero icon appearances for a cleaner, more consistent display across clans and campaign views. Icons now use a refreshed image approach with updated sizing, padding, and margin adjustments.
  • Refactor

    • Streamlined the icon update process so that hero images are loaded directly, ensuring more reliable and efficient visual updates during gameplay.

The old method for loading hero icon images in main campaign involved using an old spritesheet(which contained the original heroes only) I reoptimized the process by loading hero images through user DB's hero thang ID, which means the code doesn't need updating in the future when more heroes are introduced.
Copy link
Contributor
coderabbitai bot commented Mar 31, 2025

Walkthrough

This pull request updates the way player hero icons are rendered across the application. The previous sprite-based .player-hero-icon implementation is removed in favor of a simplified system using the new .player-hero class that displays individual image files. Changes span style sheets, template files, and JavaScript methods in both the clan details and campaign view components, where HTML elements are switched from spans to images and icon updates now involve setting the image source directly.

Changes

File(s) Change Summary
app/styles/clans/clan-details.sass
app/styles/play/campaign-view.sass
Removed the .player-hero-icon (and .player-name in campaign-view) classes and added .player-hero with updated properties, including a fixed width/height, new background image settings, padding, and margin adjustments.
app/templates/clans/clan-details.pug
app/templates/play/campaign-view.pug
Replaced <span> elements using the .player-hero-icon class with <img> elements using the new .player-hero class, ensuring consistent rendering of hero icons in the templates.
app/views/clans/ClanDetailsView.js
app/views/play/CampaignView.js
Modified methods updating hero icons: the clan view now sets the src attribute on .player-hero elements, and the campaign view simplifies the iteration over heroes to update the image source directly, replacing previous class-based manipulations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant View
    participant HeroIconElement

    User->>View: Triggers hero icon update
    View->>HeroIconElement: Locate element with class ".player-hero"
    View->>View: Compute new image source based on hero variable
    View->>HeroIconElement: Set the src attribute to the new image path
    HeroIconElement-->>User: Render updated hero icon
Loading

Possibly related PRs

Suggested reviewers

  • mrfinch

Poem

I'm just a rabbit, hopping with cheer,
As old sprites fade and new images appear.
The icons now shine with a fresh new glow,
With simple code paths that smoothly flow.
Carrots and code, together we leap—
In the garden of change, our joy runs deep!

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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:
    • < 8000 code class="notranslate">@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 generate unit testing code.
    • @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.

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 docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link
Contributor
@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/styles/play/campaign-view.sass (1)

654-654: Removed unnecessary whitespace

These blank lines with whitespace should be removed to maintain clean formatting in the stylesheet.

- $spriteSheetSize: 30px
-
-  
-
- .level-indicator
+ $spriteSheetSize: 30px
+ 
+ .level-indicator
- margin: 0 2px
-
-     
-
-  .campaign-control-button
+ margin: 0 2px
+ 
+ .campaign-control-button

Also applies to: 662-662

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68007cd and f7ca36b.

⛔ Files ignored due to path filters (1)
  • app/assets/images/pages/play/hero-portrait-frame.png is excluded by !**/*.png
📒 Files selected for processing (6)
  • app/styles/clans/clan-details.sass (1 hunks)
  • app/styles/play/campaign-view.sass (1 hunks)
  • app/templates/clans/clan-details.pug (3 hunks)
  • app/templates/play/campaign-view.pug (1 hunks)
  • app/views/clans/ClanDetailsView.js (1 hunks)
  • app/views/play/CampaignView.js (1 hunks)
🔇 Additional comments (8)
app/templates/play/campaign-view.pug (1)

397-397: Good refactoring of hero icon implementation.

Converting from a span with background image to a direct img element is a good approach for making the code more maintainable and scalable. This change aligns perfectly with the PR objective of optimizing hero icon images to handle new heroes dynamically.

app/views/clans/ClanDetailsView.js (1)

350-350: Excellent improvement to hero icon update logic.

This change properly transitions from the previous class-based approach to directly setting the image source, making it much more maintainable. The new implementation dynamically loads hero portraits from the database using the hero's ThangType ID, which ensures the system will automatically work with new heroes without code modifications.

app/styles/clans/clan-details.sass (1)

146-151: Clean CSS implementation for the new hero image approach.

The new .player-hero class effectively supports the transition from spritesheet-based icons to individual image elements. The styling provides a consistent frame and sizing while allowing hero portraits to be loaded dynamically. This greatly simplifies the CSS by eliminating the need for hero-specific style rules, making the codebase more maintainable and scalable.

app/views/play/CampaignView.js (1)

1724-1729: Improved hero image loading implementation

This change simplifies the hero updating logic by directly setting the image source rather than swapping CSS classes, making the code more straightforward and maintainable. This approach will also better support new heroes as they're added.

-    for (const [slug, original] of Object.entries(ThangType.heroes)) {
-      if (original === hero) {
-        this.$el.find('.player-hero-icon').removeClass('player-hero-icon-' + ('collected' in ThangType.heroes ? 'bronze' : 'null'))
-        this.$el.find('.player-hero-icon').addClass('player-hero-icon-' + slug)
+    for (const original of Object.values(ThangType.heroes)) {
+      if (original === hero) {
+        this.$el.find('.player-hero').attr('src', `/file/db/thang.type/${hero}/portrait.png`)
app/templates/clans/clan-details.pug (3)

53-53: Changed span to img element for clan chieftain hero

Converting from a span with CSS sprite background to an actual img element improves semantic HTML and accessibility. This change also aligns with the new approach for hero images throughout the application.


144-144: Changed span to img element for premium dashboard member hero

Consistent with the previous change, this improves semantic HTML by using an img element instead of a styled span for member heroes in the premium dashboard view.


241-241: Changed span to img element for basic dashboard member hero

Completing the conversion from spans to img elements for all hero icons in the clan details view. This ensures consistency across the application.

app/styles/play/campaign-view.sass (1)

640-648: Updated player hero styling for new image-based approach

The new CSS for .player-hero properly defines dimensions, padding, and margins for the hero images. This replaces the old sprite-based approach with a cleaner, more maintainable solution.

- .player-name
-   margin-left: 45px

+ .player-hero
+   height: 30px
+   width: 30px
+   background-image: url(/images/pages/play/hero-portrait-frame.png)
+   padding: 6px
+   background-size: contain
+   margin-left: 10px
+   margin-right: 2px

- .player-hero-icon
-   background: url(/images/pages/play/play-spritesheet.png) no-repeat
-   width: 30px
-   height: 30px
-   display: inline-block
-   margin: 0px 5px 0px 5px

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0