phantom-camera icon indicating copy to clipboard operation
phantom-camera copied to clipboard

C# wrapper

Open Renari opened this issue 1 year ago • 7 comments

Project Type

2D, 3D

Feature Description

It would be nice if phantom camera included a C# wrapper to ease use with C#.

Use Cases

Currently to call phantom camera methods in C# you have to do something like this:

var cameraActive = (bool)GetNode("PhantomCamera2D").Call("is_active");

This is prone to causing runtime issues, for example if phantom camera changed the is_active method to active this would still compile but cause runtime issues.

(Optional) Proposed Solution

Phantom Camera could ship a C# wrapper that would prevent the above from happening.

One such example: https://github.com/Portponky/better-terrain/blob/main/addons/better-terrain/BetterTerrain.cs

The above example could then be changed to:

var cameraActive = GetNode<PhantomCamera>("PhantomCamera2D").is_active();

Upon such an update where is_active is changed to active this would then cause a compile error, this also integrates better with IDE.

Renari avatar May 02 '24 10:05 Renari

This was also mentioned in this issue, so am exploring adding that in.

ramokz avatar May 02 '24 10:05 ramokz

Having a C# wrapper that's similar to the one provided in BetterTerrain would be amazing.

The way I see it, it's similar to shipping a TypeScript definition file (aka .d.ts) on a JavaScript project.

imbeingme avatar May 30 '24 18:05 imbeingme

+1 to this idea!

The sample implementations provided by other users seems fine to me, it sounds much nicer than using Call, Get, and Set with silly magic strings scattered around.

I'm following along, so I'll be around to help test the new feature when it's ready!

sci-comp avatar Jul 02 '24 23:07 sci-comp

@ramokz I have already started implementing something similar to this for my use case and I'd be willing to try contributing this feature if you're open to PRs.

The criteria I've followed for my implementation so far:

  • Follow Godot's C# code style
  • Use C# properties with getter setters to simplify the API
  • Follow Godot conventions (eg- SignalNameEventHandler, Method and Property name constants, etc)

sircodemane avatar Jul 16 '24 05:07 sircodemane

@sircodemane If you've started making a C# implementation, and happy to make a PR, then you're more than welcome to! Your criteria all sound sensible to me.

Was meaning to start looking at this proper after finishing up another feature, but it is taking longer than I had hoped… So any help with getting this in would be greatly appreciated.

ramokz avatar Jul 16 '24 10:07 ramokz

@ramokz I've opened a draft PR with the start of my efforts so you can take a look. I'll probably aim for 90% case for now and keep things fairly simple for this first pass. It's only the start of PCam3D currently but should give a good idea of the direction I'm taking it, let me know if I need to re-align.

sircodemane avatar Jul 17 '24 06:07 sircodemane