On Friday, 6 April 2018 at 02:18:28 UTC, Kayomn wrote:
On Friday, 6 April 2018 at 01:22:42 UTC, Kayomn wrote:
On Friday, 6 April 2018 at 01:14:37 UTC, ketmar wrote:
Kayomn wrote:

[...]

it is already done for you, free of charge.

        class Node {}
        class RootNode : Node {}
        class SpriteNode : Node {}

        void main () {
                auto nodeId1 = typeid(Node);
                auto nodeId2 = typeid(SpriteNode);
                auto comparison = typeid(Node);

                Node n = new SpriteNode();

                assert(typeid(Node) is typeid(Node)); // obviously
                assert(typeid(SpriteNode) !is typeid(Node)); // sure
                assert(typeid(Node) is nodeId1);
                assert(typeid(n) is nodeId2);
        }

Oh neat, thanks. I've been really scraping my head over this, and was worried I wouldn't be able to keep supporting my D version of the project.

Hmm... doesn't seem to operate at compile-time, which is an issue if I want to use it in case switch table like I was going to:

--------------------------------------------------------------------------------
switch (queryInteger(childJson,"type")) {
        case NodeType.Sprite:
                child = this.addChild!(Sprite)(childName);

                break;

        default:
                child = this.addChild!(Node)(childName);

                break;
}
--------------------------------------------------------------------------------

Wrong example code, here's the correct example:
--------------------------------------------------------------------------------
switch (queryString(childJson,"type")) {
        case (typeof (Sprite).name):
                child = this.addChild!(Sprite)(childName);

                break;

        case (typeof (Camera).name):
                child = this.addChild!(Camera)(childName);

                break;

        default:
                child = this.addChild!(Node)(childName);

                break;
}
--------------------------------------------------------------------------------

Reply via email to