Exemplo n.º 1
0
void BulletMLParserXercesSAXHandler::startElement(const XMLCh* const name,
												  AttributeList& attributes)
{
	BulletMLNode* node = parser_->addContent(parser_->uc2string(name));

	if (node->getName() == BulletMLNode::bulletml) {
		for (unsigned int i = 0; i < attributes.getLength(); i++) {
			if (parser_->uc2string(attributes.getName(i)) == "type" &&
				parser_->uc2string(attributes.getValue(i)) == "horizontal")
			{
				parser_->setHorizontal();
			}
		}
	}
	else {
		BulletMLParserXerces::MyAttributes mattr;
		for (unsigned int i = 0; i < attributes.getLength(); i++) {
			mattr.push_back(parser_->uc2string(attributes.getName(i)));
			mattr.push_back(parser_->uc2string(attributes.getValue(i)));
		}
		parser_->addAttribute(mattr, node);
	}

	if (curNode_ != 0) curNode_->addChild(node);
	curNode_ = node;
}
Exemplo n.º 2
0
BulletMLNode* BulletMLNode::next() {
	BulletMLNode* parent = getParent();
	if (parent == 0) return 0;
	ChildIterator ite =
		std::find(parent->childBegin(), parent->childEnd(), this);
	BulletMLError::doAssert(ite != parent->childEnd(), name_ + ": not found");
	ite++;
	if (ite == parent->childEnd()) return 0;
	else return *ite;
}
Exemplo n.º 3
0
void BulletMLRunnerImpl::runSub() {
	// 見たくもないコードだね。
	while (act_ != 0 && !isTurnEnd()) {
		BulletMLNode* prev = act_;
		Method fp = commandMap_[act_->getName()];
		(this->*fp)();

		// ref から戻る
		if (act_ == 0 &&
			prev->getParent() != 0 &&
			prev->getParent()->getName() == BulletMLNode::bulletml)
		{
			assert(!refStack_.empty());
			prev = refStack_.top().first;
			parameters_ = refStack_.top().second;
			refStack_.pop();
		}

		// 次の node を探す
		if (act_ == 0) act_ = prev->next();

		// 上に遡って次の node を探す
		while (act_ == 0) {
			if (prev->getParent() != 0 &&
				prev->getParent()->getName() == BulletMLNode::repeat)
			{
				RepeatElem* rep = repeatStack_.top();
				rep->ite++;
				if (rep->ite < rep->end) {
					act_ = rep->act;
					break;
				}
				else {
					delete rep;
					repeatStack_.pop();
				}
			}

			act_ = prev->getParent();
			if (act_ == 0) break;

			prev = act_;

			if (prev->getParent() != 0 &&
				prev->getParent()->getName() == BulletMLNode::bulletml)
			{
				assert(!refStack_.empty());
				prev = act_ = refStack_.top().first;
				parameters_ = refStack_.top().second;
				refStack_.pop();
			}

			act_ = act_->next();
		}
	}
}
Exemplo n.º 4
0
void BulletMLRunnerImpl::runChangeDirection() {
	int term = static_cast<int>(getNumberContents(
									act_->getChild(BulletMLNode::term)));
	BulletMLNode* dirNode = act_->getChild(BulletMLNode::direction);
	BulletMLNode::Type type = dirNode->getType();

	double dir;
	if (type != BulletMLNode::sequence) dir = getDirection(dirNode, false);
	else dir = getNumberContents(dirNode);

	calcChangeDirection(dir, term, type == BulletMLNode::sequence);

	act_ = 0;
}
Exemplo n.º 5
0
void BulletMLParserYggdrasil::start_element(yggdrasil::ygg_node element) {
    BulletMLNode* xmlNode = addContent(trimString(element.get_name()));

	if (xmlNode->getName() != BulletMLNode::bulletml) {
		MyAttributes mattr;
		for (ygg_iterator ite = element["@*"].begin(); ite.is_not_end(); ++ite)
		{
			mattr.push_back(trimString(ite->get_name()));
			mattr.push_back(trimString(ite->get_value()));
		}
		if (!mattr.empty()) addAttribute(mattr, xmlNode);

		if (curNode_ != 0) curNode_->addChild(xmlNode);
	}
	curNode_ = xmlNode;
}
Exemplo n.º 6
0
void BulletMLRunnerImpl::runChangeSpeed() {
	int term = static_cast<int>(getNumberContents(
									act_->getChild(BulletMLNode::term)));
	BulletMLNode* spdNode = act_->getChild(BulletMLNode::speed);
	BulletMLNode::Type type = spdNode->getType();

	double spd;
	if (type != BulletMLNode::sequence) spd = getSpeed(spdNode);
	else {
		spd = getNumberContents(spdNode) * (double)term
			+ runner_->getBulletSpeed();
	}
	

	calcChangeSpeed(spd, term);

	act_ = 0;
}
Exemplo n.º 7
0
BulletMLRunnerImpl::Parameters* BulletMLRunnerImpl::getParameters() {
	Parameters* para = 0;
	bool first = true;

	BulletMLNode::ChildIterator ite;
	for (ite = act_->childBegin(); ite != act_->childEnd(); ite++) {
		BulletMLNode* node = *ite;
		if (node->getName() != BulletMLNode::param) continue;

		if (first) {
			first = false;
			para = new Parameters;
			// 0番要素は使わない
			para->push_back(0);
		}

		para->push_back(getNumberContents(node));
	}

	return para;
}
Exemplo n.º 8
0
void BulletMLParserTinyXML::translateNode(TiXmlNode* node) {
    TiXmlElement* elem = node->ToElement();
    assert(elem != 0);

    BulletMLNode* xmlNode = addContent(elem->Value());

    if (xmlNode->getName() == BulletMLNode::bulletml) {
        TiXmlAttribute* attr;
        for (attr = elem->FirstAttribute(); attr; attr = attr->Next()) {
            if (attr->Value() == "horizontal") setHorizontal();
        }
    }
    else {
        MyAttributes mattr;
        TiXmlAttribute* attr;
        for (attr = elem->FirstAttribute(); attr; attr = attr->Next()) {
            mattr.push_back(attr->Name());
            mattr.push_back(attr->Value());
        }
        addAttribute(mattr, xmlNode);
        if (curNode_ != 0) curNode_->addChild(xmlNode);
    }
    curNode_ = xmlNode;
}
Exemplo n.º 9
0
void BulletMLRunnerImpl::runAccel() {
	int term = static_cast<int>(getNumberContents(
									act_->getChild(BulletMLNode::term)));
	BulletMLNode* hnode = act_->getChild(BulletMLNode::horizontal);
	BulletMLNode* vnode = act_->getChild(BulletMLNode::vertical);

	if (bulletml_->isHorizontal()) {
		if (vnode != 0) calcAccelX(getNumberContents(vnode), term,
								   vnode->getType());
		if (hnode != 0) calcAccelY(-getNumberContents(hnode), term,
								   hnode->getType());
	}
	else {
		if (hnode != 0) calcAccelX(getNumberContents(hnode), term,
								   hnode->getType());
		if (vnode != 0) calcAccelY(getNumberContents(vnode), term,
								   vnode->getType());
	}

	act_ = 0;
}
Exemplo n.º 10
0
void BulletMLParserXercesSAXHandler::endElement(const XMLCh* const) {
	curNode_ = curNode_->getParent();
}
Exemplo n.º 11
0
void BulletMLParserXercesSAXHandler::characters(const XMLCh* const chars,
												const unsigned int length)
{
	curNode_->setValue(parser_->uc2string(chars, length));
}