From 9986f2ee5f172b6068198b302e7b47a0bbd0061d Mon Sep 17 00:00:00 2001 From: andreja6 Date: Mon, 30 Apr 2018 21:43:02 -0700 Subject: [PATCH] Made class name getter, can not be set outside of class --- Instance.cpp | 10 ++++++++-- Instance.h | 3 +++ main.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Instance.cpp b/Instance.cpp index b981f8b..4d72d43 100644 --- a/Instance.cpp +++ b/Instance.cpp @@ -4,12 +4,13 @@ std::string name; Instance* parent; -static std::string className = "DataModel"; +std::vector children; +static std::string className = "BaseInstance"; Instance::Instance(void) { name = "Default Game Instance"; - className = "DataModel"; + className = "BaseInstance"; } Instance::~Instance(void) @@ -17,6 +18,11 @@ Instance::~Instance(void) name = "Default Game Instance"; } +std::string Instance::getClassName() +{ + return className; +} + diff --git a/Instance.h b/Instance.h index 8a58954..b718a3e 100644 --- a/Instance.h +++ b/Instance.h @@ -8,5 +8,8 @@ public: virtual ~Instance(void); std::string name; Instance* parent; // Another pointer. + std::vector children; // All children. + std::string getClassName(); +protected: std::string className; }; diff --git a/main.cpp b/main.cpp index 2d4f3e2..3e5c58a 100644 --- a/main.cpp +++ b/main.cpp @@ -299,7 +299,7 @@ void RotateButtonListener::onButton1MouseClick(BaseButtonInstance* button) if(selectedInstance != NULL) { AudioPlayer::PlaySound(clickSound); - if(selectedInstance->className == "Part") + if(selectedInstance->getClassName() == "Part") { PhysicalInstance* part = (PhysicalInstance*) selectedInstance; if(button->name == "Tilt") @@ -1122,7 +1122,7 @@ void Demo::onUserInput(UserInput* ui) { bool onGUI = false; for(size_t i = 0; i < instances_2D.size(); i++) { - if(instances_2D.at(i)->className == "TextButton" || instances_2D.at(i)->className == "ImageButton") + if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") { BaseButtonInstance* button = (BaseButtonInstance*)instances_2D.at(i); if(button->mouseInButton(ui->mouseXY().x, ui->mouseXY().y, app->renderDevice)) @@ -1140,7 +1140,7 @@ void Demo::onUserInput(UserInput* ui) { Vector3 camPos = app->debugCamera.getCoordinateFrame().translation; for(size_t i = 0; i < instances.size(); i++) { - if(instances.at(i)->className == "Part" && instances.at(i)->parent == dataModel) + if(instances.at(i)->getClassName() == "Part" && instances.at(i)->parent == dataModel) { PhysicalInstance* test = (PhysicalInstance*)instances.at(i); float time = testRay.intersectionTime(test->getBox()); @@ -1167,7 +1167,7 @@ void Demo::onUserInput(UserInput* ui) { for(size_t i = 0; i < instances_2D.size(); i++) { - if(instances_2D.at(i)->className == "TextButton" || instances_2D.at(i)->className == "ImageButton") + if(instances_2D.at(i)->getClassName() == "TextButton" || instances_2D.at(i)->getClassName() == "ImageButton") { BaseButtonInstance* button = (BaseButtonInstance*)instances_2D.at(i); if(button->mouseInButton(ui->mouseXY().x, ui->mouseXY().y, app->renderDevice)) @@ -1237,7 +1237,7 @@ void drawButtons(RenderDevice* rd) for(size_t i = 0; i < instances_2D.size(); i++) { Instance* instance = instances_2D.at(i); - if((instance->className == "TextButton" || instance->className == "ImageButton") && instance->parent == dataModel) + if((instance->getClassName() == "TextButton" || instance->getClassName() == "ImageButton") && instance->parent == dataModel) { BaseButtonInstance* tbi = (BaseButtonInstance*)instance; tbi->drawObj(rd, Vector2(mousex, mousey), mouseButton1Down); @@ -1451,7 +1451,7 @@ void Demo::onGraphics(RenderDevice* rd) { for(size_t i = 0; i < instances.size(); i++) { Instance* instance = instances.at(i); - if(instance->className == "Part" && instance->parent != NULL) + if(instance->getClassName() == "Part" && instance->parent != NULL) { PhysicalInstance* part = (PhysicalInstance*)instance;