OmniEngine.Net icon indicating copy to clipboard operation
OmniEngine.Net copied to clipboard

ObjectCreator is uglyyyy.

Open lukaspj opened this issue 10 years ago • 16 comments

I really wanna clean up object creation.

new A() { new B(){}; };

Is just syntactic sugar for:

new A() {};
new B() {};
A.add(B);

So instead of this:

            oc_Newobject4["#Newobject1"] = oc_Newobject1;

We could have this:

SimSet set = oc_Newobject4.create();
set.add(oc_Newobject1.create());

And we should use named parameters in the constructors so that instead of this:

ObjectCreator oc_Newobject4 = new ObjectCreator("GuiWindowCtrl", "ConsoleDlgWindow", typeof (ConsoleDlgWindow));
            oc_Newobject4["isContainer"] = "1";
            oc_Newobject4["AllowPopWindow"] = "1";

We should have:

// Have to have GuiWindowCtrl constructor in a seperate class to avoid boilerplate constructors in 
// classes derived from GuiWindowCtrl.
GuiWindowCtrl oc_Newobject4 = new GuiWindowCtrlInstance(name: "ConsoleDlgWindow", isContainer: true, AllowPopWindow: true);

// Alternately
GuiWindowCtrl oc_Newobject4 = (new GuiWindowCtrlInstance("ConsoleDlgWindow")
{
  isContainer = true,
  AllowPopWindow = true
}).create();

lukaspj avatar Jan 09 '15 21:01 lukaspj

Dynamics is ofc an issue, this could be handled through a "dynamics" parameter which could be a key-value pair or something.

lukaspj avatar Jan 09 '15 22:01 lukaspj

Is that second TS-style constructor valid C#? What must I search for to read about this wizardry?

crabmusket avatar Jan 09 '15 23:01 crabmusket

Yeah, I guess we could set up dynamics, haven’t messed with them lately though

From: Daniel Buckmaster [mailto:[email protected]] Sent: Friday, January 09, 2015 6:47 PM To: Winterleaf/OmniEngine.Net Subject: Re: [OmniEngine.Net] ObjectCreator is uglyyyy. (#19)

Is that second TS-style constructor valid C#? What must I search for to read about this wizardry?

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69421495 . https://github.com/notifications/beacon/ACUNZAOhJ85qMws7alAuYUfMck3BQOVkks5ngF_fgaJpZM4DQk0O.gif

Winterleaf avatar Jan 10 '15 00:01 Winterleaf

@eightyeight this bit?

GuiWindowCtrl oc_Newobject4 = (new GuiWindowCtrlInstance("ConsoleDlgWindow")
{
  isContainer = true,
  AllowPopWindow = true
}).create();

It's basically the same as doing oc_Newobject4.isContainer = true etc. after initialization It's just syntactic sugar, and it is valid C# ;)

Edit: Oh, source

lukaspj avatar Jan 10 '15 00:01 lukaspj

As an example of the syntactical difference:

            ObjectCreator oc = new ObjectCreator("SimGroup", "MeshQualityGroup", typeof (QualityGroup));

            ObjectCreator ao1 = new ObjectCreator("ArrayObject", "[Lowest]", typeof (GraphicsQualityLevel));
            ao1["class"] = "GraphicsQualityLevel";
            ao1["caseSensitive"] = true;
            oc["#1"] = ao1;
            oc.Create();

Will become:

SimGroup group = new SimGroupInstance(name: "MeshQualityGroup");
ArrayObject array = new ArrayObjectInstance(name: "[Lowest]",
                                             class: "GraphicsQualityLevel",
                                             caseSensitive: true);
group.add(array);

lukaspj avatar Jan 10 '15 01:01 lukaspj

so Lukas, this is all for readability, not any new functionality correct? how long do u think this would take to accomplish (pure curiosity)

On Fri, Jan 9, 2015 at 8:11 PM, Lukas Joergensen [email protected] wrote:

As an example of the syntactical difference:

        ObjectCreator oc = new ObjectCreator("SimGroup", "MeshQualityGroup", typeof (QualityGroup));

        ObjectCreator ao1 = new ObjectCreator("ArrayObject", "[Lowest]", typeof (GraphicsQualityLevel));
        ao1["class"] = "GraphicsQualityLevel";
        ao1["caseSensitive"] = true;
        oc["#1"] = ao1;
        oc.Create();

Will become:

SimGroup group = new SimGroupInstance(name: "MeshQualityGroup"); ArrayObject array = new ArrayObjectInstance(name: "[Lowest]", class: "GraphicsQualityLevel", caseSensitive: true);group.add(array);

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69429340 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 01:01 chieling

Yeah just for readability, I don't know how long it would take.. It depends on the generator that Vince is fumbling with, it doesn't take an awful lot of time to make the implementation for just e.g. SimObjects but if you need it for all classes and all future code it might take some time.. @Winterleaf (Vince) would probably be better at answering that than me :)

lukaspj avatar Jan 10 '15 01:01 lukaspj

well vince is in the middle of game code atm is why I asked ya :)

and its your suger ;)

On Fri, Jan 9, 2015 at 8:25 PM, Lukas Joergensen [email protected] wrote:

Yeah just for readability, I don't know how long it would take.. It depends on the generator that Vince is fumbling with, it doesn't take an awful lot of time to make the implementation for just e.g. SimObjects but if you need it for all classes and all future code it might take some time.. @Winterleaf https://github.com/Winterleaf (Vince) would probably be better at answering that than me :)

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69430906 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 01:01 chieling

Well, I might be able to achieve this on my own:

SimGroup group = new SimObjectInstance("MeshQualityGroup");
ArrayObject array = new SimObjectInstance("[Lowest]") 
{
    class = "GraphicsQualityLevel",
    caseSensitive = true
};
group.add(array);

But that will be without intellisense. Anything more than that will need to be written into the project generator.

lukaspj avatar Jan 10 '15 01:01 lukaspj

hmm.... is that out on github?

On Fri, Jan 9, 2015 at 8:33 PM, Lukas Joergensen [email protected] wrote:

Well, I might be able to achieve this on my own:

SimGroup group = new SimObjectInstance("MeshQualityGroup"); ArrayObject array = new SimObjectInstance("[Lowest]") { class = "GraphicsQualityLevel", caseSensitive = true };group.add(array);

But that will be without intellisense. Anything more than that will need to be written into the project generator.

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69431683 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 01:01 chieling

@chieling Is what on Github? The generator?

lukaspj avatar Jan 10 '15 01:01 lukaspj

https://github.com/Winterleaf/OmniEngine.Net

I remember there being a tools folder and didn't remember if the generator code was in there or snot.

On Fri, Jan 9, 2015 at 8:47 PM, Lukas Joergensen [email protected] wrote:

@chieling https://github.com/chieling Is what on Github? The generator?

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69432551 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 01:01 chieling

Afaik thats not in there.

lukaspj avatar Jan 10 '15 02:01 lukaspj

ah ok

On Fri, Jan 9, 2015 at 9:04 PM, Lukas Joergensen [email protected] wrote:

Afaik thats not in there.

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69433375 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 02:01 chieling

So Lukas, do u need anything? or can u test and work with what u got?

On Fri, Jan 9, 2015 at 9:12 PM, Paul Yoskowitz < [email protected]> wrote:

ah ok

On Fri, Jan 9, 2015 at 9:04 PM, Lukas Joergensen <[email protected]

wrote:

Afaik thats not in there.

— Reply to this email directly or view it on GitHub https://github.com/Winterleaf/OmniEngine.Net/issues/19#issuecomment-69433375 .

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

Paul Yoskowitz [image: http://]about.me/paulyoskowitz http://about.me/paulyoskowitz?promo=email_sig

chieling avatar Jan 10 '15 17:01 chieling

I can probably make an exapmle implementation, but we'll need to edit the codegenerator for a proper implementation. And I still don't have access to that afaik :P

lukaspj avatar Jan 11 '15 14:01 lukaspj