space-wizards / RobustToolbox

Robust multiplayer game engine, used by Space Station 14
https://spacestation14.io
Other
504 stars 380 forks source link

generic Entity wishlist #4888

Open deltanedas opened 5 months ago

deltanedas commented 5 months ago

Entity<A> should automatically convert to Entity<B?> adding .Owner is silly

Entity<A, B> should automatically convert to Entity<B?> with non-null Comp

metalgearsloth commented 5 months ago

@ElectroJr you made it i think

smugleaf you dork.

deltanedas commented 5 months ago

:trollface: @DrSmugleaf

ElectroJr commented 5 months ago

Entity should automatically convert to Entity<B?> adding .Owner is silly

One downside is that it might make it easier for people to make some mistakes. E.g., currently this would fail, which IMO is a good thing

public void Foo(Entity<CompA> entA, Entity<CompB> entB)
{
    // Accidentally swap entA & entB
    Bar(entB, entA)
}

public void Bar(Entity<CompA?> entA, Entity<CompB?> entB) { }

I think keeping the "component type checking" for arguments is probably worth having to use .Owner

Entity<A, B> should automatically convert to Entity<B?> with non-null Comp

I think this is easy enough to add, though I don't think we would want to extend this to anything with more than 2 generic arguments, because the possible permutations just start ballooning.

deltanedas commented 5 months ago

yeah it would still be great for usability with just A, B which is fairly common