WIP
This commit is contained in:
parent
05ffe52ef7
commit
b1921b2dbb
@ -9,35 +9,19 @@
|
|||||||
|
|
||||||
const BDC_KEY = "067c718d2bbd4a2ba8d0645e1633cac2";
|
const BDC_KEY = "067c718d2bbd4a2ba8d0645e1633cac2";
|
||||||
|
|
||||||
class GameHelper {
|
async function fetchSeed(id) {
|
||||||
/**
|
|
||||||
* Fetch a game seed
|
|
||||||
* @param {string} id
|
|
||||||
* @return {Promise} Seed Promise
|
|
||||||
*/
|
|
||||||
static async fetchSeed(id) {
|
|
||||||
return axios
|
return axios
|
||||||
.get(`https://www.geoguessr.com/api/v3/games/${id}`)
|
.get(`https://www.geoguessr.com/api/v3/games/${id}`)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch((error) => console.log(error));
|
.catch((error) => console.log(error));
|
||||||
};
|
};
|
||||||
|
async function getCountryBDC(location) {
|
||||||
static async getCountryBDC(location) {
|
|
||||||
return axios
|
return axios
|
||||||
.get(`https://api.bigdatacloud.net/data/reverse-geocode?latitude=${location.lat}&longitude=${location.lng}&key=${BDC_KEY}`)
|
.get(`https://api.bigdatacloud.net/data/reverse-geocode?latitude=${location.lat}&longitude=${location.lng}&key=${BDC_KEY}`)
|
||||||
.then((res) => countryCodes[res.data.countryCode])
|
.then((res) => countryCodes[res.data.countryCode])
|
||||||
.catch((error) => error);
|
.catch((error) => error);
|
||||||
};
|
};
|
||||||
|
function getSurroundings (location) {
|
||||||
/**
|
|
||||||
* Returns an array of 9 coodinates as objects.
|
|
||||||
* Each coordinate is 100 meters aways from the given
|
|
||||||
* coordinate y angles from 0 to 315
|
|
||||||
* The first coordinate is the original passed
|
|
||||||
* @param {Object} location {lat, lng}
|
|
||||||
* @return {Array} Coordinates [{lat, lng}, {lat, lng}] x 8
|
|
||||||
*/
|
|
||||||
static getSurroundings (location) {
|
|
||||||
const meters = 100;
|
const meters = 100;
|
||||||
const R_EARTH = 6378.137;
|
const R_EARTH = 6378.137;
|
||||||
const M = 1 / (((2 * Math.PI) / 360) * R_EARTH) / 1000;
|
const M = 1 / (((2 * Math.PI) / 360) * R_EARTH) / 1000;
|
||||||
@ -57,32 +41,16 @@ class GameHelper {
|
|||||||
return coordinates;
|
return coordinates;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
function isCoordinates (coordinates) {
|
||||||
* Check if the param is coordinates
|
|
||||||
* @param {string} coordinates
|
|
||||||
* @return {boolean}
|
|
||||||
*/
|
|
||||||
static isCoordinates (coordinates) {
|
|
||||||
const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g;
|
const regex = /^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g;
|
||||||
return regex.test(coordinates);
|
return regex.test(coordinates);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
function calculateScale(bounds){
|
||||||
* Returns map scale
|
return haversineDistance({ lat: bounds.min.lat, lng: bounds.min.lng }, { lat: bounds.max.lat, lng: bounds.max.lng }) / 7.458421;
|
||||||
* @param {Object} bounds map bounds
|
|
||||||
* @return {number} map scale
|
|
||||||
*/
|
|
||||||
static calculateScale(bounds){
|
|
||||||
return GameHelper.haversineDistance({ lat: bounds.min.lat, lng: bounds.min.lng }, { lat: bounds.max.lat, lng: bounds.max.lng }) / 7.458421;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function haversineDistance(mk1, mk2){
|
||||||
* Returns distance in km between two coordinates
|
|
||||||
* @param {Object} mk1 {lat, lng}
|
|
||||||
* @param {Object} mk2 {lat, lng}
|
|
||||||
* @return {number} km
|
|
||||||
*/
|
|
||||||
static haversineDistance(mk1, mk2){
|
|
||||||
const R = 6371.071;
|
const R = 6371.071;
|
||||||
const rlat1 = mk1.lat * (Math.PI / 180);
|
const rlat1 = mk1.lat * (Math.PI / 180);
|
||||||
const rlat2 = mk2.lat * (Math.PI / 180);
|
const rlat2 = mk2.lat * (Math.PI / 180);
|
||||||
@ -95,52 +63,22 @@ class GameHelper {
|
|||||||
return km;
|
return km;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
function calculateScore(distance, scale){
|
||||||
* Returns score based on distance and scale
|
|
||||||
* @param {number} distance
|
|
||||||
* @param {number} scale
|
|
||||||
* @return {number} score
|
|
||||||
*/
|
|
||||||
static calculateScore(distance, scale){
|
|
||||||
return Math.round(5000 * Math.pow(0.99866017, (distance * 1000) / scale));
|
return Math.round(5000 * Math.pow(0.99866017, (distance * 1000) / scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Replace special chars
|
function normalize(val){
|
||||||
* @param {String} val
|
|
||||||
*/
|
|
||||||
static normalize(val){
|
|
||||||
return val.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
return val.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Matches words above 3 letters
|
function isMatch(input, key){
|
||||||
* @param {String} input
|
|
||||||
* @param {String} key
|
|
||||||
*/
|
|
||||||
static isMatch(input, key){
|
|
||||||
return input.length >= 3 && key.includes(input) && input.length <= key.length;
|
return input.length >= 3 && key.includes(input) && input.length <= key.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find country by code or name
|
function findCountry(input){
|
||||||
* @param {String} input
|
|
||||||
* @return {Object} countryCodesNames
|
|
||||||
*/
|
|
||||||
static findCountry(input){
|
|
||||||
const normalized = GameHelper.normalize(input);
|
const normalized = GameHelper.normalize(input);
|
||||||
return countryCodesNames.find((country) => country.code === normalized || GameHelper.isMatch(normalized, country.names.toLowerCase()));
|
return countryCodesNames.find((country) => country.code === normalized || GameHelper.isMatch(normalized, country.names.toLowerCase()));
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var isOpen = $.getSetIniDbBoolean('chatguessr', 'isOpen', false),
|
var isOpen = $.getSetIniDbBoolean('chatguessr', 'isOpen', false),
|
||||||
seed = {},
|
seed = {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user