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

Pick up replacement images from world directory #95

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

wjt
Copy link
Member

@wjt wjt commented Feb 12, 2025

To help build interest in getting to know Godot in an introductory workshop, we want to make it possible to override a world's image assets textures by just placing image files at particular paths in the world's directory, without needing to adjust anything in the editor itself.

Add a helper function which looks up images in a named subdirectory of an Image directory adjacent to the current scene.

Adjust CandySpawner, Player and Goober to use these images, if present, selecting at random if there are more than one. Scale down any alternative Candy images that are too big.

Update the documentation accordingly.

@wjt
Copy link
Member Author

wjt commented Feb 12, 2025

Candy image scaled down (it's a picture of a laptop that I had lying around):

Screenshot from 2025-02-12 16-06-48

Asset swap with a unicorn player, heart goober, and miscellaneous foodstuffs as candy that I had lying around:

image

@wjt wjt marked this pull request as draft February 12, 2025 16:14
@wjt wjt requested a review from dylanmccall February 12, 2025 17:02
@wjt
Copy link
Member Author

wjt commented Feb 12, 2025

@dylanmccall I briefly demoed this to you yesterday – this is the tidied-up version of the branch.

@jbourqueendless Does this match what you were expecting?

@wjt wjt added the Engineering Code or Godot-specific work label Feb 12, 2025
wjt added 7 commits February 13, 2025 09:24
Previously, all the candy falling in the background would have to be one
specific texture.

With this change, it is possible to specify more than one texture. They
will be used in a different order each time, cycling through the list to
avoid repetition until it is necessary.

Because CandySpawner maintains a cache of candy sprites, this doesn't
mean that every candy that falls will be random. On early levels where
only one candy is visible at a time, it will be the same one on repeat;
once the player gets far enough for two to be visible at once, a second
one will be added to the mix; and so on. But on each playthrough, the
exact textures that get used will be different.
We will, in due course, need a new variant of this function that finds
image files.

In preparation, move it to a new ResourceFinder class. This function,
and its future sibling, are essentially polyfills for a new function
that will ship with Godot 4.4, so putting them in one place will make
it easier to clean up later.
To help build interest in getting to know Godot in an introductory
workshop, we want to make it possible to override a world's image assets
textures by just placing image files at particular paths in the world's
directory, without needing to adjust anything in the editor itself.

Add a helper function which looks up images in a named subdirectory of
an Image directory adjacent to the current scene.
Previously, to override the texture(s) used by a world's CandySpawner
instance, you would use the inspector to set the candy_textures property
on the instance. The default value of the property was a one-element
list of the default Candy.png image.

To help build interest in getting to know Godot in an introductory
workshop, we want to make it possible to override a world's candy
textures by just placing image files at a particular path in the world's
directory, without needing to adjust anything in the editor itself.

Use ResourceFinder.load_world_assets() during CandySpawner's
initialisation if the candy_textures property is empty. If no textures
are found in this directory, fall back in code to the default texture.
Change the default value of the property to the empty list.
Previously, to override the texture(s) used by a world's Goobers or
Player, you would need to:

1. Copy the Goober/Player scene into the world (perhaps as an inherited
   scene)
2. Adjust its Sprite2D's texture
3. Copy the TileSet into the world
4. Replace the Goober/Player scene in the TileSet with the custom
   instance

To help build interest in getting to know Godot in an introductory
workshop, we want to make it possible to override a world's Goober or
Player textures by just placing image files at a particular path in the
world's directory, without needing to adjust anything in the editor
itself.

Use ResourceFinder.load_world_assets() to look for Player and Goober
textures in a directory adjacent to the current scene. If any are found,
pick one at random for each instance. If none are found, preserve the
old behaviour.
It might be that a learner will drop any old image into the Image/Candy
directory of their world.

Handle this case by scaling down any image that is larger than the
default image so that its longest axis is the same size as the default.
@wjt wjt force-pushed the find-images-in-world branch from 1cd28e9 to b383268 Compare February 13, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering Code or Godot-specific work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant