[PR #595] [MERGED] fix(combat): render enemy avatars + wire portrait generation pipeline #4686

Closed
opened 2026-10-22 04:09:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/595
Author: @Romuromylus
Created: 5/9/2026
Status: ✅ Merged
Merged: 5/9/2026
Merged by: @Romuromylus

Base: main ← Head: fix/combat-enemy-portraits


📝 Commits (3)

  • df62683 fix(combat): render enemy avatars + wire portrait generation pipeline
  • f760068 fix(combat): index-aligned fallback for enemyImagePrompts lookup
  • 934427f fix(combat): case-insensitive name match when stitching generated avatars

📊 Changes

2 files changed (+169 additions, -29 deletions)

View changed files

📝 packages/client/src/components/game/GameCombatUI.tsx (+97 -28)
📝 packages/client/src/components/game/GameSurface.tsx (+72 -1)

📄 Description

Linked issue

Closes #594

Why this change

  • Game Mode combat shows broken-image placeholders for every enemy. Two related defects feed into the same symptom: the renderer treats enemy.sprite as a URL when the LLM is instructed to emit an emoji or short visual description, and the per-enemy portrait pipeline the encounter prompt asks for is never wired to a generator.
  • Even with sprite generation enabled and a working image-gen connection, combat enemies cannot get a real portrait today — there's no client code that turns the LLM's visuals.enemyImagePrompts (or enemy.description) into a generated image.

What changed

  • Renderer (packages/client/src/components/game/GameCombatUI.tsx): added resolveSpriteKind() that classifies combatant.sprite as URL / emoji glyph / unrenderable. Applied to all four sprite sites — active-player mini bar, action-menu indicator, desktop combatant card, mobile horizontal row. URL → <img>, emoji → glyph span, anything else → existing initials fallback.
  • Pipeline (packages/client/src/components/game/GameSurface.tsx): in the combat-init .then(...) handler, after hydrating combatants and before setCombatEnemies, dedupe enemies by name (so identical-named enemies share one portrait), build npcsNeedingAvatars from visuals.enemyImagePrompts[i].prompt when present else enemy.description else the enemy name, await runGameAssetGeneration, and overwrite each combatant.sprite with the matching generatedNpcAvatars[i].avatarUrl. Combat blocks here so portraits exist before the UI renders. Any failure (timeout, generation disabled, no image connection) falls through to the renderer's emoji/initials fallback with no retries. Capped at the server's npcsNeedingAvatars.max(10) limit. Respects the existing chatMeta.enableSpriteGeneration gate.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify in a Game Mode chat with sprite generation enabled and a working image-gen connection: trigger an encounter; confirm combat starts after a brief portrait-generation pause and each enemy displays a real generated portrait. Confirm identical-named enemies (e.g. multiple "Drone"s) share one portrait.
  • Manually verify the fallback path: trigger an encounter with sprite generation disabled, or with no image-gen connection configured. Confirm combat starts cleanly and enemies render either the LLM-suggested emoji glyph or initials — never a broken-image placeholder.
  • Manually verify that the existing boss-fight background/illustration generation (the shouldGenerateBossVisuals branch that fires after enemy avatars) still runs on boss encounters.
  • Manually verify a non-boss encounter (isBossFight: false) still gets per-enemy portraits, which it didn't before.
  • Manually verify the player party row still renders correctly (no regression — activePlayer.sprite is a real avatarUrl, so it routes through the new helper to the same <img> path).

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

Reporter screenshot in #594 shows three enemies (Tideborn Alpha + two Tideborn Drones) rendering as broken-image icons with the name leaking through as alt text, while the player party (Sasuke Uchiha, Emilia, Barbara) shows real avatars on the same row. After this PR: enemies show generated portraits when sprite gen is on, or the LLM-suggested emoji / initials when off, never a broken <img>.

Summary by CodeRabbit

Release Notes

  • New Features
    • Combat sprites now support multiple formats: image URLs, emoji glyphs, and fallback character initials when unavailable
    • Enemy portraits are automatically generated and rendered before combat initializes when sprite generation is enabled
    • Improved sprite handling across combat interface elements for consistent avatar display

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/595 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/9/2026 **Status:** ✅ Merged **Merged:** 5/9/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/combat-enemy-portraits` --- ### 📝 Commits (3) - [`df62683`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df6268308e6191a138a3ad955fbd23bcae4cf954) fix(combat): render enemy avatars + wire portrait generation pipeline - [`f760068`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7600686982687f8285448d8bc31f6998ea0a913) fix(combat): index-aligned fallback for enemyImagePrompts lookup - [`934427f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/934427faae599341322d27d640fc1d3073dfe8df) fix(combat): case-insensitive name match when stitching generated avatars ### 📊 Changes **2 files changed** (+169 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameCombatUI.tsx` (+97 -28) 📝 `packages/client/src/components/game/GameSurface.tsx` (+72 -1) </details> ### 📄 Description ## Linked issue Closes #594 ## Why this change - Game Mode combat shows broken-image placeholders for every enemy. Two related defects feed into the same symptom: the renderer treats `enemy.sprite` as a URL when the LLM is instructed to emit an emoji or short visual description, and the per-enemy portrait pipeline the encounter prompt asks for is never wired to a generator. - Even with sprite generation enabled and a working image-gen connection, combat enemies cannot get a real portrait today — there's no client code that turns the LLM's `visuals.enemyImagePrompts` (or `enemy.description`) into a generated image. ## What changed - **Renderer** (`packages/client/src/components/game/GameCombatUI.tsx`): added `resolveSpriteKind()` that classifies `combatant.sprite` as URL / emoji glyph / unrenderable. Applied to all four sprite sites — active-player mini bar, action-menu indicator, desktop combatant card, mobile horizontal row. URL → `<img>`, emoji → glyph span, anything else → existing initials fallback. - **Pipeline** (`packages/client/src/components/game/GameSurface.tsx`): in the combat-init `.then(...)` handler, after hydrating combatants and before `setCombatEnemies`, dedupe enemies by name (so identical-named enemies share one portrait), build `npcsNeedingAvatars` from `visuals.enemyImagePrompts[i].prompt` when present else `enemy.description` else the enemy name, await `runGameAssetGeneration`, and overwrite each `combatant.sprite` with the matching `generatedNpcAvatars[i].avatarUrl`. Combat blocks here so portraits exist before the UI renders. Any failure (timeout, generation disabled, no image connection) falls through to the renderer's emoji/initials fallback with no retries. Capped at the server's `npcsNeedingAvatars.max(10)` limit. Respects the existing `chatMeta.enableSpriteGeneration` gate. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify in a Game Mode chat with sprite generation **enabled** and a working image-gen connection: trigger an encounter; confirm combat starts after a brief portrait-generation pause and each enemy displays a real generated portrait. Confirm identical-named enemies (e.g. multiple "Drone"s) share one portrait. - Manually verify the **fallback path**: trigger an encounter with sprite generation disabled, or with no image-gen connection configured. Confirm combat starts cleanly and enemies render either the LLM-suggested emoji glyph or initials — never a broken-image placeholder. - Manually verify that the existing **boss-fight background/illustration** generation (the `shouldGenerateBossVisuals` branch that fires after enemy avatars) still runs on boss encounters. - Manually verify a **non-boss** encounter (`isBossFight: false`) still gets per-enemy portraits, which it didn't before. - Manually verify the player party row still renders correctly (no regression — `activePlayer.sprite` is a real `avatarUrl`, so it routes through the new helper to the same `<img>` path). ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) Reporter screenshot in #594 shows three enemies (Tideborn Alpha + two Tideborn Drones) rendering as broken-image icons with the name leaking through as alt text, while the player party (Sasuke Uchiha, Emilia, Barbara) shows real avatars on the same row. After this PR: enemies show generated portraits when sprite gen is on, or the LLM-suggested emoji / initials when off, never a broken `<img>`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Combat sprites now support multiple formats: image URLs, emoji glyphs, and fallback character initials when unavailable * Enemy portraits are automatically generated and rendered before combat initializes when sprite generation is enabled * Improved sprite handling across combat interface elements for consistent avatar display [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/595) <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:09:49 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4686
No description provided.