Skip to content

Abstract #[signal] in #[godot_dyn] traits #1343

@pablopenna

Description

@pablopenna

Edit bromeon: rust code tags + rustfmt

I want to implement a system to choose a skill from a pool.

My current approach was defining a trait called and then implement it in different ways (e.g. one implementation for the AI and another one for the player - linked to UI)

pub(crate) trait SkillChooser {
    fn choose(
        &mut self,
        skill_pool: &Gd<SkillContainerModule>,
        target: &Gd<BattleEntity>,
    ) -> DynGd<Node, dyn SkillImplementation>;
}

The issue is that to link it to the UI, I would need to make this async. I can emit a signal once a skill is chosen. Something like:

pub(crate) trait SkillChooser {
    fn choose(&mut self, skill_pool: &Gd<SkillContainerModule>, target: &Gd<BattleEntity>);

   #[signal]    
   fn skill_chosen(skill: DynGd<Node, dyn SkillImplementation>);
}

However, I cannot declare a signal inside a trait (because I cannot annotate it with #[godot_api]).

I don't know if it is feasible or not to have this feature but I wanted to raise this just in case it is a valid request.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: registerRegister classes, functions and other symbols to GDScriptfeatureAdds functionality to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions