Skip to content

Conversation

@JuanFdS
Copy link
Contributor

@JuanFdS JuanFdS commented Apr 30, 2025

While working in #260, I realised:

This PR addresses those 3 things and adds a helper to PropertyUtils to create groups.

@JuanFdS JuanFdS force-pushed the modify-how-variables-are-being-exported-in-guards branch 3 times, most recently from 27bf802 to 32788fe Compare April 30, 2025 12:57
@JuanFdS JuanFdS marked this pull request as ready for review April 30, 2025 12:57
@JuanFdS JuanFdS requested review from pablitar and wjt and removed request for wjt April 30, 2025 12:57
if not property_dict.is_empty():
property_dict = property_dict.duplicate()
property_dict["name"] = "%s__%s" % [child.name.to_snake_case(), property]
property_dict["name"] = "%s__%s" % [child.name, property]
Copy link
Member

Choose a reason for hiding this comment

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

Does this break any properties currently saved in the game? I think yes:

scenes/game_elements/props/buildings/house/house_1.tscn:11:house_sprite__texture = ExtResource("2_qufpk")
scenes/game_elements/props/buildings/house/house_2.tscn:11:house_sprite__texture = ExtResource("2_1mgcp")
scenes/game_elements/props/decoration/bush/bush.tscn:8:bush_sprite__texture = ExtResource("1_p46yk")
scenes/game_elements/props/decoration/spool/spool.tscn:11:spool_sprite__texture = ExtResource("2_dh24t")
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. Opening those scenes again corrected it. Then, for the scenes that included these decorations, I went over them and corrected the property manually in 5bd21a6

Comment on lines +487 to +501
func _get_property_list() -> Array[Dictionary]:
var properties: Array[Dictionary] = []
properties.append(PropertyUtils.group("Appearance"))
properties.append_array(
PropertyUtils.expose_children_property(self, &"sprite_frames", &"AnimatedSprite2D")
)
return properties


func _get(property_name: StringName) -> Variant:
return PropertyUtils.get_child_property(self, property_name)


func _set(property_name: StringName, value: Variant) -> bool:
return PropertyUtils.set_child_property(self, property_name, value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using PropertyUtils we lose adding a documentation comment to the exported property. For example in Player SpriteFrames, I have documented which animations and how many frames each animation should have.

Reading all this, I'm not so sure how much is PropertyUtils saving us, compared to losing the documentation comment. It also makes things more complex by having to traverse all the tree, in my opinion.

Copy link
Contributor Author

@JuanFdS JuanFdS Apr 30, 2025

Choose a reason for hiding this comment

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

Oh, I tried encoding that requirement as a warning, so it's harder to miss. You are right though about the documentation (!), I think there's no way to add documentation to properties added through _get_property_list, which is a shame

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think that this project being for educational purposes, we should put the effort on our (developer) side when exporting each of these properties, and keep each property documented. Is also not apparent to me how much does PropertyUtils really save to us, developers. I'd get rid of PropertyUtils and move Decoration and Teleporter back to normal exporting.

Copy link
Contributor Author

@JuanFdS JuanFdS Apr 30, 2025

Choose a reason for hiding this comment

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

Mmm, okay, I think this is a trade off between making it easier to mod almost any texture in the game vs code simplicity. Both are things that are desirable for the learners side.


With the PropertyUtils approach, we can write that once and any animated sprite owned by this scene will be exposed, which might be nice if we have scenes with more than one. Also, it'd be the same exact boilerplate we could have in other scenes (I actually just copied these 3 functions to the throwing_enemy.tscn and that was it), even when the AnimatedSprite2D nodes might be called different or be in different parts of the scene hierarchy. So, I think it has some value. We could be even go higher level and have something like:

func _get_property_list() -> Array[Dictionary]:
        return PropertyUtils.expose_children_sprites(self)

that automatically exposes the texture property from any Sprite and the sprite_frames property from any AnimatedSprite2D. It'd be even more magic (pejorative) but it would make it really simple to make a node's textures configurable (just have these 3 functions and @tool).


On the other hand, it's not obvious at all how this works and requires deeper knowledge of godot, so we might not want the learners to deal with that just so they have automatic exports for the spritesheets. The alternative would be to repeat the boilerplate for each node that we want to re-export properties and write the necessary glue code:

if animated_sprite_2d:
animated_sprite_2d.sprite_frames = sprite_frames
update_configuration_warnings()

if animated_sprite_2d:
animated_sprite_2d.sprite_frames = sprite_frames


I'm fine either way, what do you think should be the priority in this case? @manuq

Comment on lines +105 to +112
for required_animation in ["alerted", "idle", "walk"]:
if sprite_frames and not sprite_frames.has_animation(required_animation):
warnings.push_back(
(
"AnimatedSprite2D__sprite_frames is missing the following animation: %s"
% required_animation
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, I should add a warning to the Player SpriteFrames as well.

@JuanFdS JuanFdS force-pushed the modify-how-variables-are-being-exported-in-guards branch 2 times, most recently from 950279b to b68af68 Compare April 30, 2025 14:48
JuanFdS added 2 commits April 30, 2025 11:50
Converting to snake_case and then to PascalCase doesn't always produces the original result. For example: AnimatedSprite2D gets turned into animated_sprite_2d and then into AnimatedSprite2d (last character is d instead of D). Removed that logic to make it work for those cases, the inspector still shows it in a readable way.
@JuanFdS JuanFdS force-pushed the modify-how-variables-are-being-exported-in-guards branch from b68af68 to e38a265 Compare April 30, 2025 14:50
There are 2 changes:
- Use group instead of categories for properties. This is in order to keep it consistent with other scenes (throwing_enemy.tscn, projectile.tscn, sokoban's directional_input.tscn) where we also used groups.
- Use PropertyUtils.expose_children_properties for the AnimatedSprite2D texture, so we just reuse that pattern everywhere we need to do that.
@JuanFdS
Copy link
Contributor Author

JuanFdS commented May 7, 2025

Closed since we are moving out of exporting variables automagically with PropertyUtils for the sake of simplicity

@JuanFdS JuanFdS closed this May 7, 2025
@wjt wjt deleted the modify-how-variables-are-being-exported-in-guards branch May 12, 2025 14:17
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.

4 participants