Merge branch 'develop' into idac
This commit is contained in:
79
titles/idac/templates/js/idac_scripts.js
Normal file
79
titles/idac/templates/js/idac_scripts.js
Normal file
@@ -0,0 +1,79 @@
|
||||
// Declare a global variable to store the JSON data
|
||||
var constData;
|
||||
|
||||
function evaluateRank(evalId) {
|
||||
if (evalId >= 1 && evalId <= 4) {
|
||||
return "Rookie";
|
||||
} else if (evalId >= 5 && evalId <= 8) {
|
||||
return "Regular";
|
||||
} else if (evalId >= 9 && evalId <= 12) {
|
||||
return "Specialist";
|
||||
} else if (evalId >= 13 && evalId <= 16) {
|
||||
return "Expert";
|
||||
} else if (evalId >= 17 && evalId <= 20) {
|
||||
return "Pro";
|
||||
} else if (evalId >= 21 && evalId <= 24) {
|
||||
return "Master";
|
||||
} else if (evalId == 25) {
|
||||
return "Master+";
|
||||
} else {
|
||||
return "Invalid";
|
||||
}
|
||||
}
|
||||
|
||||
function formatGoalTime(milliseconds) {
|
||||
// Convert the milliseconds to a time string
|
||||
var minutes = Math.floor(milliseconds / 60000);
|
||||
var seconds = Math.floor((milliseconds % 60000) / 1000);
|
||||
milliseconds %= 1000;
|
||||
|
||||
return `${parseInt(minutes)}'${seconds.toString().padStart(2, '0')}"${milliseconds.toString().padStart(3, '0')}`;
|
||||
}
|
||||
|
||||
|
||||
// Function to get style_name for a given style_car_id
|
||||
function getCarName(style_car_id) {
|
||||
// Find the car with the matching style_car_id
|
||||
var foundCar = constData.car.find(function (style) {
|
||||
return style.style_car_id === style_car_id;
|
||||
});
|
||||
|
||||
// Return the style_name if found, otherwise return Unknown
|
||||
return foundCar ? foundCar.style_name : "Unknown car";
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// Make an AJAX request to load the JSON file
|
||||
$.ajax({
|
||||
url: "/game/idac/ranking/const.get",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
// Check if the 'course' array exists in the JSON data
|
||||
if (data && data.course) {
|
||||
// Assign the JSON data to the global variable
|
||||
constData = data;
|
||||
|
||||
// Get the select element
|
||||
var selectElement = $("#course-select");
|
||||
|
||||
// Remove the Loading text
|
||||
selectElement.empty();
|
||||
|
||||
// Loop through the 'course' array and add options to the select
|
||||
$.each(constData.course, function (index, course) {
|
||||
var option = '<option value="' + course.course_id + '"' + (index === 0 ? 'selected' : '') + '>' + course.course_name + '</option>';
|
||||
selectElement.append(option);
|
||||
});
|
||||
|
||||
// Simulate a change event on page load with the default value (0)
|
||||
$("#course-select").val("0").change();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
// Print the error message as an option element
|
||||
$("#course-select").html("<option value='0' selected disabled>" + textStatus + "</option>");
|
||||
console.error("Error loading JSON file:", textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user