Example #1
0
TreeNodePtr TreeItemModel::getNodeFromIndex(const QModelIndex& index)
{
	TreeNode *item = this->itemFromIndex(index);
	if (!item)
		return TreeNodePtr();
	return mRepository->getNode(item->getUid());
}
TreeNodePtr TreeRepository::getTopNode()
{
	std::vector<TreeNodePtr> all = this->getNodes();
	for (unsigned i=0; i<all.size(); ++i)
		if (all[i]->getUid() == "node::invisible_top")
			return all[i];
	CX_LOG_CHANNEL_DEBUG("CA") << "invalid tree - did not find top node";
	return TreeNodePtr();
}
TreeNodePtr TreeRepository::getNode(QString uid)
{
	for (unsigned i=0; i<mNodes.size(); ++i)
	{
		if (mNodes[i]->getUid()==uid)
			return mNodes[i];
	}
	return TreeNodePtr();
}
Example #4
0
TreeNodePtr TreeNode::getParent_r(const TreeNodePtr& parent, int id) const {
	for (auto& child : _children) {
		if (child->getId() == id)
			return parent;
		const TreeNodePtr& parentPtr = child->getParent_r(child, id);
		if (parentPtr)
			return parentPtr;
	}
	return TreeNodePtr();
}
Example #5
0
TreeNodePtr TreeNode::getChild(int id) const {
	for (auto& child : _children) {
		if (child->getId() == id)
			return child;
		const TreeNodePtr& node = child->getChild(id);
		if (node)
			return node;
	}
	return TreeNodePtr();
}
Example #6
0
TreeNodePtr TreeNode::getParent(const TreeNodePtr& self, int id) const {
	ai_assert(getId() != id, "Root nodes don't have a parent");
	for (auto& child : _children) {
		if (child->getId() == id)
			return self;
		const TreeNodePtr& parent = child->getParent_r(child, id);
		if (parent)
			return parent;
	}
	return TreeNodePtr();
}
Example #7
0
TreeNodePtr Steer::Factory::create(const SteerNodeFactoryContext *ctx) const {
	movement::WeightedSteerings weightedSteerings;

	if (ctx->parameters.empty()) {
		for (const SteeringPtr& s : ctx->steerings) {
			weightedSteerings.push_back(movement::WeightedData(s, 1.0f));
		}
	} else {
		std::vector<std::string> tokens;
		Str::splitString(ctx->parameters, tokens, ",");
		ai_assert(tokens.size() == ctx->steerings.size(), "weights doesn't match steerings methods count");
		const int tokenAmount = static_cast<int>(tokens.size());
		for (int i = 0; i < tokenAmount; ++i) {
			weightedSteerings.push_back(movement::WeightedData(ctx->steerings[i], Str::strToFloat(tokens[i])));
		}
	}
	const movement::WeightedSteering w(weightedSteerings);
	return TreeNodePtr(new Steer(ctx->name, ctx->parameters, ctx->condition, w));
}
Example #8
0
TreeNodePtr Idle::Factory::create(const TreeNodeFactoryContext *ctx) const {
	return TreeNodePtr(new Idle(ctx->name, ctx->parameters, ctx->condition));
}
Example #9
0
TreeNodePtr TopTreeNode::getParent() const
{
	return TreeNodePtr();
}