From 9fbe72b3c59c20bd107e193d7e6eba2632bcc3b5 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Sun, 29 Nov 2015 02:16:07 +0100 Subject: [PATCH] Move getter from characteristics to properties --- .gitignore | 1 + src/items/attachment.cpp | 18 +- src/items/plunger.cpp | 2 +- src/items/powerup.cpp | 16 +- src/items/rubber_band.cpp | 8 +- src/items/swatter.cpp | 8 +- src/karts/abstract_characteristic.cpp | 15 +- src/karts/abstract_characteristic.hpp | 5 +- src/karts/kart.cpp | 4 +- src/karts/kart_properties.cpp | 635 +++++++++++++++++++++++++- src/karts/kart_properties.hpp | 142 +++++- tools/create_kart_properties.py | 197 +++++--- tools/update_characteristics.py | 22 +- 13 files changed, 927 insertions(+), 146 deletions(-) diff --git a/.gitignore b/.gitignore index 1ba98ce23..b437bf1b2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ stk-editor/ .config/ supertuxkart-64 make*.bat +__pycache__ data/editor data/karts diff --git a/src/items/attachment.cpp b/src/items/attachment.cpp index a8a3045fe..a405a55c7 100644 --- a/src/items/attachment.cpp +++ b/src/items/attachment.cpp @@ -268,7 +268,7 @@ void Attachment::hitBanana(Item *item, int new_attachment) // same banana again once the explosion animation is finished, giving // the kart the same penalty twice. float f = std::max(item->getDisableTime(), - m_kart->getCharacteristic()->getExplosionDuration() + 2.0f); + m_kart->getKartProperties()->getExplosionDuration() + 2.0f); item->setDisableTime(f); break; } @@ -296,7 +296,7 @@ void Attachment::hitBanana(Item *item, int new_attachment) switch (new_attachment) { case 0: - set(ATTACH_PARACHUTE, m_kart->getCharacteristic()-> + set(ATTACH_PARACHUTE, m_kart->getKartProperties()-> getParachuteDuration() + leftover_time); m_initial_speed = m_kart->getSpeed(); @@ -311,13 +311,13 @@ void Attachment::hitBanana(Item *item, int new_attachment) // sound -> playSfx ( SOUND_SHOOMF ) ; break ; case 2: - set(ATTACH_ANVIL, m_kart->getCharacteristic()-> + set(ATTACH_ANVIL, m_kart->getKartProperties()-> getAnvilDuration() + leftover_time); // if ( m_kart == m_kart[0] ) // sound -> playSfx ( SOUND_SHOOMF ) ; // Reduce speed once (see description above), all other changes are // handled in Kart::updatePhysics - m_kart->adjustSpeed(m_kart->getCharacteristic()->getAnvilSpeedFactor()); + m_kart->adjustSpeed(m_kart->getKartProperties()->getAnvilSpeedFactor()); m_kart->updateWeight(); break ; } // switch @@ -422,12 +422,12 @@ void Attachment::update(float dt) // This percentage is based on the ratio of // initial_speed / initial_max_speed - float f = m_initial_speed / m_kart->getCharacteristic()->getParachuteMaxSpeed(); + float f = m_initial_speed / m_kart->getKartProperties()->getParachuteMaxSpeed(); if (f > 1.0f) f = 1.0f; // cap fraction if (m_kart->getSpeed() <= m_initial_speed * - (m_kart->getCharacteristic()->getParachuteLboundFraction() + - f * ( m_kart->getCharacteristic()->getParachuteUboundFraction() - - m_kart->getCharacteristic()->getParachuteLboundFraction()))) + (m_kart->getKartProperties()->getParachuteLboundFraction() + + f * ( m_kart->getKartProperties()->getParachuteUboundFraction() + - m_kart->getKartProperties()->getParachuteLboundFraction()))) { m_time_left = -1; } @@ -512,7 +512,7 @@ void Attachment::update(float dt) // ---------------------------------------------------------------------------- float Attachment::weightAdjust() const { - return m_type == ATTACH_ANVIL ? m_kart->getCharacteristic()->getAnvilWeight() : 0.0f; + return m_type == ATTACH_ANVIL ? m_kart->getKartProperties()->getAnvilWeight() : 0.0f; } // ---------------------------------------------------------------------------- diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 192ccc962..011a0a983 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -177,7 +177,7 @@ bool Plunger::hit(AbstractKart *kart, PhysicalObject *obj) } else { - m_keep_alive = m_owner->getCharacteristic()->getPlungerBandDuration(); + m_keep_alive = m_owner->getKartProperties()->getPlungerBandDuration(); // Make this object invisible by placing it faaar down. Not that if this // objects is simply removed from the scene graph, it might be auto-deleted diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index fd3d754d7..3f89ebe59 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -223,7 +223,7 @@ void Powerup::use() case PowerupManager::POWERUP_SWATTER: m_owner->getAttachment() ->set(Attachment::ATTACH_SWATTER, - m_owner->getCharacteristic()->getSwatterDuration()); + m_owner->getKartProperties()->getSwatterDuration()); break; case PowerupManager::POWERUP_BUBBLEGUM: @@ -258,12 +258,12 @@ void Powerup::use() if (m_owner->getIdent() == "nolok") { m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD, - m_owner->getCharacteristic()->getBubblegumShieldDuration()); + m_owner->getKartProperties()->getBubblegumShieldDuration()); } else { m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD, - m_owner->getCharacteristic()->getBubblegumShieldDuration()); + m_owner->getKartProperties()->getBubblegumShieldDuration()); } } else // using a bubble gum while still having a shield @@ -271,12 +271,12 @@ void Powerup::use() if (m_owner->getIdent() == "nolok") { m_owner->getAttachment()->set(Attachment::ATTACH_NOLOK_BUBBLEGUM_SHIELD, - m_owner->getCharacteristic()->getBubblegumShieldDuration() + m_owner->getShieldTime()); + m_owner->getKartProperties()->getBubblegumShieldDuration() + m_owner->getShieldTime()); } else { m_owner->getAttachment()->set(Attachment::ATTACH_BUBBLEGUM_SHIELD, - m_owner->getCharacteristic()->getBubblegumShieldDuration() + m_owner->getShieldTime()); + m_owner->getKartProperties()->getBubblegumShieldDuration() + m_owner->getShieldTime()); } } @@ -300,9 +300,9 @@ void Powerup::use() if(kart->getPosition() == 1) { kart->getAttachment()->set(Attachment::ATTACH_ANVIL, - m_owner->getCharacteristic()->getAnvilDuration()); + m_owner->getKartProperties()->getAnvilDuration()); kart->updateWeight(); - kart->adjustSpeed(m_owner->getCharacteristic()->getAnvilSpeedFactor() * 0.5f); + kart->adjustSpeed(m_owner->getKartProperties()->getAnvilSpeedFactor() * 0.5f); // should we position the sound at the kart that is hit, // or the kart "throwing" the anvil? Ideally it should be both. @@ -339,7 +339,7 @@ void Powerup::use() { kart->getAttachment() ->set(Attachment::ATTACH_PARACHUTE, - m_owner->getCharacteristic()->getParachuteDurationOther()); + m_owner->getKartProperties()->getParachuteDurationOther()); if(kart->getController()->isPlayerController()) player_kart = kart; diff --git a/src/items/rubber_band.cpp b/src/items/rubber_band.cpp index bfa1303e8..805028b94 100644 --- a/src/items/rubber_band.cpp +++ b/src/items/rubber_band.cpp @@ -150,7 +150,7 @@ void RubberBand::update(float dt) // Check for rubber band snapping // ------------------------------ float l = (m_end_position-k).length2(); - float max_len = m_owner->getCharacteristic()->getPlungerBandMaxLength(); + float max_len = m_owner->getKartProperties()->getPlungerBandMaxLength(); if(l>max_len*max_len) { // Rubber band snaps @@ -163,7 +163,7 @@ void RubberBand::update(float dt) // ---------------------------- if(m_attached_state!=RB_TO_PLUNGER) { - float force = m_owner->getCharacteristic()->getPlungerBandForce(); + float force = m_owner->getKartProperties()->getPlungerBandForce(); Vec3 diff = m_end_position-k; // detach rubber band if kart gets very close to hit point @@ -179,10 +179,10 @@ void RubberBand::update(float dt) diff.normalize(); // diff can't be zero here m_owner->getBody()->applyCentralForce(diff*force); m_owner->increaseMaxSpeed(MaxSpeed::MS_INCREASE_RUBBER, - m_owner->getCharacteristic()->getPlungerBandSpeedIncrease(), + m_owner->getKartProperties()->getPlungerBandSpeedIncrease(), /*engine_force*/ 0.0f, /*duration*/0.1f, - m_owner->getCharacteristic()->getPlungerBandFadeOutTime()); + m_owner->getKartProperties()->getPlungerBandFadeOutTime()); if(m_attached_state==RB_TO_KART) m_hit_kart->getBody()->applyCentralForce(diff*(-force)); } diff --git a/src/items/swatter.cpp b/src/items/swatter.cpp index 4b96e37c8..13140595b 100644 --- a/src/items/swatter.cpp +++ b/src/items/swatter.cpp @@ -157,7 +157,7 @@ bool Swatter::updateAndTestFinished(float dt) (m_target->getXYZ()- Vec3(m_scene_node->getAbsolutePosition())) .length2(); float min_dist2 - = m_kart->getCharacteristic()->getSwatterDistance(); + = m_kart->getKartProperties()->getSwatterDistance(); if(dist_to_target2 < min_dist2) { // Start squashing @@ -265,9 +265,9 @@ void Swatter::pointToTarget() */ void Swatter::squashThingsAround() { - const AbstractCharacteristic *ch = m_kart->getCharacteristic(); + const KartProperties *kp = m_kart->getKartProperties(); // Square of the minimum distance - float min_dist2 = ch->getSwatterDistance(); + float min_dist2 = kp->getSwatterDistance(); const World* world = World::getWorld(); // Get the node corresponding to the joint at the center of the swatter @@ -294,7 +294,7 @@ void Swatter::squashThingsAround() if(dist2 >= min_dist2) continue; // too far away, ignore this kart - kart->setSquash(ch->getSwatterSquashDuration(), ch->getSwatterSquashSlowdown()); + kart->setSquash(kp->getSwatterSquashDuration(), kp->getSwatterSquashSlowdown()); //Handle achievement if the swatter is used by the current player const StateManager::ActivePlayer *const ap = m_kart->getController() diff --git a/src/karts/abstract_characteristic.cpp b/src/karts/abstract_characteristic.cpp index b39d0eb9b..f25c41150 100755 --- a/src/karts/abstract_characteristic.cpp +++ b/src/karts/abstract_characteristic.cpp @@ -53,7 +53,7 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType( // Please don't change the following tag. It will be automatically detected // by the script and replace the contained content. // To update the code, use tools/update_characteristics.py - /* */ + /* */ case SUSPENSION_STIFFNESS: return TYPE_FLOAT; case SUSPENSION_REST: @@ -259,7 +259,7 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType( case SKID_ENABLED: return TYPE_BOOL; - /* */ + /* */ } // switch (type) Log::fatal("AbstractCharacteristic::getType", "Unknown type"); return TYPE_FLOAT; @@ -277,7 +277,7 @@ std::string AbstractCharacteristic::getName(CharacteristicType type) // Please don't change the following tag. It will be automatically detected // by the script and replace the contained content. // To update the code, use tools/update_characteristics.py - /* */ + /* */ case SUSPENSION_STIFFNESS: return "SUSPENSION_STIFFNESS"; case SUSPENSION_REST: @@ -483,18 +483,17 @@ std::string AbstractCharacteristic::getName(CharacteristicType type) case SKID_ENABLED: return "SKID_ENABLED"; - /* */ + /* */ } // switch (type) Log::error("AbstractCharacteristic::getName", "Unknown type"); return "Unknown type"; } // getName -// ---------------------------------------------------------------------------- -// Script-generated content generated by tools/create_kart_properties.py getter +// Script-generated content generated by tools/create_kart_properties.py defs // Please don't change the following tag. It will be automatically detected // by the script and replace the contained content. // To update the code, use tools/update_characteristics.py -/* */ +/* */ // ---------------------------------------------------------------------------- float AbstractCharacteristic::getSuspensionStiffness() const { @@ -1720,5 +1719,5 @@ bool AbstractCharacteristic::getSkidEnabled() const } // getSkidEnabled -/* */ +/* */ diff --git a/src/karts/abstract_characteristic.hpp b/src/karts/abstract_characteristic.hpp index 9c5badc90..0f1ac3d2c 100755 --- a/src/karts/abstract_characteristic.hpp +++ b/src/karts/abstract_characteristic.hpp @@ -245,11 +245,12 @@ public: static ValueType getType(CharacteristicType type); static std::string getName(CharacteristicType type); + // Script-generated content generated by tools/create_kart_properties.py defs // Please don't change the following tag. It will be automatically detected // by the script and replace the contained content. // To update the code, use tools/update_characteristics.py - /* */ + /* */ float getSuspensionStiffness() const; float getSuspensionRest() const; @@ -375,7 +376,7 @@ public: float getSkidReduceTurnMax() const; bool getSkidEnabled() const; - /* */ + /* */ }; #endif diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index 9ab4f1888..d6ee8c5a0 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2651,14 +2651,14 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz, const float steer_frac = m_skidding->getSteeringFraction(); - const float roll_speed = m_kart_properties->getLeanSpeed(); + const float roll_speed = m_kart_properties->getLeanSpeed() * DEGREE_TO_RAD; if(speed_frac > 0.8f && fabsf(steer_frac)>0.5f) { // Use steering ^ 7, which means less effect at lower // steering const float f = m_skidding->getSteeringFraction(); const float f2 = f*f; - const float max_lean = -m_kart_properties->getMaxLean() + const float max_lean = -m_kart_properties->getLeanMax() * DEGREE_TO_RAD * f2*f2*f2*f * speed_frac; if(max_lean>0) diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 882ab7854..09fc83c81 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -321,6 +321,7 @@ void KartProperties::combineCharacteristics() m_combined_characteristic->addCharacteristic(characteristic); m_combined_characteristic->addCharacteristic(m_characteristic.get()); + m_cached_characteristic.reset(new CachedCharacteristic(m_combined_characteristic.get())); } // combineCharacteristics //----------------------------------------------------------------------------- @@ -448,15 +449,6 @@ void KartProperties::getAllData(const XMLNode * root) #endif } // if sounds-node exist - - if(const XMLNode *lean_node= root->getNode("lean")) - { - lean_node->get("max", &m_max_lean ); - lean_node->get("speed", &m_lean_speed); - m_max_lean *= DEGREE_TO_RAD; - m_lean_speed *= DEGREE_TO_RAD; - } - if(m_kart_model) m_kart_model->loadInfo(*root); } // getAllData @@ -482,9 +474,6 @@ void KartProperties::checkAllSet(const std::string &filename) CHECK_NEG(m_restitution, "collision restitution" ); CHECK_NEG(m_physical_wheel_position, "collision physical-wheel-position"); - CHECK_NEG(m_max_lean, "lean max" ); - CHECK_NEG(m_lean_speed, "lean speed" ); - m_speed_weighted_object_properties.checkAllSet(); for(unsigned int i=0; i */ +// ---------------------------------------------------------------------------- +float KartProperties::getSuspensionStiffness() const +{ + return m_cached_characteristic->getSuspensionStiffness(); +} // getSuspensionStiffness + +// ---------------------------------------------------------------------------- +float KartProperties::getSuspensionRest() const +{ + return m_cached_characteristic->getSuspensionRest(); +} // getSuspensionRest + +// ---------------------------------------------------------------------------- +float KartProperties::getSuspensionTravel() const +{ + return m_cached_characteristic->getSuspensionTravel(); +} // getSuspensionTravel + +// ---------------------------------------------------------------------------- +bool KartProperties::getSuspensionExpSpringResponse() const +{ + return m_cached_characteristic->getSuspensionExpSpringResponse(); +} // getSuspensionExpSpringResponse + +// ---------------------------------------------------------------------------- +float KartProperties::getSuspensionMaxForce() const +{ + return m_cached_characteristic->getSuspensionMaxForce(); +} // getSuspensionMaxForce + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilityRollInfluence() const +{ + return m_cached_characteristic->getStabilityRollInfluence(); +} // getStabilityRollInfluence + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilityChassisLinearDamping() const +{ + return m_cached_characteristic->getStabilityChassisLinearDamping(); +} // getStabilityChassisLinearDamping + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilityChassisAngularDamping() const +{ + return m_cached_characteristic->getStabilityChassisAngularDamping(); +} // getStabilityChassisAngularDamping + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilityDownwardImpulseFactor() const +{ + return m_cached_characteristic->getStabilityDownwardImpulseFactor(); +} // getStabilityDownwardImpulseFactor + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilityTrackConnectionAccel() const +{ + return m_cached_characteristic->getStabilityTrackConnectionAccel(); +} // getStabilityTrackConnectionAccel + +// ---------------------------------------------------------------------------- +float KartProperties::getStabilitySmoothFlyingImpulse() const +{ + return m_cached_characteristic->getStabilitySmoothFlyingImpulse(); +} // getStabilitySmoothFlyingImpulse + +// ---------------------------------------------------------------------------- +InterpolationArray KartProperties::getTurnRadius() const +{ + return m_cached_characteristic->getTurnRadius(); +} // getTurnRadius + +// ---------------------------------------------------------------------------- +float KartProperties::getTurnTimeResetSteer() const +{ + return m_cached_characteristic->getTurnTimeResetSteer(); +} // getTurnTimeResetSteer + +// ---------------------------------------------------------------------------- +InterpolationArray KartProperties::getTurnTimeFullSteer() const +{ + return m_cached_characteristic->getTurnTimeFullSteer(); +} // getTurnTimeFullSteer + +// ---------------------------------------------------------------------------- +float KartProperties::getEnginePower() const +{ + return m_cached_characteristic->getEnginePower(); +} // getEnginePower + +// ---------------------------------------------------------------------------- +float KartProperties::getEngineMaxSpeed() const +{ + return m_cached_characteristic->getEngineMaxSpeed(); +} // getEngineMaxSpeed + +// ---------------------------------------------------------------------------- +float KartProperties::getEngineBrakeFactor() const +{ + return m_cached_characteristic->getEngineBrakeFactor(); +} // getEngineBrakeFactor + +// ---------------------------------------------------------------------------- +float KartProperties::getEngineBrakeTimeIncrease() const +{ + return m_cached_characteristic->getEngineBrakeTimeIncrease(); +} // getEngineBrakeTimeIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getEngineMaxSpeedReverseRatio() const +{ + return m_cached_characteristic->getEngineMaxSpeedReverseRatio(); +} // getEngineMaxSpeedReverseRatio + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getGearSwitchRatio() const +{ + return m_cached_characteristic->getGearSwitchRatio(); +} // getGearSwitchRatio + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getGearPowerIncrease() const +{ + return m_cached_characteristic->getGearPowerIncrease(); +} // getGearPowerIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getMass() const +{ + return m_cached_characteristic->getMass(); +} // getMass + +// ---------------------------------------------------------------------------- +float KartProperties::getWheelsDampingRelaxation() const +{ + return m_cached_characteristic->getWheelsDampingRelaxation(); +} // getWheelsDampingRelaxation + +// ---------------------------------------------------------------------------- +float KartProperties::getWheelsDampingCompression() const +{ + return m_cached_characteristic->getWheelsDampingCompression(); +} // getWheelsDampingCompression + +// ---------------------------------------------------------------------------- +float KartProperties::getCameraDistance() const +{ + return m_cached_characteristic->getCameraDistance(); +} // getCameraDistance + +// ---------------------------------------------------------------------------- +float KartProperties::getCameraForwardUpAngle() const +{ + return m_cached_characteristic->getCameraForwardUpAngle(); +} // getCameraForwardUpAngle + +// ---------------------------------------------------------------------------- +float KartProperties::getCameraBackwardUpAngle() const +{ + return m_cached_characteristic->getCameraBackwardUpAngle(); +} // getCameraBackwardUpAngle + +// ---------------------------------------------------------------------------- +float KartProperties::getJumpAnimationTime() const +{ + return m_cached_characteristic->getJumpAnimationTime(); +} // getJumpAnimationTime + +// ---------------------------------------------------------------------------- +float KartProperties::getLeanMax() const +{ + return m_cached_characteristic->getLeanMax(); +} // getLeanMax + +// ---------------------------------------------------------------------------- +float KartProperties::getLeanSpeed() const +{ + return m_cached_characteristic->getLeanSpeed(); +} // getLeanSpeed + +// ---------------------------------------------------------------------------- +float KartProperties::getAnvilDuration() const +{ + return m_cached_characteristic->getAnvilDuration(); +} // getAnvilDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getAnvilWeight() const +{ + return m_cached_characteristic->getAnvilWeight(); +} // getAnvilWeight + +// ---------------------------------------------------------------------------- +float KartProperties::getAnvilSpeedFactor() const +{ + return m_cached_characteristic->getAnvilSpeedFactor(); +} // getAnvilSpeedFactor + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteFriction() const +{ + return m_cached_characteristic->getParachuteFriction(); +} // getParachuteFriction + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteDuration() const +{ + return m_cached_characteristic->getParachuteDuration(); +} // getParachuteDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteDurationOther() const +{ + return m_cached_characteristic->getParachuteDurationOther(); +} // getParachuteDurationOther + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteLboundFraction() const +{ + return m_cached_characteristic->getParachuteLboundFraction(); +} // getParachuteLboundFraction + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteUboundFraction() const +{ + return m_cached_characteristic->getParachuteUboundFraction(); +} // getParachuteUboundFraction + +// ---------------------------------------------------------------------------- +float KartProperties::getParachuteMaxSpeed() const +{ + return m_cached_characteristic->getParachuteMaxSpeed(); +} // getParachuteMaxSpeed + +// ---------------------------------------------------------------------------- +float KartProperties::getBubblegumDuration() const +{ + return m_cached_characteristic->getBubblegumDuration(); +} // getBubblegumDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getBubblegumSpeedFraction() const +{ + return m_cached_characteristic->getBubblegumSpeedFraction(); +} // getBubblegumSpeedFraction + +// ---------------------------------------------------------------------------- +float KartProperties::getBubblegumTorque() const +{ + return m_cached_characteristic->getBubblegumTorque(); +} // getBubblegumTorque + +// ---------------------------------------------------------------------------- +float KartProperties::getBubblegumFadeInTime() const +{ + return m_cached_characteristic->getBubblegumFadeInTime(); +} // getBubblegumFadeInTime + +// ---------------------------------------------------------------------------- +float KartProperties::getBubblegumShieldDuration() const +{ + return m_cached_characteristic->getBubblegumShieldDuration(); +} // getBubblegumShieldDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getZipperDuration() const +{ + return m_cached_characteristic->getZipperDuration(); +} // getZipperDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getZipperForce() const +{ + return m_cached_characteristic->getZipperForce(); +} // getZipperForce + +// ---------------------------------------------------------------------------- +float KartProperties::getZipperSpeedGain() const +{ + return m_cached_characteristic->getZipperSpeedGain(); +} // getZipperSpeedGain + +// ---------------------------------------------------------------------------- +float KartProperties::getZipperMaxSpeedIncrease() const +{ + return m_cached_characteristic->getZipperMaxSpeedIncrease(); +} // getZipperMaxSpeedIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getZipperFadeOutTime() const +{ + return m_cached_characteristic->getZipperFadeOutTime(); +} // getZipperFadeOutTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSwatterDuration() const +{ + return m_cached_characteristic->getSwatterDuration(); +} // getSwatterDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getSwatterDistance() const +{ + return m_cached_characteristic->getSwatterDistance(); +} // getSwatterDistance + +// ---------------------------------------------------------------------------- +float KartProperties::getSwatterSquashDuration() const +{ + return m_cached_characteristic->getSwatterSquashDuration(); +} // getSwatterSquashDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getSwatterSquashSlowdown() const +{ + return m_cached_characteristic->getSwatterSquashSlowdown(); +} // getSwatterSquashSlowdown + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerBandMaxLength() const +{ + return m_cached_characteristic->getPlungerBandMaxLength(); +} // getPlungerBandMaxLength + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerBandForce() const +{ + return m_cached_characteristic->getPlungerBandForce(); +} // getPlungerBandForce + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerBandDuration() const +{ + return m_cached_characteristic->getPlungerBandDuration(); +} // getPlungerBandDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerBandSpeedIncrease() const +{ + return m_cached_characteristic->getPlungerBandSpeedIncrease(); +} // getPlungerBandSpeedIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerBandFadeOutTime() const +{ + return m_cached_characteristic->getPlungerBandFadeOutTime(); +} // getPlungerBandFadeOutTime + +// ---------------------------------------------------------------------------- +float KartProperties::getPlungerInFaceTime() const +{ + return m_cached_characteristic->getPlungerInFaceTime(); +} // getPlungerInFaceTime + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getStartupTime() const +{ + return m_cached_characteristic->getStartupTime(); +} // getStartupTime + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getStartupBoost() const +{ + return m_cached_characteristic->getStartupBoost(); +} // getStartupBoost + +// ---------------------------------------------------------------------------- +float KartProperties::getRescueDuration() const +{ + return m_cached_characteristic->getRescueDuration(); +} // getRescueDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getRescueVertOffset() const +{ + return m_cached_characteristic->getRescueVertOffset(); +} // getRescueVertOffset + +// ---------------------------------------------------------------------------- +float KartProperties::getRescueHeight() const +{ + return m_cached_characteristic->getRescueHeight(); +} // getRescueHeight + +// ---------------------------------------------------------------------------- +float KartProperties::getExplosionDuration() const +{ + return m_cached_characteristic->getExplosionDuration(); +} // getExplosionDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getExplosionRadius() const +{ + return m_cached_characteristic->getExplosionRadius(); +} // getExplosionRadius + +// ---------------------------------------------------------------------------- +float KartProperties::getExplosionInvulnerabilityTime() const +{ + return m_cached_characteristic->getExplosionInvulnerabilityTime(); +} // getExplosionInvulnerabilityTime + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroDuration() const +{ + return m_cached_characteristic->getNitroDuration(); +} // getNitroDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroEngineForce() const +{ + return m_cached_characteristic->getNitroEngineForce(); +} // getNitroEngineForce + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroConsumption() const +{ + return m_cached_characteristic->getNitroConsumption(); +} // getNitroConsumption + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroSmallContainer() const +{ + return m_cached_characteristic->getNitroSmallContainer(); +} // getNitroSmallContainer + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroBigContainer() const +{ + return m_cached_characteristic->getNitroBigContainer(); +} // getNitroBigContainer + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroMaxSpeedIncrease() const +{ + return m_cached_characteristic->getNitroMaxSpeedIncrease(); +} // getNitroMaxSpeedIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroFadeOutTime() const +{ + return m_cached_characteristic->getNitroFadeOutTime(); +} // getNitroFadeOutTime + +// ---------------------------------------------------------------------------- +float KartProperties::getNitroMax() const +{ + return m_cached_characteristic->getNitroMax(); +} // getNitroMax + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamDuration() const +{ + return m_cached_characteristic->getSlipstreamDuration(); +} // getSlipstreamDuration + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamLength() const +{ + return m_cached_characteristic->getSlipstreamLength(); +} // getSlipstreamLength + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamWidth() const +{ + return m_cached_characteristic->getSlipstreamWidth(); +} // getSlipstreamWidth + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamCollectTime() const +{ + return m_cached_characteristic->getSlipstreamCollectTime(); +} // getSlipstreamCollectTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamUseTime() const +{ + return m_cached_characteristic->getSlipstreamUseTime(); +} // getSlipstreamUseTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamAddPower() const +{ + return m_cached_characteristic->getSlipstreamAddPower(); +} // getSlipstreamAddPower + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamMinSpeed() const +{ + return m_cached_characteristic->getSlipstreamMinSpeed(); +} // getSlipstreamMinSpeed + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamMaxSpeedIncrease() const +{ + return m_cached_characteristic->getSlipstreamMaxSpeedIncrease(); +} // getSlipstreamMaxSpeedIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getSlipstreamFadeOutTime() const +{ + return m_cached_characteristic->getSlipstreamFadeOutTime(); +} // getSlipstreamFadeOutTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidIncrease() const +{ + return m_cached_characteristic->getSkidIncrease(); +} // getSkidIncrease + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidDecrease() const +{ + return m_cached_characteristic->getSkidDecrease(); +} // getSkidDecrease + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidMax() const +{ + return m_cached_characteristic->getSkidMax(); +} // getSkidMax + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidTimeTillMax() const +{ + return m_cached_characteristic->getSkidTimeTillMax(); +} // getSkidTimeTillMax + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidVisual() const +{ + return m_cached_characteristic->getSkidVisual(); +} // getSkidVisual + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidVisualTime() const +{ + return m_cached_characteristic->getSkidVisualTime(); +} // getSkidVisualTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidRevertVisualTime() const +{ + return m_cached_characteristic->getSkidRevertVisualTime(); +} // getSkidRevertVisualTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidMinSpeed() const +{ + return m_cached_characteristic->getSkidMinSpeed(); +} // getSkidMinSpeed + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getSkidTimeTillBonus() const +{ + return m_cached_characteristic->getSkidTimeTillBonus(); +} // getSkidTimeTillBonus + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getSkidBonusSpeed() const +{ + return m_cached_characteristic->getSkidBonusSpeed(); +} // getSkidBonusSpeed + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getSkidBonusTime() const +{ + return m_cached_characteristic->getSkidBonusTime(); +} // getSkidBonusTime + +// ---------------------------------------------------------------------------- +std::vector KartProperties::getSkidBonusForce() const +{ + return m_cached_characteristic->getSkidBonusForce(); +} // getSkidBonusForce + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidPhysicalJumpTime() const +{ + return m_cached_characteristic->getSkidPhysicalJumpTime(); +} // getSkidPhysicalJumpTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidGraphicalJumpTime() const +{ + return m_cached_characteristic->getSkidGraphicalJumpTime(); +} // getSkidGraphicalJumpTime + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidPostSkidRotateFactor() const +{ + return m_cached_characteristic->getSkidPostSkidRotateFactor(); +} // getSkidPostSkidRotateFactor + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidReduceTurnMin() const +{ + return m_cached_characteristic->getSkidReduceTurnMin(); +} // getSkidReduceTurnMin + +// ---------------------------------------------------------------------------- +float KartProperties::getSkidReduceTurnMax() const +{ + return m_cached_characteristic->getSkidReduceTurnMax(); +} // getSkidReduceTurnMax + +// ---------------------------------------------------------------------------- +bool KartProperties::getSkidEnabled() const +{ + return m_cached_characteristic->getSkidEnabled(); +} // getSkidEnabled + + +/* */ + diff --git a/src/karts/kart_properties.hpp b/src/karts/kart_properties.hpp index 604feb6a2..c9ff4fc68 100644 --- a/src/karts/kart_properties.hpp +++ b/src/karts/kart_properties.hpp @@ -123,6 +123,8 @@ private: std::shared_ptr m_characteristic; /** The base characteristics combined with the characteristics of this kart. */ std::shared_ptr m_combined_characteristic; + /** The cached combined characteristics. */ + std::unique_ptr m_cached_characteristic; // Physic properties // ----------------- @@ -382,13 +384,6 @@ public: /** Returns the full path where the files for this kart are stored. */ const std::string& getKartDir () const {return m_root; } - // ------------------------------------------------------------------------ - /** The maximum leaning a kart should show (In radians). */ - float getMaxLean() const { return m_max_lean; } - - // ------------------------------------------------------------------------ - /** The speed with which a kart should lean (in radians/s). */ - float getLeanSpeed() const { return m_lean_speed; } // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ /** Returns minimum time during which nitro is consumed when pressing nitro @@ -411,6 +406,139 @@ public: // ------------------------------------------------------------------------ float getAvgPower() const; + + + // Script-generated content generated by tools/create_kart_properties.py defs + // Please don't change the following tag. It will be automatically detected + // by the script and replace the contained content. + // To update the code, use tools/update_characteristics.py + /* */ + + float getSuspensionStiffness() const; + float getSuspensionRest() const; + float getSuspensionTravel() const; + bool getSuspensionExpSpringResponse() const; + float getSuspensionMaxForce() const; + + float getStabilityRollInfluence() const; + float getStabilityChassisLinearDamping() const; + float getStabilityChassisAngularDamping() const; + float getStabilityDownwardImpulseFactor() const; + float getStabilityTrackConnectionAccel() const; + float getStabilitySmoothFlyingImpulse() const; + + InterpolationArray getTurnRadius() const; + float getTurnTimeResetSteer() const; + InterpolationArray getTurnTimeFullSteer() const; + + float getEnginePower() const; + float getEngineMaxSpeed() const; + float getEngineBrakeFactor() const; + float getEngineBrakeTimeIncrease() const; + float getEngineMaxSpeedReverseRatio() const; + + std::vector getGearSwitchRatio() const; + std::vector getGearPowerIncrease() const; + + float getMass() const; + + float getWheelsDampingRelaxation() const; + float getWheelsDampingCompression() const; + + float getCameraDistance() const; + float getCameraForwardUpAngle() const; + float getCameraBackwardUpAngle() const; + + float getJumpAnimationTime() const; + + float getLeanMax() const; + float getLeanSpeed() const; + + float getAnvilDuration() const; + float getAnvilWeight() const; + float getAnvilSpeedFactor() const; + + float getParachuteFriction() const; + float getParachuteDuration() const; + float getParachuteDurationOther() const; + float getParachuteLboundFraction() const; + float getParachuteUboundFraction() const; + float getParachuteMaxSpeed() const; + + float getBubblegumDuration() const; + float getBubblegumSpeedFraction() const; + float getBubblegumTorque() const; + float getBubblegumFadeInTime() const; + float getBubblegumShieldDuration() const; + + float getZipperDuration() const; + float getZipperForce() const; + float getZipperSpeedGain() const; + float getZipperMaxSpeedIncrease() const; + float getZipperFadeOutTime() const; + + float getSwatterDuration() const; + float getSwatterDistance() const; + float getSwatterSquashDuration() const; + float getSwatterSquashSlowdown() const; + + float getPlungerBandMaxLength() const; + float getPlungerBandForce() const; + float getPlungerBandDuration() const; + float getPlungerBandSpeedIncrease() const; + float getPlungerBandFadeOutTime() const; + float getPlungerInFaceTime() const; + + std::vector getStartupTime() const; + std::vector getStartupBoost() const; + + float getRescueDuration() const; + float getRescueVertOffset() const; + float getRescueHeight() const; + + float getExplosionDuration() const; + float getExplosionRadius() const; + float getExplosionInvulnerabilityTime() const; + + float getNitroDuration() const; + float getNitroEngineForce() const; + float getNitroConsumption() const; + float getNitroSmallContainer() const; + float getNitroBigContainer() const; + float getNitroMaxSpeedIncrease() const; + float getNitroFadeOutTime() const; + float getNitroMax() const; + + float getSlipstreamDuration() const; + float getSlipstreamLength() const; + float getSlipstreamWidth() const; + float getSlipstreamCollectTime() const; + float getSlipstreamUseTime() const; + float getSlipstreamAddPower() const; + float getSlipstreamMinSpeed() const; + float getSlipstreamMaxSpeedIncrease() const; + float getSlipstreamFadeOutTime() const; + + float getSkidIncrease() const; + float getSkidDecrease() const; + float getSkidMax() const; + float getSkidTimeTillMax() const; + float getSkidVisual() const; + float getSkidVisualTime() const; + float getSkidRevertVisualTime() const; + float getSkidMinSpeed() const; + std::vector getSkidTimeTillBonus() const; + std::vector getSkidBonusSpeed() const; + std::vector getSkidBonusTime() const; + std::vector getSkidBonusForce() const; + float getSkidPhysicalJumpTime() const; + float getSkidGraphicalJumpTime() const; + float getSkidPostSkidRotateFactor() const; + float getSkidReduceTurnMin() const; + float getSkidReduceTurnMax() const; + bool getSkidEnabled() const; + + /* */ }; // KartProperties #endif diff --git a/tools/create_kart_properties.py b/tools/create_kart_properties.py index 5d6a1c6db..4b00ba3b1 100755 --- a/tools/create_kart_properties.py +++ b/tools/create_kart_properties.py @@ -140,60 +140,35 @@ def joinSubName(group, member, titleCase): else: return "_".join(words) -def main(): - # Find out what to do - if len(sys.argv) == 1: - print("""Usage: ./create_kart_properties.py -Operations: - enum List the enum values for all characteristics in abstract_characteristic.hpp - defs Create the headers in abstract_characteristic.hpp - getter The getter implementations in abstract_characteristic.cpp - getProp1 Creates the getType function in abstract_characteristic.cpp - getProp2 Creates the getName funciton in abstract_characteristic.cpp - getXml Used to load the characteristics from an xml file in xml_characteristic.cpp""") - return - task = sys.argv[1] +# Functions to generate code - groups = [Group.parse(line) for line in characteristics.split("\n")] +def createEnum(groups): + for g in groups: + print() + print(" // {0}".format(g.getBaseName().title())) + for m in g.members: + print(" {0},".format(joinSubName(g, m, False).upper())) - # Find longest name to align the function bodies - nameLengthTitle = 0 - nameLengthUnderscore = 0 +def createAcDefs(groups): + for g in groups: + print() + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + typeC = m.typeC + + print(" {0} get{1}() const;". + format(typeC, nameTitle, nameUnderscore)) + +def createAcGetter(groups): for g in groups: for m in g.members: - l = len(joinSubName(g, m, True)) - if l > nameLengthTitle: - nameLengthTitle = l - l = len(joinSubName(g, m, False)) - if l > nameLengthUnderscore: - nameLengthUnderscore = l + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + typeC = m.typeC + result = "result" - # Print the results - if task == "enum": - for g in groups: - print() - print(" // {0}".format(g.getBaseName().title())) - for m in g.members: - print(" {0},".format(joinSubName(g, m, False).upper())) - elif task == "defs": - for g in groups: - print() - for m in g.members: - nameTitle = joinSubName(g, m, True) - nameUnderscore = joinSubName(g, m, False) - typeC = m.typeC - - print(" {0} get{1}() const;". - format(typeC, nameTitle, nameUnderscore)) - elif task == "getter": - for g in groups: - for m in g.members: - nameTitle = joinSubName(g, m, True) - nameUnderscore = joinSubName(g, m, False) - typeC = m.typeC - result = "result" - - print("""// ---------------------------------------------------------------------------- + print("""// ---------------------------------------------------------------------------- {3} AbstractCharacteristic::get{1}() const {{ {0} result; @@ -205,33 +180,105 @@ Operations: return {4}; }} // get{1} """.format(m.typeC, nameTitle, nameUnderscore.upper(), typeC, result)) - elif task == "getProp1": - for g in groups: - for m in g.members: - nameTitle = joinSubName(g, m, True) - nameUnderscore = joinSubName(g, m, False) - print(" case {0}:\n return TYPE_{1};". - format(nameUnderscore.upper(), "_".join(toList(m.typeStr)).upper())) - elif task == "getProp2": - for g in groups: - for m in g.members: - nameTitle = joinSubName(g, m, True) - nameUnderscore = joinSubName(g, m, False).upper() - print(" case {0}:\n return \"{0}\";". - format(nameUnderscore)) - elif task == "getXml": - for g in groups: - print(" if (const XMLNode *sub_node = node->getNode(\"{0}\"))\n {{". - format(g.baseName.lower())) - for m in g.members: - nameUnderscore = joinSubName(g, m, False) - nameMinus = "-".join(toList(m.name)) - print(""" sub_node->get(\"{0}\", + +def createKpDefs(groups): + for g in groups: + print() + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + typeC = m.typeC + + print(" {0} get{1}() const;". + format(typeC, nameTitle, nameUnderscore)) + +def createKpGetter(groups): + for g in groups: + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + typeC = m.typeC + result = "result" + + print("""// ---------------------------------------------------------------------------- +{1} KartProperties::get{0}() const +{{ + return m_cached_characteristic->get{0}(); +}} // get{0} +""".format(nameTitle, typeC)) + +def createGetType(groups): + for g in groups: + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False) + print(" case {0}:\n return TYPE_{1};". + format(nameUnderscore.upper(), "_".join(toList(m.typeStr)).upper())) + +def createGetName(groups): + for g in groups: + for m in g.members: + nameTitle = joinSubName(g, m, True) + nameUnderscore = joinSubName(g, m, False).upper() + print(" case {0}:\n return \"{0}\";". + format(nameUnderscore)) + +def createLoadXml(groups): + for g in groups: + print(" if (const XMLNode *sub_node = node->getNode(\"{0}\"))\n {{". + format(g.baseName.lower())) + for m in g.members: + nameUnderscore = joinSubName(g, m, False) + nameMinus = "-".join(toList(m.name)) + print(""" sub_node->get(\"{0}\", &m_values[{1}]);""". - format(nameMinus, nameUnderscore.upper())) - print(" }\n") - else: - print("Unknown task") + format(nameMinus, nameUnderscore.upper())) + print(" }\n") + +# Dicionary that maps an argument string to a tupel of +# a generator function, a help string and a filename +functions = { + "enum": (createEnum, "List the enum values for all characteristics", "karts/abstract_characteristic.hpp"), + "acdefs": (createAcDefs, "Create the header function definitions", "karts/abstract_characteristic.hpp"), + "acgetter": (createAcGetter, "Implement the getters", "karts/abstract_characteristic.cpp"), + "getType": (createGetType, "Implement the getType function", "karts/abstract_characteristic.cpp"), + "getName": (createGetName, "Implement the getName function", "karts/abstract_characteristic.cpp"), + "kpdefs": (createKpDefs, "Create the header function definitions for the getters", "karts/kart_properties.hpp"), + "kpgetter": (createKpGetter, "Implement the getters", "karts/kart_properties.cpp"), + "loadXml": (createLoadXml, "Code to load the characteristics from an xml file", "karts/xml_characteristic.hpp"), +} + +def main(): + # Find out what to do + if len(sys.argv) != 2: + print("""Usage: ./create_kart_properties.py +Operations:""") + maxOperationLength = 0 + maxDescriptionLength = 0 + for o, f in functions.items(): + l = len(o) + if l > maxOperationLength: + maxOperationLength = l + l = len(f[1]) + if l > maxDescriptionLength: + maxDescriptionLength = l + + formatString = " {{0:{0}}} {{1:{1}}} in {{2}}".format(maxOperationLength, maxDescriptionLength) + for o, f in functions.items(): + print(formatString.format(o, f[1], f[2])) + return + + task = sys.argv[1] + + if task not in functions: + print("The wanted operation was not found. Please call this script without arguments to list available arguments.") + return + + # Parse properties + groups = [Group.parse(line) for line in characteristics.split("\n")] + + # Create the wanted code + functions[task][0](groups) if __name__ == '__main__': main() diff --git a/tools/update_characteristics.py b/tools/update_characteristics.py index 0c8ee9c78..6815623e5 100755 --- a/tools/update_characteristics.py +++ b/tools/update_characteristics.py @@ -26,30 +26,24 @@ import os import re import subprocess -# Where and what should be replaced -replacements = [ - ["enum", "karts/abstract_characteristic.hpp"], - ["defs", "karts/abstract_characteristic.hpp"], - ["getter", "karts/abstract_characteristic.cpp"], - ["getProp1", "karts/abstract_characteristic.cpp"], - ["getProp2", "karts/abstract_characteristic.cpp"], - ["getXml", "karts/xml_characteristic.cpp"]] +from create_kart_properties import functions def main(): # Check, if it runs in the root directory if not os.path.isfile("tools/update_characteristics.py"): print("Please run this script in the root directory of the project.") exit(1) - for replacement in replacements: + for operation, function in functions.items(): + # + " 2> /dev/null" result = subprocess.Popen("tools/create_kart_properties.py " + - replacement[0] + " 2> /dev/null", shell = True, + operation, shell = True, stdout = subprocess.PIPE).stdout.read().decode('UTF-8') - with open("src/" + replacement[1], "r") as f: + with open("src/" + function[2], "r") as f: text = f.read() # Replace the text by using look behinds and look forwards - text = re.sub("(?<=/\* \ \*/\\n)(.|\n)*(?=\\n\s*/\* \*/)", result, text) - with open("src/" + replacement[1], "w") as f: + text = re.sub("(?<=/\* \ \*/\\n)(.|\n)*(?=\\n\s*/\* \*/)", result, text) + with open("src/" + function[2], "w") as f: f.write(text) if __name__ == '__main__':