mirror of
https://github.com/placeAtlas/atlas.git
synced 2025-01-17 01:01:56 +01:00
Added preview button
Added another test entry
This commit is contained in:
parent
2fbd1afa66
commit
5634f58b8d
5 changed files with 7768 additions and 7757 deletions
|
@ -16,14 +16,12 @@ const finishButton = document.getElementById("finishButton");
|
|||
const resetButton = document.getElementById("resetButton");
|
||||
const undoButton = document.getElementById("undoButton");
|
||||
const redoButton = document.getElementById("redoButton");
|
||||
const previewButton = document.getElementById("previewButton");
|
||||
const highlightUnchartedLabel = document.getElementById("highlightUnchartedLabel");
|
||||
let entryId = 0
|
||||
|
||||
const objectInfoBox = document.getElementById("objectInfo");
|
||||
|
||||
var drawControlsBody = document.getElementById("offcanvasDraw-drawControls");
|
||||
var objectInfoBody = document.getElementById("offcanvasDraw-objectInfo");
|
||||
var objectInfoForm = document.getElementById("objectInfo");
|
||||
const drawControlsBody = document.getElementById("offcanvasDraw-drawControls");
|
||||
const objectInfoBody = document.getElementById("offcanvasDraw-objectInfo");
|
||||
const objectInfoForm = document.getElementById("objectInfo");
|
||||
|
||||
const hintText = document.getElementById("hint");
|
||||
|
||||
|
@ -50,6 +48,7 @@ const discordGroup = document.getElementById("discordGroup");
|
|||
const wikiGroup = document.getElementById("wikiGroup");
|
||||
const exportArea = document.getElementById("exportString");
|
||||
|
||||
let entryId = 0;
|
||||
let path = [];
|
||||
let center = [1000, 1000];
|
||||
|
||||
|
@ -219,6 +218,10 @@ function initDraw() {
|
|||
back();
|
||||
});
|
||||
|
||||
previewButton.addEventListener("click", function (e) {
|
||||
preview();
|
||||
});
|
||||
|
||||
// refocus on button when modal is closed
|
||||
exportModalElement.addEventListener('hidden.bs.modal', function() {
|
||||
document.getElementById("exportButton").focus();
|
||||
|
@ -238,7 +241,7 @@ function initDraw() {
|
|||
render(path);
|
||||
});
|
||||
|
||||
function exportJson() {
|
||||
function generateExportObject() {
|
||||
const exportObject = {
|
||||
id: entryId,
|
||||
name: nameField.value,
|
||||
|
@ -253,28 +256,34 @@ function initDraw() {
|
|||
for (let i = pathWithPeriodsTemp.length - 1; i > 0; i--) {
|
||||
for (let j = 0; j < i; j++) {
|
||||
if (JSON.stringify(pathWithPeriodsTemp[i][1]) === JSON.stringify(pathWithPeriodsTemp[j][1])) {
|
||||
pathWithPeriodsTemp[j][0] = pathWithPeriodsTemp[i][0] + ', ' + pathWithPeriodsTemp[j][0]
|
||||
pathWithPeriodsTemp.splice(i, 1)
|
||||
break
|
||||
pathWithPeriodsTemp[j][0] = pathWithPeriodsTemp[i][0] + ', ' + pathWithPeriodsTemp[j][0];
|
||||
pathWithPeriodsTemp.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pathWithPeriodsTemp.forEach(([key, value]) => {
|
||||
// TODO: Compress periods on something like 0-13, 14.
|
||||
exportObject.path[key] = value
|
||||
exportObject.center[key] = calculateCenter(value)
|
||||
exportObject.path[key] = value;
|
||||
exportObject.center[key] = calculateCenter(value);
|
||||
})
|
||||
|
||||
const inputWebsite = websiteGroupElements.map(element => element.value.trim()).filter(element => element);
|
||||
const inputSubreddit = subredditGroupElements.map(element => element.value.trim().replace(/(?:(?:(?:(?:https?:\/\/)?(?:(?:www|old|new|np)\.)?)?reddit\.com)?\/)?[rR]\/([A-Za-z0-9][A-Za-z0-9_]{2,20})(?:\/[^" ]*)*/, '$1')).filter(element => element);
|
||||
const inputSubreddit = subredditGroupElements.map(element => element.value.trim().replace(/(?:(?:(?:(?:https?:\/\/)?(?:(?:www|old|new|np)\.)?)?reddit\.com)?\/)?[rR]\/([A-Za-z0-9][A-Za-z0-9_]{0,20})(?:\/[^" ]*)*/, '$1')).filter(element => element);
|
||||
const inputDiscord = discordGroupElements.map(element => element.value.trim().replace(/(?:https?:\/\/)?(?:www\.)?(?:(?:discord)?\.?gg|discord(?:app?)\.com\/invite)\/([^\s/]+?)(?=\b)/, '$1')).filter(element => element);
|
||||
const inputWiki = wikiGroupElements.map(element => element.value.trim().replace(/ /g, '_')).filter(element => element);
|
||||
|
||||
if (inputWebsite.length) exportObject.links.website = inputWebsite
|
||||
if (inputSubreddit.length) exportObject.links.subreddit = inputSubreddit
|
||||
if (inputDiscord.length) exportObject.links.discord = inputDiscord
|
||||
if (inputWiki.length) exportObject.links.wiki = inputWiki
|
||||
if (inputWebsite.length) exportObject.links.website = inputWebsite;
|
||||
if (inputSubreddit.length) exportObject.links.subreddit = inputSubreddit;
|
||||
if (inputDiscord.length) exportObject.links.discord = inputDiscord;
|
||||
if (inputWiki.length) exportObject.links.wiki = inputWiki;
|
||||
|
||||
return exportObject;
|
||||
}
|
||||
|
||||
function exportJson() {
|
||||
const exportObject = generateExportObject()
|
||||
|
||||
let jsonString = JSON.stringify(exportObject, null, "\t");
|
||||
jsonString = jsonString.split("\n");
|
||||
|
@ -293,6 +302,13 @@ function initDraw() {
|
|||
exportModal.show();
|
||||
}
|
||||
|
||||
function preview() {
|
||||
let infoElement = createInfoBlock(generateExportObject(), true);
|
||||
objectsContainer.replaceChildren();
|
||||
objectsContainer.appendChild(infoElement);
|
||||
closeObjectsListButton.classList.remove("d-none");
|
||||
}
|
||||
|
||||
function undo() {
|
||||
if (path.length > 0 && drawing) {
|
||||
undoHistory.push(path.pop());
|
||||
|
@ -310,7 +326,7 @@ function initDraw() {
|
|||
}
|
||||
|
||||
function finish() {
|
||||
if (objectInfoBox.style.display === "block") return
|
||||
if (objectInfoForm.style.display === "block") return
|
||||
updatePath()
|
||||
drawing = false;
|
||||
disableDrawingOverride = true;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
========================================================================
|
||||
*/
|
||||
|
||||
function createInfoBlock(entry) {
|
||||
function createInfoBlock(entry, isPreview) {
|
||||
function createLabel(name, value, parent) {
|
||||
const nameElement = document.createElement("span");
|
||||
nameElement.className = "fw-bold";
|
||||
|
@ -38,7 +38,8 @@ function createInfoBlock(entry) {
|
|||
headerElement.className = "card-header";
|
||||
const linkElement = document.createElement("a");
|
||||
linkElement.className = "text-decoration-none d-flex justify-content-between text-body";
|
||||
linkElement.href = "#" + entry.id;
|
||||
if (isPreview) linkElement.href = "#";
|
||||
else linkElement.href = "#" + entry.id;
|
||||
const linkNameElement = document.createElement("span");
|
||||
linkNameElement.className = "flex-grow-1 text-break";
|
||||
linkNameElement.textContent = entry.name;
|
||||
|
@ -80,15 +81,17 @@ function createInfoBlock(entry) {
|
|||
listElement.appendChild(diffElement);
|
||||
}
|
||||
|
||||
const [x, y] = entry.center;
|
||||
listElement.appendChild(createInfoListItem("Position: ", `${Math.floor(x)}, ${Math.floor(y)}`));
|
||||
|
||||
if(entry.path){
|
||||
const area = calcPolygonArea(entry.path);
|
||||
listElement.appendChild(createInfoListItem("Area: ", `${area} pixels`));
|
||||
if (!isPreview) {
|
||||
const [x, y] = entry.center;
|
||||
listElement.appendChild(createInfoListItem("Position: ", `${Math.floor(x)}, ${Math.floor(y)}`));
|
||||
|
||||
if(entry.path){
|
||||
const area = calcPolygonArea(entry.path);
|
||||
listElement.appendChild(createInfoListItem("Area: ", `${area} pixels`));
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.links.subreddit.length) {
|
||||
if (entry.links.subreddit) {
|
||||
const subredditGroupElement = document.createElement("div");
|
||||
subredditGroupElement.className = "btn-group-vertical";
|
||||
linkListElement.appendChild(subredditGroupElement);
|
||||
|
@ -107,7 +110,7 @@ function createInfoBlock(entry) {
|
|||
});
|
||||
};
|
||||
|
||||
if (entry.links.website.length) {
|
||||
if (entry.links.website) {
|
||||
const websiteGroupElement = document.createElement("div");
|
||||
websiteGroupElement.className = "btn-group-vertical";
|
||||
linkListElement.appendChild(websiteGroupElement);
|
||||
|
@ -130,7 +133,7 @@ function createInfoBlock(entry) {
|
|||
});
|
||||
}
|
||||
|
||||
if (entry.links.discord.length) {
|
||||
if (entry.links.discord) {
|
||||
const discordGroupElement = document.createElement("div");
|
||||
discordGroupElement.className = "btn-group-vertical";
|
||||
linkListElement.appendChild(discordGroupElement);
|
||||
|
@ -148,7 +151,7 @@ function createInfoBlock(entry) {
|
|||
});
|
||||
}
|
||||
|
||||
if (entry.links.wiki.length) {
|
||||
if (entry.links.wiki) {
|
||||
const wikiGroupElement = document.createElement("div");
|
||||
wikiGroupElement.className = "btn-group-vertical";
|
||||
linkListElement.appendChild(wikiGroupElement);
|
||||
|
@ -175,7 +178,7 @@ function createInfoBlock(entry) {
|
|||
idElementContainer.appendChild(idElement);
|
||||
element.appendChild(idElementContainer);
|
||||
|
||||
if (!entry.diff || entry.diff !== "delete") {
|
||||
if (!isPreview && (!entry.diff || entry.diff !== "delete")) {
|
||||
const editElement = document.createElement("a");
|
||||
editElement.textContent = "Edit";
|
||||
editElement.className = "btn btn-sm btn-outline-primary";
|
||||
|
@ -184,13 +187,9 @@ function createInfoBlock(entry) {
|
|||
idElementContainer.appendChild(editElement);
|
||||
}
|
||||
|
||||
if (!linkListElement.hasChildNodes()) {
|
||||
linkListElement.remove();
|
||||
}
|
||||
|
||||
if (!bodyElement.hasChildNodes()) {
|
||||
bodyElement.remove();
|
||||
}
|
||||
if (!bodyElement.hasChildNodes()) bodyElement.remove();
|
||||
if (!linkListElement.hasChildNodes()) linkListElement.remove();
|
||||
if (!listElement.hasChildNodes()) listElement.remove();
|
||||
|
||||
return element;
|
||||
}
|
|
@ -734,8 +734,6 @@ window.addEventListener("hashchange", highlightEntryFromUrl);
|
|||
|
||||
function highlightEntryFromUrl() {
|
||||
|
||||
const objectsContainer = document.getElementById("objectsList");
|
||||
|
||||
const id = window.location.hash.substring(1); //Remove hash prefix
|
||||
|
||||
const entries = atlas.filter(function (e) {
|
||||
|
|
15418
web/atlas.json
15418
web/atlas.json
File diff suppressed because one or more lines are too long
|
@ -332,18 +332,16 @@
|
|||
</a>
|
||||
</label>
|
||||
<div id="wikiGroup" class="mb-3 d-flex flex-column gap-2"></div>
|
||||
<div id="infoButtons" class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-secondary w-50" id="cancelButton">Back</button>
|
||||
<button type="submit" class="btn btn-primary w-50" id="exportButton">Ok</button>
|
||||
<div id="infoButtons" class="d-flex flex-wrap gap-2">
|
||||
<button type="button" class="btn btn-secondary flex-fill" id="cancelButton">Back</button>
|
||||
<button type="button" class="btn btn-secondary flex-fill" id="previewButton">Preview</button>
|
||||
<button type="submit" class="btn btn-primary flex-fill" id="exportButton">Export</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" id="closeObjectsListButton" class="d-none btn btn-secondary shadow" aria-label="Close">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">
|
||||
<path fill-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z"/>
|
||||
<path fill-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z"/>
|
||||
</svg>
|
||||
<button type="button" id="closeObjectsListButton" class="d-none btn btn-secondary shadow p-0" aria-label="Close">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</button>
|
||||
<div id="objectsList" class="p-2"></div>
|
||||
<span id="objectsListOverflowNotice" class="p-2 me-2 btn-primary rounded text-center d-none">Click the map to lock your selection</span>
|
||||
|
|
Loading…
Add table
Reference in a new issue