Skip to content

Board and Tetromino Styles#17

Merged
finityfly merged 5 commits intomainfrom
feat-cosmetics
Jul 21, 2025
Merged

Board and Tetromino Styles#17
finityfly merged 5 commits intomainfrom
feat-cosmetics

Conversation

@finityfly
Copy link
Owner

@finityfly finityfly commented Jul 9, 2025

#14

Summary by CodeRabbit

  • New Features
    • Added the ability to customize and retrieve the display character for tetromino pieces.
    • Tetromino pieces now render using the chosen character with bold color styling during gameplay and in previews.
  • Bug Fixes
    • Improved initialization of the hold piece for consistent behavior.
  • UI Improvements
    • Updated menu separator line style for enhanced visual clarity.

@coderabbitai
Copy link

coderabbitai bot commented Jul 9, 2025

Walkthrough

A new static character setting tetrominoCharacter was added to the Settings class with getter and setter methods. The settings UI and configuration persistence were updated to include this character. The UI rendering of tetromino blocks was changed to use this character with bold color attributes. Minor adjustments were made to menu separators and Game::reset() initialization.

Changes

File(s) Change Summary
include/Settings.h Added static private member tetrominoCharacter and public static getter/setter methods for it in Settings class.
src/Settings.cpp Defined and initialized tetrominoCharacter; updated configure(), saveConfig(), and loadConfig() to handle the new character setting; changed menu separator char from "─" to "="; added config versioning, endianness handling, and robust error checking.
src/UI.cpp Modified tetromino rendering functions to use Settings::getTetrominoCharacter() with bold color attributes instead of spaces/dots; added <cstring>.
src/Game.cpp Added #include <algorithm>; changed holdPiece initialization in reset() from NULL to Tetromino(0).
src/Menu.cpp Removed extra blank line; changed menu separator line from "─" to "=" with dim attribute.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant Settings
    participant ConfigFile

    UI->>Settings: getTetrominoCharacter()
    Settings-->>UI: return tetrominoCharacter

    UI->>Settings: setTetrominoCharacter(character)
    Settings-->>Settings: update tetrominoCharacter

    Settings->>ConfigFile: saveConfig()
    ConfigFile-->>Settings: write tetrominoCharacter with version and endianness

    Settings->>ConfigFile: loadConfig()
    ConfigFile-->>Settings: read and validate version, read tetrominoCharacter with error handling
Loading

Estimated code review effort

2 (~20 minutes)

Poem

🐇 A tiny hop, a style anew,
Tetromino blocks wear characters true.
From dots to bold, they now display,
A single char that leads the way.
Settings hold the secret key,
To brighten games for you and me! 🎮✨

✨ 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.
    • 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 docstrings to generate docstrings for this 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.

@finityfly finityfly linked an issue Jul 9, 2025 that may be closed by this pull request
Copy link

@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: 1

🧹 Nitpick comments (1)
include/Settings.h (1)

7-10: Consider moving the struct inside the Settings class.

The TetrominoStyle struct is currently defined in the global namespace, which could lead to naming conflicts. Consider moving it inside the Settings class as a nested struct or adding a namespace to improve encapsulation.

+class Settings {
+public:
+    struct TetrominoStyle {
+        char character;
+        std::string color;
+    };
+    
-struct TetrominoStyle {
-    char character;
-    std::string color;
-};

-class Settings {
-public:
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0de110e and 54c7726.

📒 Files selected for processing (1)
  • include/Settings.h (3 hunks)
🔇 Additional comments (1)
include/Settings.h (1)

29-32: LGTM! Clean interface design.

The getter and setter methods provide a clean interface for accessing tetromino styles. The const reference return type for the getter is efficient, and the parameters use const references appropriately.

Comment on lines +44 to +45
static std::unordered_map<std::string, TetrominoStyle> tetrominoStyles;

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify static member definition in implementation file.

The static member tetrominoStyles is declared but needs to be defined in a corresponding .cpp file to avoid linker errors. Ensure this is properly initialized alongside other static members.


🏁 Script executed:

#!/bin/bash
# Description: Check if static member tetrominoStyles is defined in implementation files
# Expected: Find definition of tetrominoStyles in a .cpp file

# Search for tetrominoStyles definition in source files
rg -t cpp "tetrominoStyles.*=" --type-add 'cpp:*.{cpp,cc,cxx}'

# Also check for any Settings class implementation files
fd -e cpp -e cc -e cxx Settings

Length of output: 178


🏁 Script executed:

#!/bin/bash
# Verify if the static member tetrominoStyles is defined in src/Settings.cpp
rg -n "Settings::tetrominoStyles" src/Settings.cpp

Length of output: 50


Add missing static member definition for tetrominoStyles

The declaration in include/Settings.h isn’t matched by a definition in src/Settings.cpp, which will cause a linker error. Please add the following to src/Settings.cpp (typically alongside other static member definitions, after your #include directives):

#include "Settings.h"

// Define the static member declared in Settings.h
std::unordered_map<std::string, TetrominoStyle> Settings::tetrominoStyles;

This ensures the linker has a single, global instance of tetrominoStyles.

🤖 Prompt for AI Agents
In include/Settings.h at lines 44-45, the static member tetrominoStyles is
declared but not defined, causing linker errors. To fix this, add a definition
for tetrominoStyles in src/Settings.cpp after the #include directives by
defining std::unordered_map<std::string, TetrominoStyle>
Settings::tetrominoStyles; This provides a single global instance for the
linker.

Copy link

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54c7726 and 41e1b26.

📒 Files selected for processing (3)
  • include/Settings.h (3 hunks)
  • src/Settings.cpp (4 hunks)
  • src/UI.cpp (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/UI.cpp (3)
include/Settings.h (3)
  • type (29-29)
  • tetromino (30-32)
  • tetromino (30-30)
src/Settings.cpp (2)
  • getTetrominoStyle (343-349)
  • getTetrominoStyle (343-343)
include/UI.h (6)
  • win (11-11)
  • win (12-12)
  • win (13-13)
  • win (14-14)
  • win (15-15)
  • win (16-16)
🔇 Additional comments (9)
src/UI.cpp (3)

32-34: Good integration of configurable tetromino styles.

The implementation correctly retrieves the tetromino style and uses the appropriate character based on the rendering context (ghost pieces use '.' while normal pieces use the configured character).


53-56: Proper usage of styled character for tetromino rendering.

The rendering logic correctly applies the configured character from the TetrominoStyle with appropriate color and bold attributes.


88-91: Consistent style application in piece box rendering.

The piece box rendering properly retrieves and uses the tetromino style, maintaining consistency with the main board rendering.

include/Settings.h (3)

7-10: Well-defined TetrominoStyle structure.

The struct clearly encapsulates the character and color properties needed for tetromino customization.


29-32: Appropriate public interface for tetromino style management.

The getter and setter methods provide a clean interface for accessing and modifying tetromino styles.


44-45: Static member definition is properly implemented.

The static member tetrominoStyles is correctly defined and initialized in src/Settings.cpp at lines 35-43, resolving the previous linker error concern.

src/Settings.cpp (3)

35-43: Comprehensive initialization of tetromino styles.

All 7 standard tetromino types (I, J, L, O, S, T, Z) are properly initialized with appropriate default colors and 'x' character. This resolves the static member definition issue from previous reviews.


343-349: Robust tetromino style retrieval with fallback.

The method correctly looks up the style in the map and provides a sensible fallback (space character with white color) for unknown tetromino types.


388-395: Proper serialization of tetromino styles.

The configuration saving logic correctly serializes the tetromino character, style character, and color string with appropriate length handling.

Copy link

@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 (2)
include/Settings.h (2)

25-27: Consider renaming for consistency.

The method name getTetrominoStyle() suggests it returns a style object, but it actually returns a char representing the character. Consider renaming to getTetrominoCharacter() to match the underlying member variable name and be more descriptive of what it returns.

-    static char getTetrominoStyle() {
+    static char getTetrominoCharacter() {
         return tetrominoCharacter;
     }

29-31: Consider renaming and ensure parameter validation.

Same naming inconsistency as the getter - consider setTetrominoCharacter() for clarity. Ensure the implementation validates that the character is printable and suitable for UI display to prevent rendering issues.

-    static void setTetrominoStyle(const char character) {
+    static void setTetrominoCharacter(const char character) {
         tetrominoCharacter = character;
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d2fb6b3 and 51902ab.

📒 Files selected for processing (3)
  • include/Settings.h (3 hunks)
  • src/Settings.cpp (11 hunks)
  • src/UI.cpp (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/UI.cpp
  • src/Settings.cpp
🔇 Additional comments (1)
include/Settings.h (1)

43-43: No action needed: tetrominoCharacter is already defined

The static member Settings::tetrominoCharacter is defined and initialized in src/Settings.cpp (line 21). No further changes required.

Copy link

@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

♻️ Duplicate comments (1)
src/Settings.cpp (1)

454-531: Excellent robust error handling implementation.

This addresses the previous review concern with comprehensive improvements:

  • Format version validation with clear error messages
  • Read size validation for all fields preventing truncated reads
  • Endianness conversion for all integer values
  • Maximum key binding size validation preventing DoS attacks
  • Descriptive error messages for debugging
  • Graceful fallback to defaults with config regeneration

The implementation significantly improves security and reliability compared to the previous version.

🧹 Nitpick comments (1)
src/Settings.cpp (1)

42-42: Verify the default character choice for tetromino rendering.

The default '.' character is reasonable, but consider if it provides sufficient visual distinction in the game interface compared to other UI elements.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51902ab and 8625604.

📒 Files selected for processing (3)
  • include/Settings.h (3 hunks)
  • src/Settings.cpp (11 hunks)
  • src/UI.cpp (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • include/Settings.h
  • src/UI.cpp
🔇 Additional comments (10)
src/Settings.cpp (10)

11-26: Excellent cross-platform endianness handling implementation.

The platform-specific includes and endianness conversion macros are well-implemented with proper fallbacks for Windows, macOS, and Linux. The approach ensures binary compatibility across different architectures.


30-34: Good defensive programming with format versioning and validation.

The configuration constants and static assertion provide good safeguards:

  • Format versioning enables future compatibility
  • MAX_KEYBIND_SIZE prevents potential DoS attacks from malformed files
  • Static assertion ensures platform compatibility assumptions

69-69: LGTM: Proper integration of tetromino character setting.

The new setting is correctly added to the settings names list and integrated into the UI layout calculations. The box height calculation properly accounts for the additional display section.

Also applies to: 128-129, 133-133


247-275: Well-structured display settings section.

The new "Display Settings" section is properly implemented with:

  • Consistent formatting and alignment
  • Proper selection highlighting
  • Appropriate input validation for single characters

310-323: Robust input handling for the new character setting.

The input validation correctly:

  • Limits input to printable ASCII characters (32-126)
  • Replaces the entire buffer for single character input
  • Integrates seamlessly with the existing settings flow

Also applies to: 345-355


363-372: Correct restriction of left/right navigation.

The handling settings adjustment is properly restricted to indices 10-13 (the four handling settings), excluding the new tetromino character setting which doesn't need +/-5 adjustments.


422-425: Proper versioned binary format implementation.

The format version is correctly written with endianness conversion, enabling future format evolution and cross-platform compatibility.


433-438: Good endianness handling for key bindings.

All integer values are properly converted to little-endian format before writing, ensuring consistent binary format across platforms.


441-441: Simple and correct character persistence.

The tetromino character is written directly as a single byte, which is appropriate since characters don't have endianness concerns.


162-162: UI separators consistently use “=”
Verified across Settings.cpp, Menu.cpp, and other UI components that all separator lines use “=” and there are no remaining instances of “─”. No further changes are needed.

@finityfly finityfly merged commit 77db397 into main Jul 21, 2025
1 check passed
@finityfly finityfly deleted the feat-cosmetics branch July 21, 2025 15:55
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.

plz add texture packs for blocks !!

1 participant