Beispiel #1
0
		void connectEntities (const scene::Path& path, const scene::Path& targetPath)
		{
			Entity* e1 = ScenePath_getEntity(path);
			Entity* e2 = ScenePath_getEntity(targetPath);

			if (e1 == 0 || e2 == 0) {
				globalErrorStream() << "entityConnectSelected: both of the selected instances must be an entity\n";
				return;
			}

			if (e1 == e2) {
				globalErrorStream()
						<< "entityConnectSelected: the selected instances must not both be from the same entity\n";
				return;
			}

			UndoableCommand undo("entityConnectSelected");

			ConnectEntities connector(e1, e2);
			std::string value = e2->getKeyValue("targetname");
			if (value.empty()) {
				value = e1->getKeyValue("target");
			}
			if (!value.empty()) {
				connector.connect(value);
			} else {
				std::string type = e2->getKeyValue("classname");
				if (type.empty()) {
					type = "t";
				}
				std::string key = type + "1";
				GlobalNamespace().makeUnique(key, ConnectEntities::ConnectCaller(connector));
			}

			SceneChangeNotify();
		}
Beispiel #2
0
  void connectEntities(const scene::Path& path, const scene::Path& targetPath, int index)
  {
    Entity* e1 = ScenePath_getEntity(path);
    Entity* e2 = ScenePath_getEntity(targetPath);

    if(e1 == 0 || e2 == 0)
    {
      globalErrorStream() << "entityConnectSelected: both of the selected instances must be an entity\n";
      return;
    }

    if(e1 == e2)
    {
      globalErrorStream() << "entityConnectSelected: the selected instances must not both be from the same entity\n";
      return;
    }


    UndoableCommand undo("entityConnectSelected");

    if(g_gameType == eGameTypeDoom3)
    {
      StringOutputStream key(16);
      if(index >= 0)
      {
	  key << "target";
	  if(index != 0)
	  {
	    key << index;
	  }
	  e1->setKeyValue(key.c_str(), e2->getKeyValue("name"));
	  key.clear();
      }
      else
      {
	for(unsigned int i = 0; ; ++i)
	{
	  key << "target";
	  if(i != 0)
	  {
	    key << i;
	  }
	  const char* value = e1->getKeyValue(key.c_str());
	  if(string_empty(value))
	  {
	    e1->setKeyValue(key.c_str(), e2->getKeyValue("name"));
	    break;
	  }
	  key.clear();
	}
      }
    }
    else
    {
      ConnectEntities connector(e1, e2, index);
      const char* value = e2->getKeyValue("targetname");
      if(!string_empty(value))
      {
        connector.connect(value);
      }
      else
      {
        const char* type = e2->getKeyValue("classname");
        if(string_empty(type))
        {
          type = "t";
        }
        StringOutputStream key(64);
        key << type << "1";
        GlobalNamespace().makeUnique(key.c_str(), ConnectEntities::ConnectCaller(connector));
      }
    }

    SceneChangeNotify();
  }