rbxts-flamework / core

Flamework is an extensible game framework. It requires typescript and offers many useful features.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to retrieve a component by tag

mwalk-dev opened this issue · comments

Maybe there's a better way to achieve what I'm trying to do, but it seems like the ability to retrieve a component based on the tag used to instantiate it would be helpful, because the tag is an identifier that isn't tightly coupled to the component's implementation like the specifier is.

I have weapon components in my shared code, which are intended to be usable by both players and NPCs. I have a client-only player input component and a server-only NPC input component, with the same public API. From the weapon code, I want to be able to do something like Dependency<Components>.getComponentFromTag<IInputComponent>("Input") so that weapons can just react to the owner's input without regard for where it originated from. The downside is that I don't see a way to have this proposed function actually validate that the component is truly an IInputComponent, but to me it still seems worth having.

The only current workaround I see is functional, but pretty terrible - have the weapon component do something like components.getComponent<PlayerInput>() ?? components.getComponent<NpcInput>(). It works but generates import warnings about client/server code in a shared module, and it looks like it should be a compilation error to anyone unfamiliar with how the TS code is transformed to Lua.

Closing in favor of #38