curiosity-ai / h5

🚀 The next generation C# to JavaScript compiler
https://github.com/curiosity-ai/h5
Apache License 2.0
211 stars 30 forks source link

Box2D support #40

Closed thomz12 closed 3 years ago

thomz12 commented 3 years ago

In my project I'd like to use Box2D. Is it possible to port that over from Retyped.box2d?

Is that something I can look into? Are you decompiling the Retyped packages for that?

theolivenbaum commented 3 years ago

Hi @thomz12,

Yeah that's the approach I used before, just decompile with any tool and replace Retyped with H5.core

I've two packages in my todo list for a while, let's see if I manage to do the three over this weekend.

Cheers,

Rafael

On Fri, Apr 16, 2021, 5:47 PM thomz12 @.***> wrote:

In my project I'd like to use Box2D. Is it possible to port that over from Retyped.box2d?

Is that something I can look into? Are you decompiling the Retyped packages for that?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/theolivenbaum/h5/issues/40, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDCOA3JQOZUE62C2XHDZWLTJBL2TANCNFSM43BY2YJQ .

thomz12 commented 3 years ago

Thanks for the info! I had I look just now and was able to decompile and get it to compile with my project. Had a quick test that still didn't quite work, but I'll figure that out tomorrow. :)

theolivenbaum commented 3 years ago

Perfect! If you wanna submit the code as a PR I can publish it as a Nuget package as well

On Fri, Apr 16, 2021, 7:18 PM thomz12 @.***> wrote:

Thanks for the info! I had I look just now and was able to decompile and get it to compile with my project. Had a quick test that still didn't quite work, but I'll figure that out tomorrow. :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theolivenbaum/h5/issues/40#issuecomment-821321163, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDCOA5LQME5GVGKWRVBQG3TJBWNTANCNFSM43BY2YJQ .

thomz12 commented 3 years ago

So unfortunatly the original package used for Retpyed.box2d is used just for node applications. (I failed to notice that before) I can convert it so it can be loaded in a browser, but I can't get the retyped package to work with that. (in the browser)

Do you have any ideas?

theolivenbaum commented 3 years ago

To be honest my personal experience with Retyped isn't very good - for all the libraries we use, we just ended up writing our own wrapper classes - much easy to get a consistency experience than the autogenerated one from the typescript definition files used by Retyped. I'm not familiar with Box2D, but if their API is not too crazy might be worth giving it a try.

It's usually as simple as writing a C# method and directly call the javascript code with something like this:

public class MyLib
{ 
    public int DoSomething(string par1, int par2)
    {
        return Script.Write<int>("myLib.doSomething({0}, {1}", par1, par2);
    }
}

The trick is that the compiler will emit directly the parameter variables in the final javascript, so that becomes:

return myLib.doSomething(par1, par2);

If you need more complex data types, you can create lightweight classes using the [ObjectLiteral] attribute. These classes are compiled to plain javascript objects without any of the C# extra code.

theolivenbaum commented 3 years ago

Obviously, use static methods if it's a static library, or create an instance of the library and store it locally in the wrapper class if needed

thomz12 commented 3 years ago

Thanks again for the tips! I ended up using p2.js instead, and decompiled the retyped package for that. That seems to work now!

Would you like to make a nuget package for it? (p2) If you do, I'll open a PR tomorrow.

theolivenbaum commented 3 years ago

If you can that would be great!

On Sat, Apr 17, 2021, 5:28 PM thomz12 @.***> wrote:

Thanks again for the tips! I ended up using p2.js instead, and decompiled the retyped package for that. That seems to work now!

Would you like to make a nuget package for it? (p2) If you do, I'll open a PR tomorrow.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theolivenbaum/h5/issues/40#issuecomment-821840582, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDCOA52JV3EF3I6RC3ERJDTJGSJXANCNFSM43BY2YJQ .

thomz12 commented 3 years ago

Cool! I wanted to push a new branch, but it it looks like I'm not allowed to.

remote: Permission to theolivenbaum/h5.git denied to thomz12.
theolivenbaum commented 3 years ago

I think you've to fork first, push to your fork and then open a PR

On Sun, Apr 18, 2021, 4:30 AM thomz12 @.***> wrote:

Cool! I wanted to push a new branch, but it it looks like I'm not allowed to.

remote: Permission to theolivenbaum/h5.git denied to thomz12.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theolivenbaum/h5/issues/40#issuecomment-821919804, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDCOA467VNZN4QEESOQ4FTTJI757ANCNFSM43BY2YJQ .

thomz12 commented 3 years ago

Oh duh! I've opened a PR now.

theolivenbaum commented 3 years ago

did that mistake in the past too 😄

Just merged the code, thanks for contributing!

For future reference, I'm leaving these two regexs that I used for cleaning the decompiled code:

The final package should be published on nuget soon!