luxeengine / alpha

alpha - deprecated 2015~2016. unrelated to the new engine! view the new engine here - https://luxeengine.com/
MIT License
565 stars 74 forks source link

Entity.active_path #370

Closed jarnik closed 8 years ago

jarnik commented 8 years ago

Easily hide/disable a complex nested structure of Visuals/Entities by just setting its root entity to active = true/false;

Entity has a new property .active_path that checks if the Entity and all of its parents have .active==true (think of Unity's .activeInHierarchy). Only updated when hierarchy changes.

Entity only receives events when active_path == true, Visuals are only visible when active_path == true (may be disabled via Visual._ACTIVE_BASED_VISIBILITY = false).

ruby0x1 commented 8 years ago

Thanks a lot for the effort! I appreciate the desire to contribute, and I'm glad you did.

Unfortunately this PR is incompatible with the library design goals. Events is an agnostic class, it must not be coupled to Entity. The all caps underscored static variables are not a convention in luxe (and can't be for later reasons). The visuals and entity coupling like this is also against the idea. There may also be the assumption that the root is the relevant tier to consider (i.e all of the parents up to the root), which would mean that this value only makes sense for root type nodes and asking halfway up the tree doesn't apply, which would mean you might need even more queries and states to track, and more and more chance of a ball of state moving around that has no real meaning to the API it's trying to facilitate. It would be better if the coupling was managed by a higher level construct, not internally.

I will note that there will be facility like this from the engine when the focus sheet for Entities comes around.

If you want this specific query it would make more sense to me atm as a static extension, the engine code will be changing in it's focus sheet anyway. Here is an example:

class EntityTools {

    public static function active_path(e:luxe.Entity) : Bool {

        if(e.parent != null) {
            return e.active && active_path(e.parent);
        }

        return e.active;

    }

}

You would use it by adding using EntityTools; at the top of your module somewhere:

        var r = new luxe.Entity({name:'root'});
        var a = new luxe.Entity({name:'a'});
        var b = new luxe.Entity({name:'b'});
        var c = new luxe.Entity({name:'c'});

        c.parent = b;
        b.parent = a;
        a.parent = r;

        trace(c.active_path());
        trace(b.active_path());
        trace(a.active_path());
        trace(r.active_path());

        a.active = false;

        trace(c.active_path());
        trace(b.active_path());
        trace(a.active_path());
        trace(r.active_path());

Thanks again, and I look forward to your thoughts.

jarnik commented 8 years ago

Cool, thanks for clearing it up! I assumed there were some design constraints, I just needed the functionality now and wasn't sure about how to approach it correctly. I'll have a look at static extensions.

And thanks for keeping the codebase strict and focused! :)