Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: alternative_sprites in conditional blocks away from the parent behave inconsistently #371

Open
zephyris opened this issue Apr 3, 2025 · 1 comment

Comments

@zephyris
Copy link
Contributor

zephyris commented Apr 3, 2025

As alternative_sprite blocks can be placed away from their 'parent' sprites, the NML syntax implies you can do things like define alternative_sprites in a conditional block which are used only when that condition is met. For example:

replace grid_temperate_spr3981(3981, "temperate_groundtiles_gridline_8bpp.png") { template_groundtiles(0, 0, 1) }
if (climate==CLIMATE_ARCTIC) {
    alternative_sprites (grid_temperate_spr3981, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "arctic_groundtiles_gridline_bt32bpp.png") { template_groundtiles(0, 0, 1) }
}

This doesn't work as you'd expect from the code. The alternative sprites are always used irrespective of climate.

The syntax also allows some quite nonsensical definitions:

if (climate==CLIMATE_TEMPERATE) {
    replace grid_temperate_spr3981(3981, "temperate_groundtiles_gridline_8bpp.png") { template_groundtiles(0, 0, 1) }
}
if (climate==CLIMATE_ARCTIC) {
    alternative_sprites (grid_temperate_spr3981, ZOOM_LEVEL_NORMAL, BIT_DEPTH_32BPP, "arctic_groundtiles_gridline_bt32bpp.png") { template_groundtiles(0, 0, 1) }
}

Such behaviour is not possible for NewGRFs (cf. NFO specs) as alternative sprites are just one part of the definition of a single real sprite.

Some example NML and images:
redef-alternate.zip

@zephyris
Copy link
Contributor Author

zephyris commented Apr 3, 2025

Two suggested changes:

  1. As alternative_sprite definitions have the global action of providing alternative sprites for a uniquely named block of sprites, the requirement could be that they are only placed outside of conditional statements. Similar behaviour to template definition.
  2. Prevent 'orphan' definitions of alternative sprites: If an alternative_sprite definition is in a conditional statement, require the 'parent' block of sprites is also defined in that conditional statement.

Option 1 is a heavy-handed change that may break existing NML which functions as expected. This would no longer be valid:

if (climate==CLIMATE_TEMPERATE) {
    replace sprite_set_1(....
    alternative_sprites (sprite_set_1, ...
}

Option 2 would prevent both syntax issues above. But, would it solve all cases?

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

No branches or pull requests

1 participant