bool FloatNode::applyDiff(const DefinitionDiff *diff, bool backward) { if (!DefinitionNode::applyDiff(diff, backward)) { return false; } assert(diff->getTypeName() == "float"); auto float_diff = dynamic_cast<const FloatDiff *>(diff); if (float_diff) { double previous = backward ? float_diff->getNewValue() : float_diff->getOldValue(); double next = backward ? float_diff->getOldValue() : float_diff->getNewValue(); if (value == previous) { value = next; return true; } else { Logs::error("Definition") << "Can't apply float diff " << previous << " => " << next << " to " << getName() << endl; return false; } } else { Logs::error("Could not cast DefinitionDiff to IntDiff"); return false; } }
void DefinitionWatcher::nodeChanged(const DefinitionNode *node, const DefinitionDiff *diff, const DefinitionNode *) { string type_name = node->getTypeName(); if (type_name == "int") { auto int_diff = static_cast<const IntDiff *>(diff); intNodeChanged(node->getPath(), int_diff->getNewValue(), int_diff->getOldValue()); } else if (type_name == "float") { auto float_diff = static_cast<const FloatDiff *>(diff); floatNodeChanged(node->getPath(), float_diff->getNewValue(), float_diff->getOldValue()); } }
void BreakBlocksScene::onBarPropertyChanged(void *sender, PropertyChangedEventArgsBase *e) { if (strcmp(e->getPropertyName(), "centerX") == 0) { auto arg = (PropertyChangedEventArgs<float>*)e; this->bar->setPositionX(arg->getNewValue()); } if (strcmp(e->getPropertyName(), "centerY") == 0) { auto arg = (PropertyChangedEventArgs<float>*)e; this->bar->setPositionY(arg->getNewValue()); } }
void BreakBlocksScene::onBlockPropertyChanged(void *sender, PropertyChangedEventArgsBase *e) { if (strcmp(e->getPropertyName(), "durability") == 0) { auto arg = (PropertyChangedEventArgs<int>*)e; if (arg->getNewValue() == 0) { auto block = this->getChildByTag(((Block*)sender)->getId()); block->removeFromParentAndCleanup(true); } } }