fix: Fix asset prefix double-prefixing and sprite name stripping#3869
Open
gnarhard wants to merge 4 commits intoflame-engine:mainfrom
Open
fix: Fix asset prefix double-prefixing and sprite name stripping#3869gnarhard wants to merge 4 commits intoflame-engine:mainfrom
gnarhard wants to merge 4 commits intoflame-engine:mainfrom
Conversation
s1r1m1r1
added a commit
to s1r1m1r1/flame
that referenced
this pull request
Mar 23, 2026
…sprite name parsing
s1r1m1r1
added a commit
to s1r1m1r1/flame
that referenced
this pull request
Mar 23, 2026
…sprite name parsing
Contributor
|
I tested this fix, Perhaps I should add some fixes for loading images for the atlas from the package. |
Contributor
|
If there are too many changes, it's possible to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Bug 1: Image loading double-prefixes paths
loadAtlasDataImagesappliedassetsPrefix(designed forFlame.assets, prefixassets/) toFlame.images(prefixassets/images/), causing paths likeassets/images/images/packs/textures.png. The image path should be passed directly toimg.load()without the assets prefix, as it was in 5.0.5.Bug 2:
_parseRegionstrips trailing digits from sprite namesThe regex
(_?)(\d+)$in_parseRegionstrips trailing digits from all sprite names, assuming they're animation frame indices. This breaks any sprite whose name naturally contains trailing digits (e.g.drohne2→drohne,cu3→cu,crystal2→crystal). In 5.0.5, the name was always kept as-is and the index only came from the explicitindex:field in the atlas.Fix 1: Double-prefixed image paths in
loadAtlasDataImagesassetsPrefix(default'images') was applied to bothFlame.assets(prefixassets/) andFlame.images(prefixassets/images/), causing paths likeassets/images/images/packs/texture.png.The
elsebranch inloadAtlasDataImagesprependedassetsPrefixtotexturePathbefore passing it toimages.load(). SinceFlame.imagesalready addsassets/images/, this created a double prefix. Thesubsequent stripping logic was fragile — it relied on
AssetsCache.prefixaligning withImages.prefix, which silently failed in non-standard configurations.Changes:
lib/src/texture_packer_parser.dart—loadAtlasDataImages:assetsPrefixandassetsparameters (no longer needed for image loading)assetsPrefixprefix application blocktoRelative/relativePrefixstripping logic with a simpler approach that directly checks for overlap withimg.prefix(both full and partial), independent ofAssetsCacheconfigurationtexturePathfromvartofinal(no longer reassigned)lib/src/texture_packer_atlas.dart—loadAtlas:assetsPrefixandassetsarguments from theloadAtlasDataImagescalltest/atlas_path_resolution_test.dart:assetsPrefixis not applied to image paths loaded viaImagesFix 2: Aggressive digit stripping from sprite names in
_parseRegionThe regex
r'(_?)(\d+)$'unconditionally stripped trailing digits from all sprite names and treated them as animation frame indices. This broke any sprite whose name naturally ends in digits (e.g.drohne2→drohne,cu3→cu,vine1→vine,corruption_sack-1→corruption_sack-).v5.1.0 added name-based index extraction that can't distinguish between animation indices (
walk_01) and names that end in digits (drohne2). In v5.0.5, the index only came from the explicitindex:field in theatlas file.
Changes:
lib/src/texture_packer_parser.dart—_parseRegion:indexMatchlogic andnameBeforeIndex/extractedIndexvariables)finalIndexnow only uses the explicitindex:field from the atlas, defaulting to-1nameis the original name from the atlas (with file extension stripped), never modifiedtest/naming_index_test.dart:image1,image_01, etc.) with index-1index:field to verify it still workstest/separated_parsing_test.dart:sprite1preserved as name (not stripped tosprite)getAnimationtest to use explicitindex:fields in atlas contenttest/atlas_path_resolution_test.dart:knight_walk_01, notknight_walk)index:field still works correctlyTests
index:fields)assetsPrefixindex:fields (the supported mechanism)Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues