-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code to generate official karts list
- Loading branch information
Showing
5 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<karts> | ||
<kart name="adiumy" type="medium" width="0.852" height="0.775" length="0.943" gravity-shift="0 0.2829 0"/> | ||
<kart name="amanda" type="heavy" width="1.119" height="0.764" length="1.476" gravity-shift="0 0.382 0"/> | ||
<kart name="beastie" type="heavy" width="0.837" height="0.847" length="1.49" gravity-shift="0 0.4235 0"/> | ||
<kart name="emule" type="medium" width="0.625" height="0.735" length="1.146" gravity-shift="0 0.3438 0"/> | ||
<kart name="gavroche" type="medium" width="0.77" height="0.614" length="1.272" gravity-shift="0 0.307 0"/> | ||
<kart name="gnu" type="medium" width="0.77" height="0.949" length="1.345" gravity-shift="0 0.4035 0"/> | ||
<kart name="hexley" type="light" width="0.611" height="0.858" length="1.608" gravity-shift="0 0.429 0"/> | ||
<kart name="kiki" type="light" width="0.866" height="0.974" length="1.227" gravity-shift="0 0.3681 0"/> | ||
<kart name="konqi" type="medium" width="0.931" height="0.857" length="1.588" gravity-shift="0 0.4285 0"/> | ||
<kart name="nolok" type="medium" width="0.725" height="0.645" length="1.413" gravity-shift="0 0.3225 0"/> | ||
<kart name="pidgin" type="heavy" width="0.781" height="0.627" length="1.243" gravity-shift="0 0.3135 0"/> | ||
<kart name="puffy" type="heavy" width="1.109" height="0.621" length="1.573" gravity-shift="0 0.3105 0"/> | ||
<kart name="sara_the_racer" type="light" width="0.459" height="0.989" length="1.152" gravity-shift="0 0.3456 0"/> | ||
<kart name="sara_the_wizard" type="medium" width="0.5" height="0.959" length="1.22" gravity-shift="0 0.366 0"/> | ||
<kart name="suzanne" type="medium" width="0.935" height="0.645" length="1.405" gravity-shift="0 0.3225 0"/> | ||
<kart name="tux" type="medium" width="0.821" height="0.675" length="1.437" gravity-shift="0 0.3375 0"/> | ||
<kart name="wilber" type="light" width="0.837" height="0.871" length="1.715" gravity-shift="0 0.4355 0"/> | ||
<kart name="xue" type="medium" width="1.006" height="0.944" length="1.446" gravity-shift="0 0.4338 0"/> | ||
</karts> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include "karts/official_karts.hpp" | ||
|
||
#include "karts/kart_properties_manager.hpp" | ||
#include "io/file_manager.hpp" | ||
#include "io/xml_node.hpp" | ||
#include "karts/kart_model.hpp" | ||
#include "karts/kart_properties.hpp" | ||
#include "utils/file_utils.hpp" | ||
#include "utils/log.hpp" | ||
#include "utils/vec3.hpp" | ||
|
||
#include <cassert> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <vector> | ||
|
||
namespace OfficialKarts | ||
{ | ||
// ============================================================================ | ||
struct OfficialKart | ||
{ | ||
std::string name; | ||
std::string type; | ||
float width; | ||
float height; | ||
float length; | ||
Vec3 gravity_shift; | ||
OfficialKart(const std::string& n, const std::string& t, float w, float h, | ||
float l, const Vec3& g) : name(n), type(t), width(w), height(h), | ||
length(l), gravity_shift(g) {} | ||
}; // OfficialKart | ||
std::vector<OfficialKart> g_official_karts; | ||
|
||
// ---------------------------------------------------------------------------- | ||
void dumpOfficialKarts() | ||
{ | ||
std::stringstream ss; | ||
ss << "<?xml version=\"1.0\"?>\n"; | ||
ss << "<karts>\n"; | ||
for (unsigned i = 0; i < kart_properties_manager->getNumberOfKarts(); i++) | ||
{ | ||
const KartProperties* kp = kart_properties_manager->getKartById(i); | ||
if (kp->isAddon()) | ||
continue; | ||
auto km = kp->getKartModelCopy(); | ||
ss << " <kart name=\"" << kp->getIdent() << "\" type=\"" << | ||
kp->getKartType() << "\" width=\"" << km->getWidth() << | ||
"\" height=\"" << km->getHeight() << "\" length=\"" << | ||
km->getLength() << "\" gravity-shift=\"" << | ||
kp->getGravityCenterShift().x() << " " << | ||
kp->getGravityCenterShift().y() << " " << | ||
kp->getGravityCenterShift().z() << "\"/>\n"; | ||
} | ||
ss << "</karts>\n"; | ||
std::string s = ss.str(); | ||
std::ofstream xml("official_karts.xml", std::ofstream::out); | ||
xml << ss.rdbuf(); | ||
xml.close(); | ||
} // getAllData | ||
|
||
// ---------------------------------------------------------------------------- | ||
void load() | ||
{ | ||
const std::string file_name = file_manager->getAsset("official_karts.xml"); | ||
if (file_name.empty()) | ||
Log::fatal("OfficialKarts", "Missing official_karts.xml"); | ||
const XMLNode *root = file_manager->createXMLTree(file_name); | ||
assert(root); | ||
for (unsigned int i = 0; i < root->getNumNodes(); i++) | ||
{ | ||
const XMLNode *node = root->getNode(i); | ||
std::string name; | ||
std::string type; | ||
float width = 0.0f; | ||
float height = 0.0f; | ||
float length = 0.0f; | ||
Vec3 gravity_shift; | ||
node->get("name", &name); | ||
node->get("type", &type); | ||
node->get("width", &width); | ||
node->get("height", &height); | ||
node->get("length", &length); | ||
node->get("gravity-shift", &gravity_shift); | ||
g_official_karts.emplace_back(name, type, width, height, length, | ||
gravity_shift); | ||
} | ||
} // load | ||
|
||
// ---------------------------------------------------------------------------- | ||
std::set<std::string> getOfficialKarts() | ||
{ | ||
std::set<std::string> result; | ||
for (OfficialKart& ok : g_official_karts) | ||
result.insert(ok.name); | ||
return result; | ||
} // getOfficialKarts | ||
|
||
// ---------------------------------------------------------------------------- | ||
const KartProperties* getKartByIdent(const std::string& ident, | ||
float* width, float* height, | ||
float* length, Vec3* gravity_shift) | ||
{ | ||
for (OfficialKart& ok : g_official_karts) | ||
{ | ||
if (ok.name == ident) | ||
{ | ||
for (unsigned i = 0; | ||
i < kart_properties_manager->getNumberOfKarts(); i++) | ||
{ | ||
const KartProperties* kp = | ||
kart_properties_manager->getKartById(i); | ||
if (kp->isAddon()) | ||
continue; | ||
if (kp->getKartType() == ok.type) | ||
{ | ||
*width = ok.width; | ||
*height = ok.height; | ||
*length = ok.length; | ||
*gravity_shift = ok.gravity_shift; | ||
return kp; | ||
} | ||
} | ||
} | ||
} | ||
return NULL; | ||
} // getKartByIdent | ||
|
||
} // OfficialKarts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef HEADER_OFFICIAL_KARTS_HPP | ||
#define HEADER_OFFICIAL_KARTS_HPP | ||
|
||
#include <string> | ||
#include <set> | ||
|
||
class KartProperties; | ||
class Vec3; | ||
|
||
namespace OfficialKarts | ||
{ | ||
void dumpOfficialKarts(); | ||
void load(); | ||
std::set<std::string> getOfficialKarts(); | ||
const KartProperties* getKartByIdent(const std::string& ident, | ||
float* width, float* height, | ||
float* length, Vec3* gravity_shift); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters