ramokz / phantom-camera

👻🎥 Control the movement and dynamically tween 2D & 3D cameras. Built for Godot 4. Inspired by Cinemachine.
https://phantom-camera.dev/
MIT License
2.17k stars 71 forks source link

C# wrapper #286

Open Renari opened 5 months ago

Renari commented 5 months ago

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

Better terrain 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.

ramokz commented 5 months ago

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

imbeingme commented 4 months ago

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.

sci-comp commented 3 months ago

+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!

sircodemane commented 2 months ago

@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:

ramokz commented 2 months ago

@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.

sircodemane commented 2 months ago

@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.