Load sliders from paths.json

This commit is contained in:
Gent
2020-09-25 14:42:31 -04:00
parent b4fb449e69
commit 0ea5712f8c
4 changed files with 43 additions and 15 deletions

View File

@@ -40,7 +40,7 @@ void TableData::init() {
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
}
loadPaths(); // load paths
loadPaths(&nextId); // load paths
// load everything else from xdttable
std::cout << "[INFO] Parsing xdt.json..." << std::endl;
@@ -223,7 +223,7 @@ int TableData::getItemType(int itemSet) {
/*
* Load paths from paths JSON.
*/
void TableData::loadPaths() {
void TableData::loadPaths(int* nextId) {
try {
std::ifstream inFile(settings::PATHJSON);
nlohmann::json pathData;
@@ -238,6 +238,21 @@ void TableData::loadPaths() {
}
std::cout << "[INFO] Loaded " << TransportManager::SkywayPaths.size() << " skyway paths" << std::endl;
// slider circuit
nlohmann::json pathDataSlider = pathData["slider"];
for (nlohmann::json::iterator _sliderPoint = pathDataSlider.begin(); _sliderPoint != pathDataSlider.end(); _sliderPoint++) {
auto sliderPoint = _sliderPoint.value();
if (sliderPoint["stop"]) { // check if this point in the circuit is a stop
// spawn a slider
std::cout << "bus ID was " << *nextId << std::endl;
BaseNPC* slider = new BaseNPC(sliderPoint["iX"], sliderPoint["iY"], sliderPoint["iZ"], 1, (*nextId)++, NPC_BUS);
NPCManager::NPCs[slider->appearanceData.iNPC_ID] = slider;
NPCManager::updateNPCPosition(slider->appearanceData.iNPC_ID, slider->appearanceData.iX, slider->appearanceData.iY, slider->appearanceData.iZ);
// set slider path to a rotation of the circuit
constructPathSlider(pathDataSlider, 0, slider->appearanceData.iNPC_ID);
}
}
// npc paths
nlohmann::json pathDataNPC = pathData["npc"];
for (nlohmann::json::iterator npcPath = pathDataNPC.begin(); npcPath != pathDataNPC.end(); npcPath++) {
@@ -272,6 +287,27 @@ void TableData::constructPathSkyway(nlohmann::json::iterator _pathData) {
TransportManager::SkywayPaths[pathData["iRouteID"]] = points;
}
void TableData::constructPathSlider(nlohmann::json points, int rotations, int sliderID) {
std::queue<WarpLocation> route;
std::rotate(points.begin(), points.begin() + rotations, points.end()); // rotate points
nlohmann::json::iterator _point = points.begin(); // iterator
auto point = _point.value();
WarpLocation from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
int stopTime = point["stop"] ? SLIDER_STOP_TICKS : 0; // arbitrary stop length
for (_point++; _point != points.end(); _point++) { // loop through all point Bs
point = _point.value();
for (int i = 0; i < stopTime + 1; i++) // repeat point if it's a stop
route.push(from); // add point A to the queue
WarpLocation to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
TransportManager::lerp(&route, from, to, SLIDER_SPEED); // lerp from A to B (arbitrary speed)
from = to; // update point A
stopTime = point["stop"] ? SLIDER_STOP_TICKS : 0;
}
std::rotate(points.rbegin(), points.rbegin() + rotations, points.rend()); // undo rotation
TransportManager::NPCQueues[sliderID] = route;
}
void TableData::constructPathNPC(nlohmann::json::iterator _pathData) {
auto pathData = _pathData.value();
// Interpolate