Skip to content

Fix duplicate code in PlatformTarget subclasses, fix assets being included twice.#1980

Merged
player-03 merged 7 commits intoopenfl:8.4.0-devfrom
player-03:PlatformTarget_update_consistency
Oct 23, 2025
Merged

Fix duplicate code in PlatformTarget subclasses, fix assets being included twice.#1980
player-03 merged 7 commits intoopenfl:8.4.0-devfrom
player-03:PlatformTarget_update_consistency

Conversation

@player-03
Copy link
Contributor

Having eight separate implementations made it harder to maintain.

When an asset embedding bug got fixed on desktop targets, it got overlooked on others. This lead to assets being included twice on those other targets: once embedded, and once normally. (#1898) Now, that behavior is controlled from one place, and the bug is fixed for eight targets at once.

This also standardizes the case of asset.embed == true && asset.type == TEMPLATE. Previously, some targets would prioritze embed over type, embedding the template into the app without even processing it as a template. Now, it will always prioritize type, processing templates as templates and never trying to embed them.

I left out AIRPlatform, FlashPlatform, and HTML5Platform since they have more complex asset embedding behavior. I haven't checked if the bug is present on any of those.

Having eight separate implementations made it harder to maintain. While an asset embedding bug got fixed on desktop targets, it got overlooked on others. This lead to assets being included twice on those other targets: once embedded, and once normally. (openfl#1898) Now, that behavior is controlled from one place, and the bug is fixed for eight targets at once.

This also standardizes the case of `asset.embed == true && asset.type == TEMPLATE`. Previously, some targets would prioritze `embed` over `type`, embedding the template into the app without even processing it as a template. Now, it will always prioritize `type`, processing templates as templates and never trying to embed them.

Three targets are left out since they have more complex asset embedding behavior. I haven't checked if the bug is present on any of those.
The old code appeared to be trying to do this, but it didn't work. When it found appinfo.json, it would call `copyAsset()` with an extra `context` argument, which is what you do for templates. However, `copyAsset()` only processes templates when `type == TEMPLATE`, otherwise it ignores the extra argument and processes it as a normal asset.
@player-03
Copy link
Contributor Author

@MAJigsaw77 Check this out and let me know if it works.

The implementation was copy-pasted, so it makes more sense to have only a single copy. `HTML5Platform` added a comment about possible future changes, so I kept that. Future changes will still be possible by overriding the function.
@player-03 player-03 changed the title Unify asset copying code, and standardize asset embedding. Fix duplicate code in PlatformTarget subclasses, fix assets being included twice. Sep 1, 2025
All of the implementations were identical, except for `FlashPlatform`, which was identical with extra steps.
@player-03
Copy link
Contributor Author

Cleaned up some more duplicate code while I was at it. I think that's it, though; the rest of the functions look unique.


@ignore public override function uninstall():Void {}

@ignore public override function watch():Void {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

watch() relies on getDisplayHXML(), which is missing from AIRPlatform and TizenPlatform, so that explains why we don't have it there.

However, WebAssemblyPlatform has getDisplayHXML() and doesn't have watch(). I don't know why, but I kept that behavior anyway. It seems like it ought to work, if we just enable it.

@MAJigsaw77
Copy link
Contributor

{0983020E-7020-487A-8788-454710077708}

Screenshot_20250901_093432

Can confirm that it works on Android.

@player-03 player-03 changed the base branch from 8.3.0-Dev to 8.4.0-dev October 22, 2025 22:59
Two reasons:

1. This is how it always worked in practice. The old special case actually did nothing due to an oversight.
2. Per the principle of least astonishment, Lime should avoid messing with the user's assets. If they wanted it to be a template, they would have specified `type="template"`.
@player-03 player-03 merged commit 6a7239c into openfl:8.4.0-dev Oct 23, 2025
31 checks passed
@player-03 player-03 deleted the PlatformTarget_update_consistency branch October 23, 2025 02:57
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