Add world coordinate export for burgs with improved unit conversion

- Added X_World and Y_World columns in meters to CSV export
- Enhanced distance unit conversion with support for multiple units (km, m, mi, yd, ft, leagues)
- Renamed existing X,Y columns to X_Pixel, Y_Pixel for clarity
- World coordinates account for proper Y-axis orientation (negative for downward direction)
- Maintains backward compatibility with existing latitude/longitude columns
This commit is contained in:
barrulus 2025-08-12 18:30:21 +01:00
parent bcce33e046
commit 51572e34a8

View file

@ -480,49 +480,100 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
}); });
} }
function downloadBurgsData() { // Helper function to get meters per pixel (add this if it doesn't exist)
let data = `Id,Burg,Province,Province Full Name,State,State Full Name,Culture,Religion,Population,X,Y,Latitude,Longitude,Elevation (${heightUnit.value}),Temperature,Temperature likeness,Capital,Port,Citadel,Walls,Plaza,Temple,Shanty Town,Emblem,City Generator Link\n`; // headers function getMetersPerPixel() {
const valid = pack.burgs.filter(b => b.i && !b.removed); // all valid burgs const unit = distanceUnitInput.value.toLowerCase();
valid.forEach(b => { switch(unit) {
data += b.i + ","; case 'km':
data += b.name + ","; return distanceScale * 1000;
const province = pack.cells.province[b.cell]; case 'm':
data += province ? pack.provinces[province].name + "," : ","; case 'meter':
data += province ? pack.provinces[province].fullName + "," : ","; case 'meters':
data += pack.states[b.state].name + ","; return distanceScale;
data += pack.states[b.state].fullName + ","; case 'mi':
data += pack.cultures[b.culture].name + ","; case 'mile':
data += pack.religions[pack.cells.religion[b.cell]].name + ","; case 'miles':
data += rn(b.population * populationRate * urbanization) + ","; return distanceScale * 1609.344;
case 'yd':
// add geography data case 'yard':
data += b.x + ","; case 'yards':
data += b.y + ","; return distanceScale * 0.9144;
data += getLatitude(b.y, 2) + ","; case 'ft':
data += getLongitude(b.x, 2) + ","; case 'foot':
data += parseInt(getHeight(pack.cells.h[b.cell])) + ","; case 'feet':
const temperature = grid.cells.temp[pack.cells.g[b.cell]]; return distanceScale * 0.3048;
data += convertTemperature(temperature) + ","; case 'league':
data += getTemperatureLikeness(temperature) + ","; case 'leagues':
return distanceScale * 4828.032;
// add status data default:
data += b.capital ? "capital," : ","; console.warn(`Unknown distance unit: ${unit}, defaulting to km`);
data += b.port ? "port," : ","; return distanceScale * 1000;
data += b.citadel ? "citadel," : ",";
data += b.walls ? "walls," : ",";
data += b.plaza ? "plaza," : ",";
data += b.temple ? "temple," : ",";
data += b.shanty ? "shanty town," : ",";
data += b.coa ? JSON.stringify(b.coa).replace(/"/g, "").replace(/,/g, ";") + "," : ",";
data += getBurgLink(b);
data += "\n";
});
const name = getFileName("Burgs") + ".csv";
downloadFile(data, name);
} }
}
function downloadBurgsData() {
// Calculate meters per pixel for world coordinates
const metersPerPixel = getMetersPerPixel();
// Build headers with new world coordinate columns
let data = `Id,Burg,Province,Province Full Name,State,State Full Name,Culture,Religion,Population,`;
data += `X_World (m),Y_World (m),X_Pixel,Y_Pixel,`; // New world coords + renamed pixel coords
data += `Latitude,Longitude,`; // Keep for compatibility
data += `Elevation (${heightUnit.value}),Temperature,Temperature likeness,`;
data += `Capital,Port,Citadel,Walls,Plaza,Temple,Shanty Town,Emblem,City Generator Link\n`;
const valid = pack.burgs.filter(b => b.i && !b.removed); // all valid burgs
valid.forEach(b => {
data += b.i + ",";
data += b.name + ",";
const province = pack.cells.province[b.cell];
data += province ? pack.provinces[province].name + "," : ",";
data += province ? pack.provinces[province].fullName + "," : ",";
data += pack.states[b.state].name + ",";
data += pack.states[b.state].fullName + ",";
data += pack.cultures[b.culture].name + ",";
data += pack.religions[pack.cells.religion[b.cell]].name + ",";
data += rn(b.population * populationRate * urbanization) + ",";
// Add world coordinates in meters
const xWorld = b.x * metersPerPixel;
const yWorld = -b.y * metersPerPixel; // Negative because Y increases downward
data += rn(xWorld, 2) + ",";
data += rn(yWorld, 2) + ",";
// Add pixel coordinates (renamed for clarity)
data += b.x + ",";
data += b.y + ",";
// Keep lat/lon for compatibility (even though not used in fantasy map)
data += getLatitude(b.y, 2) + ",";
data += getLongitude(b.x, 2) + ",";
// Continue with elevation and other data
data += parseInt(getHeight(pack.cells.h[b.cell])) + ",";
const temperature = grid.cells.temp[pack.cells.g[b.cell]];
data += convertTemperature(temperature) + ",";
data += getTemperatureLikeness(temperature) + ",";
// Add status data
data += b.capital ? "capital," : ",";
data += b.port ? "port," : ",";
data += b.citadel ? "citadel," : ",";
data += b.walls ? "walls," : ",";
data += b.plaza ? "plaza," : ",";
data += b.temple ? "temple," : ",";
data += b.shanty ? "shanty town," : ",";
data += b.coa ? JSON.stringify(b.coa).replace(/"/g, "").replace(/,/g, ";") + "," : ",";
data += getBurgLink(b);
data += "\n";
});
const name = getFileName("Burgs") + ".csv";
downloadFile(data, name);
}
function renameBurgsInBulk() { function renameBurgsInBulk() {
alertMessage.innerHTML = /* html */ `Download burgs list as a text file, make changes and re-upload the file. Make sure the file is a plain text document with each alertMessage.innerHTML = /* html */ `Download burgs list as a text file, make changes and re-upload the file. Make sure the file is a plain text document with each