Skip to content

fix toggleable tile#59

Merged
CLOEI merged 4 commits into
CLOEI:mainfrom
badewen:fix/tile
Apr 22, 2026
Merged

fix toggleable tile#59
CLOEI merged 4 commits into
CLOEI:mainfrom
badewen:fix/tile

Conversation

@badewen

@badewen badewen commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved tile interaction handling when tiles are damaged or attacked by players.
    • Tiles now correctly toggle their state based on defined interaction rules and item properties.

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added TileApplyDamage packet handling to the game dispatch system with a new on_tile_apply_damage handler. The handler validates tile existence, computes tile index from coordinates, toggles tile flags for specific item types, and looks up item metadata without synchronizing state updates.

Changes

Cohort / File(s) Summary
Tile Damage Packet Handler
src/bot/core.rs
Added dispatch routing for GamePacketType::TileApplyDamage and implemented on_tile_apply_damage handler that toggles tile flags (IS_ON) when target items match predefined toggle lists or have action type 31, with metadata lookup via items_dat.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A patch to make the tiles respond,
When punches come and damages are done,
We toggle flags with toggleable care,
Item data queries float through the air—
No state sync yet, but the foundations are fair! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix toggleable tile' directly corresponds to the main change: implementing proper handling for toggleable tile mechanics through the new on_tile_apply_damage handler.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

🧹 Nitpick comments (1)
src/bot/core.rs (1)

2041-2045: Replace action_type == 31 with a named constant or enum.

The bare 31 hides protocol meaning in the handler. Pulling it into a named item-action constant would make this logic much easier to audit and reuse.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bot/core.rs` around lines 2041 - 2045, Replace the magic literal 31 in
the match on item_info.action_type with a named constant or enum variant (e.g.,
an ItemAction::Switcheroo variant or ITEM_ACTION_SWITCHEROO constant) so the
intent is explicit; update the match arm that currently uses the literal 31 to
match the new enum variant or constant and keep the body
(tile.flags.toggle(TileFlags::IS_ON)) unchanged, and add the constant/enum
definition next to other item-action definitions so other handlers can reuse it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bot/core.rs`:
- Around line 2023-2046: The toggle logic currently mutates only world.tile_map
(tile.flags.toggle(TileFlags::IS_ON)) in the TOGGLEABLE_ITEM_BY_PUNCH branch and
in the action_type 31 branch, so update the same flag in the cached UI state:
compute the same index (idx) into self.state.tiles (the tile entry corresponding
to world.tile_map) and mirror the toggle there as well (toggle the IS_ON bit on
the corresponding self.state.tiles[idx] or set/clear its flag field accordingly)
right after each place that calls tile.flags.toggle(...) so the web/shared view
stays in sync with world changes.

---

Nitpick comments:
In `@src/bot/core.rs`:
- Around line 2041-2045: Replace the magic literal 31 in the match on
item_info.action_type with a named constant or enum variant (e.g., an
ItemAction::Switcheroo variant or ITEM_ACTION_SWITCHEROO constant) so the intent
is explicit; update the match arm that currently uses the literal 31 to match
the new enum variant or constant and keep the body
(tile.flags.toggle(TileFlags::IS_ON)) unchanged, and add the constant/enum
definition next to other item-action definitions so other handlers can reuse it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fadd0f9c-b026-400e-8b82-8fd48a1aa4b5

📥 Commits

Reviewing files that changed from the base of the PR and between 77cf2b7 and 1eb4057.

📒 Files selected for processing (1)
  • src/bot/core.rs

Comment thread src/bot/core.rs
Comment on lines +2023 to +2046
let tile_map = &mut world.tile_map;
let idx = (pkt.int_y as u32) * tile_map.width + (pkt.int_x as u32);

let Some(tile) = tile_map.tiles.get_mut(idx as usize) else {
return;
};

// TODO: find better way than this ugly thing
const TOGGLEABLE_ITEM_BY_PUNCH: [u32; 7] = [1226, 6172, 6398, 8348, 8350, 8806, 8808];
if TOGGLEABLE_ITEM_BY_PUNCH.contains(&(tile.fg_item_id as u32)) {
tile.flags.toggle(TileFlags::IS_ON);
}

let Some(item_info) = self.items_dat.find_by_id(tile.fg_item_id as u32) else {
return;
};


match item_info.action_type {
31 => { // switcheroo
tile.flags.toggle(TileFlags::IS_ON);
}
_ => {}
}

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.

⚠️ Potential issue | 🟠 Major

Mirror the toggle into self.state as well.

Line 2033 and Line 2043 only mutate self.world. Unlike the other tile handlers, this never updates self.state.tiles, so the web/shared view will keep the old on/off state until a full map reload.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bot/core.rs` around lines 2023 - 2046, The toggle logic currently mutates
only world.tile_map (tile.flags.toggle(TileFlags::IS_ON)) in the
TOGGLEABLE_ITEM_BY_PUNCH branch and in the action_type 31 branch, so update the
same flag in the cached UI state: compute the same index (idx) into
self.state.tiles (the tile entry corresponding to world.tile_map) and mirror the
toggle there as well (toggle the IS_ON bit on the corresponding
self.state.tiles[idx] or set/clear its flag field accordingly) right after each
place that calls tile.flags.toggle(...) so the web/shared view stays in sync
with world changes.

@CLOEI

CLOEI commented Apr 22, 2026

Copy link
Copy Markdown
Owner

haha i agree we need to find a better way instead of hard coded id, overall nice job! thank you!

@CLOEI CLOEI merged commit cf031a1 into CLOEI:main Apr 22, 2026
9 checks passed
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