fix: Fix asset prefix double-prefixing and sprite name stripping#3869
fix: Fix asset prefix double-prefixing and sprite name stripping#3869gnarhard wants to merge 5 commits intoflame-engine:mainfrom
Conversation
…sprite name parsing
…sprite name parsing
|
I tested this fix, Perhaps I should add some fixes for loading images for the atlas from the package. |
|
If there are too many changes, it's possible to |
|
@s1r1m1r1 Thanks for testing this and flagging the package loading issue. On the index pattern suggestion though, I think the regex-based index extraction should be fully removed rather than scaled back. TexturePacker already handles frame indexing explicitly via the I'd prefer to keep these as two separate concerns — the index stripping fix stands on its own, and the package loading issue can be addressed independently. Happy to collaborate on the package path fix if you want to share what you're seeing there. |
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