Coder Social home page Coder Social logo

Box2D support about h5 HOT 12 CLOSED

thomz12 avatar thomz12 commented on May 18, 2024
Box2D support

from h5.

Comments (12)

theolivenbaum avatar theolivenbaum commented on May 18, 2024 1

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024 1

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024 1

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.

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024 1

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024 1

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:

  • Replace \s+{[\n\r]\s+get[\n\r]\s+{(.|[\s\n\r])*?}[\n\r]\s+set[\n\r]\s+{(.|[\s\n\r])*?}\s+} with { get; set; }
  • Replace \s+private .*?__BackingField;\r\n with

The final package should be published on nuget soon!

from h5.

thomz12 avatar thomz12 commented on May 18, 2024

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. :)

from h5.

thomz12 avatar thomz12 commented on May 18, 2024

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?

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024

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

from h5.

thomz12 avatar thomz12 commented on May 18, 2024

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.

from h5.

thomz12 avatar thomz12 commented on May 18, 2024

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.

from h5.

theolivenbaum avatar theolivenbaum commented on May 18, 2024

from h5.

thomz12 avatar thomz12 commented on May 18, 2024

Oh duh!
I've opened a PR now.

from h5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.