2017-04-04 01:24:46 +02:00
|
|
|
/*
|
|
|
|
========================================================================
|
2022-04-28 12:41:19 +02:00
|
|
|
The 2022 r/place Atlas
|
2022-04-09 04:45:47 +02:00
|
|
|
|
2022-04-28 12:41:19 +02:00
|
|
|
An Atlas of Reddit's 2022 r/place, with information to each
|
2017-04-04 01:24:46 +02:00
|
|
|
artwork of the canvas provided by the community.
|
2022-04-09 04:45:47 +02:00
|
|
|
|
|
|
|
Copyright (c) 2017 Roland Rytz <roland@draemm.li>
|
2022-04-23 15:30:48 +02:00
|
|
|
Copyright (c) 2022 Place Atlas contributors
|
2022-04-09 04:45:47 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
Licensed under the GNU Affero General Public License Version 3
|
2022-04-09 03:23:55 +02:00
|
|
|
https://place-atlas.stefanocoding.me/license.txt
|
2017-04-04 01:24:46 +02:00
|
|
|
========================================================================
|
|
|
|
*/
|
2022-04-16 14:44:50 +02:00
|
|
|
const finishButton = document.getElementById("finishButton");
|
|
|
|
const resetButton = document.getElementById("resetButton");
|
|
|
|
const undoButton = document.getElementById("undoButton");
|
|
|
|
const redoButton = document.getElementById("redoButton");
|
|
|
|
const highlightUnchartedLabel = document.getElementById("highlightUnchartedLabel");
|
|
|
|
let entryId = 0
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const objectInfoBox = document.getElementById("objectInfo");
|
2022-04-22 02:33:30 +02:00
|
|
|
|
|
|
|
var drawControlsBody = document.getElementById("offcanvasDraw-drawControls");
|
|
|
|
var objectInfoBody = document.getElementById("offcanvasDraw-objectInfo");
|
|
|
|
var objectInfoForm = document.getElementById("objectInfo");
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const hintText = document.getElementById("hint");
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
const periodsStatus = document.getElementById('periodsStatus');
|
|
|
|
const periodGroups = document.getElementById('periodGroups');
|
|
|
|
const periodGroupTemplate = document.getElementById('period-group').content.firstElementChild.cloneNode(true);
|
|
|
|
const periodsAdd = document.getElementById('periodsAdd');
|
2022-04-14 09:56:30 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const exportButton = document.getElementById("exportButton");
|
|
|
|
const cancelButton = document.getElementById("cancelButton");
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
const exportModal = new bootstrap.Modal(document.getElementById("exportModal"));
|
|
|
|
const exportModalElement = document.getElementById("exportModal");
|
2022-04-22 02:33:30 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const exportOverlay = document.getElementById("exportOverlay");
|
|
|
|
const exportCloseButton = document.getElementById("exportCloseButton");
|
2022-04-23 03:20:59 +02:00
|
|
|
const exportBackButton = document.getElementById("exportBackButton");
|
|
|
|
|
|
|
|
const nameField = document.getElementById("nameField");
|
|
|
|
const descriptionField = document.getElementById("descriptionField");
|
|
|
|
const websiteGroup = document.getElementById("websiteGroup");
|
|
|
|
const subredditGroup = document.getElementById("subredditGroup");
|
|
|
|
const discordGroup = document.getElementById("discordGroup");
|
|
|
|
const wikiGroup = document.getElementById("wikiGroup");
|
2022-04-17 08:08:30 +02:00
|
|
|
const exportArea = document.getElementById("exportString");
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
let path = [];
|
|
|
|
let center = [1000, 1000];
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
let websiteGroupElements = [];
|
|
|
|
let subredditGroupElements = [];
|
|
|
|
let discordGroupElements = [];
|
|
|
|
let wikiGroupElements = [];
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
let pathWithPeriods = [];
|
|
|
|
let periodGroupElements = [];
|
|
|
|
|
|
|
|
let disableDrawingOverride = false;
|
2022-04-16 14:44:50 +02:00
|
|
|
let drawing = true;
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-17 09:10:06 +02:00
|
|
|
let undoHistory = [];
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const periodClipboard = {
|
2022-04-16 12:56:03 +02:00
|
|
|
"index": null,
|
|
|
|
"path": null
|
|
|
|
}
|
|
|
|
|
2022-04-22 08:10:03 +02:00
|
|
|
;[...document.querySelectorAll("#objectInfo textarea")].forEach(el => {
|
2022-04-16 14:44:50 +02:00
|
|
|
el.addEventListener("input", function () {
|
|
|
|
this.style.height = "auto";
|
|
|
|
this.style.height = (this.scrollHeight) + "px"
|
|
|
|
})
|
2022-04-15 09:24:08 +02:00
|
|
|
})
|
|
|
|
|
2022-04-17 09:10:06 +02:00
|
|
|
window.initDraw = initDraw
|
2022-04-16 14:44:50 +02:00
|
|
|
function initDraw() {
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-09 11:27:14 +02:00
|
|
|
wrapper.classList.remove('listHidden')
|
|
|
|
|
2022-04-20 10:54:58 +02:00
|
|
|
var backButton = document.getElementById("showListButton");
|
2022-04-28 11:44:46 +02:00
|
|
|
backButton.insertAdjacentHTML("afterend", '<button class="btn btn-outline-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDraw" aria-controls="offcanvasDraw">Menu</button><a id="drawBackButton" class="btn btn-outline-primary" href="./">Exit Draw Mode</a>');
|
2022-04-21 09:25:05 +02:00
|
|
|
backButton.remove();
|
2022-04-20 10:54:58 +02:00
|
|
|
|
|
|
|
var myOffcanvas = document.getElementById("offcanvasDraw");
|
|
|
|
var bsOffcanvas = new bootstrap.Offcanvas(myOffcanvas);
|
|
|
|
bsOffcanvas.show();
|
|
|
|
|
2022-04-09 11:27:14 +02:00
|
|
|
window.render = render
|
|
|
|
window.renderBackground = renderBackground
|
|
|
|
window.updateHovering = updateHovering
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
// let startPeriodField = document.getElementById('startPeriodField')
|
|
|
|
// let endPeriodField = document.getElementById('endPeriodField')
|
|
|
|
// let periodVisbilityInfo = document.getElementById('periodVisbilityInfo')
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
let rShiftPressed = false;
|
|
|
|
let lShiftPressed = false;
|
|
|
|
let shiftPressed = false;
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
let highlightUncharted = true;
|
2017-04-05 03:47:36 +02:00
|
|
|
|
|
|
|
renderBackground();
|
2022-04-09 11:27:14 +02:00
|
|
|
applyView();
|
2017-04-05 03:47:36 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
container.style.cursor = "crosshair";
|
|
|
|
|
|
|
|
render(path);
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
container.addEventListener("mousedown", function (e) {
|
2017-04-04 01:24:46 +02:00
|
|
|
lastPos = [
|
2022-04-16 14:44:50 +02:00
|
|
|
e.clientX,
|
2022-04-09 16:07:01 +02:00
|
|
|
e.clientY
|
2017-04-04 01:24:46 +02:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function getCanvasCoords(x, y) {
|
2017-04-06 19:15:16 +02:00
|
|
|
x = x - container.offsetLeft;
|
|
|
|
y = y - container.offsetTop;
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const pos = [
|
|
|
|
~~((x - (container.clientWidth / 2 - innerContainer.clientWidth / 2 + zoomOrigin[0])) / zoom) + 0.5,
|
|
|
|
~~((y - (container.clientHeight / 2 - innerContainer.clientHeight / 2 + zoomOrigin[1])) / zoom) + 0.5
|
2017-04-06 19:15:16 +02:00
|
|
|
];
|
2022-04-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (shiftPressed && path.length > 0) {
|
|
|
|
const previous = path[path.length - 1];
|
|
|
|
|
|
|
|
if (Math.abs(pos[1] - previous[1]) > Math.abs(pos[0] - previous[0])) {
|
2017-04-06 19:15:16 +02:00
|
|
|
pos[0] = previous[0];
|
|
|
|
} else {
|
|
|
|
pos[1] = previous[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
container.addEventListener("mouseup", function (e) {
|
|
|
|
|
2017-04-06 19:15:16 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (Math.abs(lastPos[0] - e.clientX) + Math.abs(lastPos[1] - e.clientY) <= 4 && drawing) {
|
2017-04-06 19:15:16 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const coords = getCanvasCoords(e.clientX, e.clientY);
|
2017-04-06 19:15:16 +02:00
|
|
|
|
|
|
|
path.push(coords);
|
|
|
|
render(path);
|
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
undoHistory = [];
|
|
|
|
redoButton.disabled = true;
|
|
|
|
undoButton.disabled = false;
|
2017-04-06 19:15:16 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (path.length >= 3) {
|
2017-04-04 01:24:46 +02:00
|
|
|
finishButton.disabled = false;
|
|
|
|
}
|
2022-04-14 19:06:13 +02:00
|
|
|
|
|
|
|
updatePath()
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
window.addEventListener("mousemove", function (e) {
|
2022-04-09 11:27:14 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (!dragging && drawing && path.length > 0) {
|
2022-04-09 11:27:14 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const coords = getCanvasCoords(e.clientX, e.clientY);
|
2017-04-06 19:15:16 +02:00
|
|
|
render(path.concat([coords]));
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener("keyup", function(e){
|
2022-04-20 10:54:58 +02:00
|
|
|
if (e.key == "z" && e.ctrlKey){
|
2017-04-04 01:24:46 +02:00
|
|
|
undo();
|
2022-04-16 14:44:50 +02:00
|
|
|
} else if (e.key == "y" && e.ctrlKey) {
|
2017-04-04 01:24:46 +02:00
|
|
|
redo();
|
2017-04-04 12:13:23 +02:00
|
|
|
} else if (e.key === "Shift" ){
|
2017-04-06 19:15:16 +02:00
|
|
|
if(e.code === "ShiftRight"){
|
|
|
|
rShiftPressed = false;
|
2022-04-16 14:44:50 +02:00
|
|
|
} else if (e.code === "ShiftLeft") {
|
2017-04-06 19:15:16 +02:00
|
|
|
lShiftPressed = false;
|
|
|
|
}
|
|
|
|
shiftPressed = rShiftPressed || lShiftPressed;
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2022-04-22 02:33:30 +02:00
|
|
|
window.addEventListener("keydown", function(e) {
|
2022-04-16 14:44:50 +02:00
|
|
|
if (e.key === "Shift") {
|
|
|
|
if (e.code === "ShiftRight") {
|
2017-04-06 19:15:16 +02:00
|
|
|
rShiftPressed = true;
|
2022-04-16 14:44:50 +02:00
|
|
|
} else if (e.code === "ShiftLeft") {
|
2017-04-06 19:15:16 +02:00
|
|
|
lShiftPressed = true;
|
|
|
|
}
|
|
|
|
shiftPressed = rShiftPressed || lShiftPressed;
|
|
|
|
}
|
|
|
|
});
|
2017-04-04 12:13:23 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
finishButton.addEventListener("click", function (e) {
|
2017-04-04 01:24:46 +02:00
|
|
|
finish();
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
undoButton.addEventListener("click", function (e) {
|
2017-04-04 01:24:46 +02:00
|
|
|
undo();
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
redoButton.addEventListener("click", function (e) {
|
2017-04-04 01:24:46 +02:00
|
|
|
redo();
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
resetButton.addEventListener("click", function (e) {
|
2017-04-04 01:24:46 +02:00
|
|
|
reset();
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
cancelButton.addEventListener("click", function (e) {
|
2022-04-09 16:07:01 +02:00
|
|
|
back();
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2022-04-20 10:54:58 +02:00
|
|
|
// refocus on button when modal is closed
|
|
|
|
exportModalElement.addEventListener('hidden.bs.modal', function() {
|
|
|
|
document.getElementById("exportButton").focus();
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2022-04-22 02:33:30 +02:00
|
|
|
exportModalElement.addEventListener('shown.bs.modal', function() {
|
|
|
|
document.getElementById("exportButton").focus();
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2022-04-20 10:54:58 +02:00
|
|
|
objectInfoForm.addEventListener('submit', function(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
exportJson()
|
2017-04-04 01:24:46 +02:00
|
|
|
});
|
|
|
|
|
2017-04-05 03:47:36 +02:00
|
|
|
document.getElementById("highlightUncharted").addEventListener("click", function(e){
|
|
|
|
highlightUncharted = this.checked;
|
|
|
|
render(path);
|
|
|
|
});
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function exportJson() {
|
|
|
|
const exportObject = {
|
2022-04-09 16:07:01 +02:00
|
|
|
id: entryId,
|
2022-04-17 08:08:30 +02:00
|
|
|
name: nameField.value,
|
|
|
|
description: descriptionField.value,
|
2022-04-15 05:46:27 +02:00
|
|
|
links: {},
|
2022-04-14 16:03:17 +02:00
|
|
|
center: {},
|
|
|
|
path: {},
|
2017-04-04 01:24:46 +02:00
|
|
|
};
|
|
|
|
|
2022-04-17 09:10:06 +02:00
|
|
|
const pathWithPeriodsTemp = pathWithPeriods.concat()
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-14 16:03:17 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 11:11:34 +02:00
|
|
|
}
|
2022-04-14 16:03:17 +02:00
|
|
|
|
|
|
|
pathWithPeriodsTemp.forEach(([key, value]) => {
|
|
|
|
// TODO: Compress periods on something like 0-13, 14.
|
|
|
|
exportObject.path[key] = value
|
|
|
|
exportObject.center[key] = calculateCenter(value)
|
|
|
|
})
|
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
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 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);
|
2022-04-15 05:46:27 +02:00
|
|
|
|
|
|
|
if (inputWebsite.length) exportObject.links.website = inputWebsite
|
|
|
|
if (inputSubreddit.length) exportObject.links.subreddit = inputSubreddit
|
2022-04-17 08:08:30 +02:00
|
|
|
if (inputDiscord.length) exportObject.links.discord = inputDiscord
|
|
|
|
if (inputWiki.length) exportObject.links.wiki = inputWiki
|
2022-04-15 05:46:27 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
let jsonString = JSON.stringify(exportObject, null, "\t");
|
2017-04-04 01:24:46 +02:00
|
|
|
jsonString = jsonString.split("\n");
|
|
|
|
jsonString = jsonString.join("\n ");
|
2022-04-16 14:44:50 +02:00
|
|
|
jsonString = " " + jsonString;
|
2022-04-17 08:08:30 +02:00
|
|
|
exportArea.value = jsonString;
|
|
|
|
let directPostUrl = "https://www.reddit.com/r/placeAtlas2/submit?selftext=true&title=New%20Submission&text=" + encodeURIComponent(exportArea.value);
|
2022-04-09 16:07:01 +02:00
|
|
|
if (jsonString.length > 7493) {
|
2022-04-16 14:44:50 +02:00
|
|
|
directPostUrl = "https://www.reddit.com/r/placeAtlas2/submit?selftext=true&title=New%20Submission&text=" + encodeURIComponent(" " + JSON.stringify(exportObject));
|
2022-04-09 21:04:08 +02:00
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
document.getElementById("exportDirectPost").href = directPostUrl;
|
2022-04-09 21:04:08 +02:00
|
|
|
|
2022-04-26 08:58:07 +02:00
|
|
|
if (entryId == 0) document.getElementById("redditFlair").textContent = "New Entry";
|
|
|
|
else document.getElementById("redditFlair").textContent = "Edit Entry";
|
|
|
|
|
2022-04-22 02:33:30 +02:00
|
|
|
exportModal.show();
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function undo() {
|
|
|
|
if (path.length > 0 && drawing) {
|
2017-04-04 01:24:46 +02:00
|
|
|
undoHistory.push(path.pop());
|
|
|
|
redoButton.disabled = false;
|
2022-04-14 09:56:30 +02:00
|
|
|
updatePath()
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function redo() {
|
|
|
|
if (undoHistory.length > 0 && drawing) {
|
2017-04-04 01:24:46 +02:00
|
|
|
path.push(undoHistory.pop());
|
|
|
|
undoButton.disabled = false;
|
2022-04-14 09:56:30 +02:00
|
|
|
updatePath()
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function finish() {
|
2022-04-15 09:24:08 +02:00
|
|
|
if (objectInfoBox.style.display === "block") return
|
2022-04-14 09:56:30 +02:00
|
|
|
updatePath()
|
2017-04-04 01:24:46 +02:00
|
|
|
drawing = false;
|
2022-04-14 10:37:29 +02:00
|
|
|
disableDrawingOverride = true;
|
2022-04-22 02:33:30 +02:00
|
|
|
objectInfoBody.removeAttribute("style");
|
|
|
|
drawControlsBody.style.display = "none";
|
2022-04-22 08:10:03 +02:00
|
|
|
[...document.querySelectorAll("#objectInfo textarea")].forEach(el => {
|
2022-04-15 09:24:08 +02:00
|
|
|
if (el.value) el.style.height = (el.scrollHeight) + "px"
|
2022-04-16 14:44:50 +02:00
|
|
|
})
|
2022-04-14 08:41:13 +02:00
|
|
|
// if (isOnPeriod()) {
|
|
|
|
// periodVisbilityInfo.textContent = ""
|
|
|
|
// } else {
|
|
|
|
// periodVisbilityInfo.textContent = "Not visible during this period!"
|
|
|
|
// }
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function reset() {
|
2022-04-24 09:51:41 +02:00
|
|
|
// Requires button to be pressed twice to confirm reset
|
|
|
|
if (resetButton.textContent == "Confirm Reset") {
|
|
|
|
resetButton.textContent = "Reset";
|
|
|
|
resetButton.className = "btn btn-secondary";
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-24 09:51:41 +02:00
|
|
|
updatePath([])
|
|
|
|
undoHistory = [];
|
|
|
|
drawing = true;
|
|
|
|
disableDrawingOverride = false;
|
|
|
|
objectInfoBody.style.display = "none";
|
|
|
|
drawControlsBody.removeAttribute("style");
|
|
|
|
|
|
|
|
// Blanks input values
|
|
|
|
nameField.value = "";
|
|
|
|
descriptionField.value = "";
|
|
|
|
|
|
|
|
// Clears input array
|
|
|
|
websiteGroupElements = [];
|
|
|
|
subredditGroupElements = [];
|
|
|
|
discordGroupElements = [];
|
|
|
|
wikiGroupElements = [];
|
|
|
|
|
|
|
|
// Rebuilds multi-input list
|
|
|
|
websiteGroup.replaceChildren();
|
|
|
|
subredditGroup.replaceChildren();
|
|
|
|
discordGroup.replaceChildren();
|
|
|
|
wikiGroup.replaceChildren();
|
|
|
|
addWebsiteFields("", 0, [0]);
|
|
|
|
addSubredditFields("", 0, [0]);
|
|
|
|
addDiscordFields("", 0, [0]);
|
|
|
|
addWikiFields("", 0, [0]);
|
2022-04-26 01:56:23 +02:00
|
|
|
|
|
|
|
// Resets periods
|
|
|
|
pathWithPeriods = []
|
|
|
|
pathWithPeriods.push([defaultPeriod, []])
|
|
|
|
initPeriodGroups()
|
2022-04-24 09:51:41 +02:00
|
|
|
} else {
|
|
|
|
resetButton.textContent = "Confirm Reset";
|
|
|
|
resetButton.className = "btn btn-danger";
|
|
|
|
}
|
|
|
|
}
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function back() {
|
2022-04-09 16:07:01 +02:00
|
|
|
drawing = true;
|
2022-04-14 10:37:29 +02:00
|
|
|
disableDrawingOverride = false;
|
2022-04-14 09:56:30 +02:00
|
|
|
updatePath()
|
2022-04-22 02:33:30 +02:00
|
|
|
objectInfoBody.style.display = "none";
|
|
|
|
drawControlsBody.removeAttribute("style");
|
2022-04-24 09:51:41 +02:00
|
|
|
resetButton.textContent = "Reset";
|
|
|
|
resetButton.className = "btn btn-secondary";
|
2022-04-09 16:07:01 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function renderBackground() {
|
2017-04-05 03:47:36 +02:00
|
|
|
|
|
|
|
backgroundContext.clearRect(0, 0, canvas.width, canvas.height);
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-05 04:01:24 +02:00
|
|
|
backgroundContext.fillStyle = "rgba(0, 0, 0, 1)";
|
2017-04-05 03:47:36 +02:00
|
|
|
//backgroundContext.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
for (let i = 0; i < atlas.length; i++) {
|
|
|
|
|
|
|
|
const path = atlas[i].path;
|
|
|
|
|
2017-04-05 03:47:36 +02:00
|
|
|
backgroundContext.beginPath();
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (path[0]) {
|
2017-04-05 03:47:36 +02:00
|
|
|
backgroundContext.moveTo(path[0][0], path[0][1]);
|
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
|
|
|
for (let p = 1; p < path.length; p++) {
|
2017-04-05 03:47:36 +02:00
|
|
|
backgroundContext.lineTo(path[p][0], path[p][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
backgroundContext.closePath();
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-05 03:47:36 +02:00
|
|
|
backgroundContext.fill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function render(path) {
|
2017-04-04 01:24:46 +02:00
|
|
|
|
2022-04-17 07:37:31 +02:00
|
|
|
if (!Array.isArray(path)) return
|
2017-04-04 01:24:46 +02:00
|
|
|
|
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
2022-04-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (highlightUncharted) {
|
2017-04-05 03:47:36 +02:00
|
|
|
context.drawImage(backgroundCanvas, 0, 0);
|
|
|
|
context.fillStyle = "rgba(0, 0, 0, 0.4)";
|
|
|
|
} else {
|
|
|
|
context.fillStyle = "rgba(0, 0, 0, 0.6)";
|
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
|
|
|
context.beginPath();
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (path[0]) {
|
2017-04-04 01:24:46 +02:00
|
|
|
context.moveTo(path[0][0], path[0][1]);
|
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
|
|
|
for (let i = 1; i < path.length; i++) {
|
2017-04-04 01:24:46 +02:00
|
|
|
context.lineTo(path[i][0], path[i][1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
context.closePath();
|
|
|
|
|
|
|
|
context.strokeStyle = "rgba(255, 255, 255, 1)";
|
|
|
|
context.stroke();
|
|
|
|
|
|
|
|
context.globalCompositeOperation = "destination-out";
|
|
|
|
|
|
|
|
context.fillStyle = "rgba(0, 0, 0, 1)";
|
|
|
|
context.fill();
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
|
|
|
function updateHovering(e, tapped) {
|
|
|
|
if (!dragging && (!fixed || tapped)) {
|
|
|
|
const pos = [
|
|
|
|
(e.clientX - (container.clientWidth / 2 - innerContainer.clientWidth / 2 + zoomOrigin[0] + container.offsetLeft)) / zoom
|
|
|
|
, (e.clientY - (container.clientHeight / 2 - innerContainer.clientHeight / 2 + zoomOrigin[1] + container.offsetTop)) / zoom
|
2022-04-09 11:27:14 +02:00
|
|
|
];
|
2022-04-22 02:33:30 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
const coords_p = document.getElementById("coords_p");
|
2022-04-20 10:54:58 +02:00
|
|
|
|
|
|
|
// Displays coordinates as zero instead of NaN
|
|
|
|
if (isNaN(pos[0]) == true) {
|
|
|
|
coords_p.innerText = "0, 0";
|
|
|
|
} else {
|
|
|
|
coords_p.innerText = Math.ceil(pos[0]) + ", " + Math.ceil(pos[1]);
|
|
|
|
}
|
2022-04-09 11:27:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-09 16:07:01 +02:00
|
|
|
const getEntry = id => {
|
2022-04-15 09:24:08 +02:00
|
|
|
const entries = atlasAll.filter(entry => entry.id === id)
|
2022-04-09 16:07:01 +02:00
|
|
|
if (entries.length === 1) return entries[0]
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:26:31 +02:00
|
|
|
const params = new URLSearchParams(document.location.search)
|
2022-04-09 16:07:01 +02:00
|
|
|
|
2022-04-23 03:20:59 +02:00
|
|
|
|
|
|
|
function addFieldButton(inputButton, inputGroup, array, index, name) {
|
|
|
|
console.log("add button fired");
|
|
|
|
if (inputButton.title == "Remove " + name) {
|
|
|
|
console.log("add (now remove) button fired");
|
|
|
|
removeFieldButton(inputGroup, array, index);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inputButton.className = "btn btn-outline-secondary";
|
|
|
|
inputButton.title = "Remove " + name;
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-trash-fill"></i>';
|
|
|
|
console.log(array);
|
|
|
|
if (name == "website") {
|
|
|
|
addWebsiteFields(null, array.length, array);
|
|
|
|
} else if (name == "subreddit") {
|
|
|
|
addSubredditFields(null, array.length, array);
|
|
|
|
} else if (name == "Discord invite") {
|
|
|
|
addDiscordFields(null, array.length, array);
|
|
|
|
} else if (name == "wiki page") {
|
|
|
|
addWikiFields(null, array.length, array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeFieldButton(inputGroup, array, index) {
|
|
|
|
console.log("remove button fired");
|
|
|
|
delete array[index];
|
|
|
|
inputGroup.remove();
|
|
|
|
console.log(array);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addWebsiteFields(link, index, array) {
|
|
|
|
const inputGroup = document.createElement("div");
|
|
|
|
inputGroup.className = "input-group";
|
|
|
|
websiteGroup.appendChild(inputGroup);
|
|
|
|
|
|
|
|
const inputField = document.createElement("input");
|
|
|
|
inputField.type = "url";
|
|
|
|
inputField.name = "url";
|
|
|
|
inputField.className = "form-control";
|
|
|
|
inputField.id = "websiteField" + index;
|
|
|
|
inputField.placeholder = "https://example.com";
|
|
|
|
inputField.pattern = "https?://.*";
|
|
|
|
inputField.title = "Website URL using the http:// or https:// protocol";
|
|
|
|
inputField.setAttribute("aria-labelledby", "websiteLabel");
|
|
|
|
inputField.value = link
|
|
|
|
inputGroup.appendChild(inputField);
|
|
|
|
websiteGroupElements.push(inputField);
|
|
|
|
|
|
|
|
const inputButton = document.createElement("button");
|
|
|
|
inputButton.type = "button";
|
|
|
|
// If button is the last in the array give it the add button
|
|
|
|
if (array.length == index + 1) {
|
|
|
|
inputButton.className = "btn btn-secondary";
|
|
|
|
inputButton.title = "Add website";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-plus-lg"></i>';
|
|
|
|
inputButton.addEventListener('click', () => addFieldButton(inputButton, inputGroup, websiteGroupElements, index, "website"));
|
|
|
|
} else {
|
|
|
|
inputButton.className = "btn btn-outline-secondary";
|
|
|
|
inputButton.title = "Remove website";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-trash-fill"></i>';
|
|
|
|
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
|
|
|
}
|
|
|
|
inputGroup.appendChild(inputButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addSubredditFields(link, index, array) {
|
|
|
|
const inputGroup = document.createElement("div");
|
|
|
|
inputGroup.className = "input-group";
|
|
|
|
subredditGroup.appendChild(inputGroup);
|
|
|
|
|
|
|
|
const inputAddon = document.createElement("span");
|
|
|
|
inputAddon.className = "input-group-text";
|
|
|
|
inputAddon.id = "subredditField" + index + "-addon";
|
|
|
|
inputAddon.textContent = "reddit.com/";
|
|
|
|
inputGroup.appendChild(inputAddon);
|
|
|
|
|
|
|
|
const inputField = document.createElement("input");
|
|
|
|
inputField.type = "text";
|
|
|
|
inputField.className = "form-control";
|
|
|
|
inputField.id = "subredditField" + index;
|
|
|
|
inputField.placeholder = "r/example";
|
|
|
|
inputField.pattern = "^r\/\\w+$";
|
|
|
|
inputField.title = "Subbredit in format of r/example";
|
|
|
|
inputField.maxLength = "23";
|
|
|
|
inputField.spellcheck = false;
|
|
|
|
inputField.setAttribute("aria-labelledby", "subredditLabel");
|
|
|
|
inputField.setAttribute("aria-describedby", "subredditField" + index + "-addon");
|
|
|
|
if (link) {
|
|
|
|
inputField.value = "r/" + link
|
|
|
|
} else {
|
|
|
|
inputField.value = "";
|
|
|
|
}
|
|
|
|
inputGroup.appendChild(inputField);
|
|
|
|
subredditGroupElements.push(inputField);
|
|
|
|
|
|
|
|
const inputButton = document.createElement("button");
|
|
|
|
inputButton.type = "button";
|
|
|
|
// If button is the last in the array give it the add button
|
|
|
|
if (array.length == index + 1) {
|
|
|
|
inputButton.className = "btn btn-secondary";
|
|
|
|
inputButton.title = "Add subreddit";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-plus-lg"></i>';
|
|
|
|
inputButton.addEventListener('click', () => addFieldButton(inputButton, inputGroup, subredditGroupElements, index, "subreddit"));
|
|
|
|
} else {
|
|
|
|
inputButton.className = "btn btn-outline-secondary";
|
|
|
|
inputButton.title = "Remove subreddit";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-trash-fill"></i>';
|
|
|
|
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
|
|
|
}
|
|
|
|
inputGroup.appendChild(inputButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDiscordFields(link, index, array) {
|
|
|
|
const inputGroup = document.createElement("div");
|
|
|
|
inputGroup.className = "input-group";
|
|
|
|
discordGroup.appendChild(inputGroup);
|
|
|
|
|
|
|
|
const inputAddon = document.createElement("span");
|
|
|
|
inputAddon.className = "input-group-text";
|
|
|
|
inputAddon.id = "discordField" + index + "-addon";
|
|
|
|
inputAddon.textContent = "discord.gg/";
|
|
|
|
inputGroup.appendChild(inputAddon);
|
|
|
|
|
|
|
|
const inputField = document.createElement("input");
|
|
|
|
inputField.type = "text";
|
|
|
|
inputField.className = "form-control";
|
|
|
|
inputField.id = "discordField" + index;
|
|
|
|
inputField.placeholder = "pJkm23b2nA";
|
|
|
|
inputField.spellcheck = false;
|
|
|
|
inputField.setAttribute("aria-labelledby", "discordLabel");
|
|
|
|
inputField.setAttribute("aria-describedby", "discordField" + index + "-addon");
|
|
|
|
inputField.value = link
|
|
|
|
inputGroup.appendChild(inputField);
|
|
|
|
discordGroupElements.push(inputField);
|
|
|
|
|
|
|
|
const inputButton = document.createElement("button");
|
|
|
|
inputButton.type = "button";
|
|
|
|
// If button is the last in the array give it the add button
|
|
|
|
if (array.length == index + 1) {
|
|
|
|
inputButton.className = "btn btn-secondary";
|
|
|
|
inputButton.title = "Add Discord invite";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-plus-lg"></i>';
|
|
|
|
inputButton.addEventListener('click', () => addFieldButton(inputButton, inputGroup, discordGroupElements, index, "Discord invite"));
|
|
|
|
} else {
|
|
|
|
inputButton.className = "btn btn-outline-secondary";
|
|
|
|
inputButton.title = "Remove Discord invite";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-trash-fill"></i>';
|
|
|
|
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
|
|
|
}
|
|
|
|
inputGroup.appendChild(inputButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addWikiFields(link, index, array) {
|
|
|
|
const inputGroup = document.createElement("div");
|
|
|
|
inputGroup.className = "input-group";
|
|
|
|
wikiGroup.appendChild(inputGroup);
|
|
|
|
|
|
|
|
const inputField = document.createElement("input");
|
|
|
|
inputField.type = "text";
|
|
|
|
inputField.className = "form-control";
|
|
|
|
inputField.id = "wikiField" + index;
|
|
|
|
inputField.placeholder = "Page title";
|
|
|
|
inputField.spellcheck = false;
|
|
|
|
inputField.setAttribute("aria-labelledby", "wikiLabel");
|
|
|
|
inputField.value = link
|
|
|
|
inputGroup.appendChild(inputField);
|
|
|
|
wikiGroupElements.push(inputField);
|
|
|
|
|
|
|
|
const inputButton = document.createElement("button");
|
|
|
|
inputButton.type = "button";
|
|
|
|
// If button is the last in the array give it the add button
|
|
|
|
if (array.length == index + 1) {
|
|
|
|
inputButton.className = "btn btn-secondary";
|
|
|
|
inputButton.title = "Add wiki page";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-plus-lg"></i>';
|
|
|
|
inputButton.addEventListener('click', () => addFieldButton(inputButton, inputGroup, wikiGroupElements, index, "wiki page"));
|
|
|
|
} else {
|
|
|
|
inputButton.className = "btn btn-outline-secondary";
|
|
|
|
inputButton.title = "Remove wiki page";
|
|
|
|
inputButton.innerHTML = '<i class="bi bi-trash-fill"></i>';
|
|
|
|
inputButton.addEventListener('click', () => removeFieldButton(inputGroup, array, index));
|
|
|
|
}
|
|
|
|
inputGroup.appendChild(inputButton);
|
|
|
|
}
|
|
|
|
|
2022-04-09 16:07:01 +02:00
|
|
|
if (params.has('id')) {
|
2022-04-17 09:10:06 +02:00
|
|
|
const entry = getEntry(params.get('id'))
|
2022-04-17 08:08:30 +02:00
|
|
|
nameField.value = entry.name
|
|
|
|
descriptionField.value = entry.description
|
2022-04-23 03:20:59 +02:00
|
|
|
|
|
|
|
if (entry.links.website.length) {
|
|
|
|
entry.links.website.forEach((link, index, array) => {
|
|
|
|
addWebsiteFields(link, index, array);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addWebsiteFields("", -1, entry.links.website);
|
|
|
|
}
|
|
|
|
if (entry.links.subreddit.length) {
|
|
|
|
entry.links.subreddit.forEach((link, index, array) => {
|
|
|
|
addSubredditFields(link, index, array);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addSubredditFields("", -1, entry.links.subreddit);
|
|
|
|
}
|
|
|
|
if (entry.links.discord.length) {
|
|
|
|
entry.links.discord.forEach((link, index, array) => {
|
|
|
|
addDiscordFields(link, index, array);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addDiscordFields("", -1, entry.links.discord);
|
|
|
|
}
|
|
|
|
if (entry.links.wiki.length) {
|
|
|
|
entry.links.wiki.forEach((link, index, array) => {
|
|
|
|
addWikiFields(link, index, array);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
addWikiFields("", -1, entry.links.wiki);
|
|
|
|
}
|
2022-04-09 16:07:01 +02:00
|
|
|
redoButton.disabled = true;
|
|
|
|
undoButton.disabled = false;
|
|
|
|
entryId = params.get('id')
|
|
|
|
|
2022-04-15 10:06:37 +02:00
|
|
|
Object.entries(entry.path).forEach(([period, path]) => {
|
|
|
|
period.split(", ").forEach(period => {
|
|
|
|
pathWithPeriods.push([period, path])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-04-14 08:44:39 +02:00
|
|
|
} else {
|
2022-04-28 11:44:46 +02:00
|
|
|
document.getElementById("offcanvasDrawLabel").textContent = "New Entry";
|
2022-04-14 08:44:39 +02:00
|
|
|
pathWithPeriods.push([defaultPeriod, []])
|
2022-04-24 09:51:41 +02:00
|
|
|
addWebsiteFields("", 0, [0]);
|
|
|
|
addSubredditFields("", 0, [0]);
|
|
|
|
addDiscordFields("", 0, [0]);
|
|
|
|
addWikiFields("", 0, [0]);
|
2022-04-09 16:07:01 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 08:44:39 +02:00
|
|
|
initPeriodGroups()
|
|
|
|
|
2022-04-14 19:06:13 +02:00
|
|
|
zoom = 4;
|
|
|
|
|
|
|
|
zoomOrigin = [
|
2022-04-16 14:44:50 +02:00
|
|
|
innerContainer.clientWidth / 2 - center[0] * zoom,// + container.offsetLeft
|
|
|
|
innerContainer.clientHeight / 2 - center[1] * zoom// + container.offsetTop
|
2022-04-14 19:06:13 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
scaleZoomOrigin = [
|
2022-04-16 14:44:50 +02:00
|
|
|
2000 / 2 - center[0],// + container.offsetLeft
|
|
|
|
2000 / 2 - center[1]// + container.offsetTop
|
2022-04-14 19:06:13 +02:00
|
|
|
];
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
applyView();
|
2022-04-14 19:06:13 +02:00
|
|
|
|
2022-04-10 11:11:34 +02:00
|
|
|
document.addEventListener('timeupdate', (event) => {
|
2022-04-14 10:37:29 +02:00
|
|
|
renderBackground()
|
2022-04-14 08:41:13 +02:00
|
|
|
updatePeriodGroups()
|
|
|
|
})
|
|
|
|
|
2022-04-14 09:56:30 +02:00
|
|
|
periodsAdd.addEventListener('click', () => {
|
|
|
|
pathWithPeriods.push([defaultPeriod, []])
|
|
|
|
initPeriodGroups()
|
|
|
|
})
|
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function calculateCenter(path) {
|
2022-04-23 15:29:22 +02:00
|
|
|
const result = polylabel(path)
|
2022-04-17 08:51:59 +02:00
|
|
|
return [Math.floor(result[0]) + 0.5, Math.floor(result[1]) + 0.5]
|
2022-04-14 19:06:13 +02:00
|
|
|
}
|
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
function initPeriodGroups() {
|
|
|
|
|
|
|
|
periodGroupElements = []
|
2022-04-14 09:56:30 +02:00
|
|
|
periodGroups.textContent = ''
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
pathWithPeriods.forEach(([period, path], index) => {
|
2022-04-16 14:26:31 +02:00
|
|
|
const periodGroupEl = periodGroupTemplate.cloneNode(true)
|
2022-04-14 08:41:13 +02:00
|
|
|
periodGroupEl.id = "periodGroup" + index
|
|
|
|
|
2022-04-16 14:26:31 +02:00
|
|
|
const startPeriodEl = periodGroupEl.querySelector('.period-start')
|
|
|
|
const endPeriodEl = periodGroupEl.querySelector('.period-end')
|
|
|
|
const periodDeleteEl = periodGroupEl.querySelector('.period-delete')
|
|
|
|
const periodDuplicateEl = periodGroupEl.querySelector('.period-duplicate')
|
|
|
|
const periodVariationEl = periodGroupEl.querySelector('.period-variation')
|
|
|
|
const periodCopyEl = periodGroupEl.querySelector('.period-copy')
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-16 14:26:31 +02:00
|
|
|
const [start, end, variation] = parsePeriod(period)
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
startPeriodEl.id = "periodStart" + index
|
2022-04-22 08:10:03 +02:00
|
|
|
startPeriodEl.previousElementSibling.htmlFor = startPeriodEl.id
|
2022-04-14 08:41:13 +02:00
|
|
|
endPeriodEl.id = "periodEnd" + index
|
2022-04-22 08:10:03 +02:00
|
|
|
endPeriodEl.previousElementSibling.htmlFor = endPeriodEl.id
|
2022-04-15 18:33:18 +02:00
|
|
|
periodVariationEl.id = "periodVariation" + index
|
2022-04-16 12:56:03 +02:00
|
|
|
periodCopyEl.id = "periodCopy" + index
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-16 07:58:26 +02:00
|
|
|
startPeriodEl.max = variationsConfig[variation].versions.length - 1
|
|
|
|
endPeriodEl.max = variationsConfig[variation].versions.length - 1
|
2022-04-16 10:34:05 +02:00
|
|
|
startPeriodEl.value = start
|
|
|
|
endPeriodEl.value = end
|
2022-04-23 15:49:22 +02:00
|
|
|
if (startPeriodEl.max == 0) periodGroupEl.classList.add('no-time-slider')
|
|
|
|
else periodGroupEl.classList.remove('no-time-slider')
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
startPeriodEl.addEventListener('input', event => {
|
|
|
|
timelineSlider.value = parseInt(event.target.value)
|
2022-04-15 18:33:18 +02:00
|
|
|
updateTime(parseInt(event.target.value), variation)
|
2022-04-14 08:41:13 +02:00
|
|
|
})
|
2022-04-14 10:37:29 +02:00
|
|
|
endPeriodEl.addEventListener('input', event => {
|
|
|
|
timelineSlider.value = parseInt(event.target.value)
|
2022-04-15 18:33:18 +02:00
|
|
|
updateTime(parseInt(event.target.value), variation)
|
2022-04-14 08:41:13 +02:00
|
|
|
})
|
2022-04-14 09:56:30 +02:00
|
|
|
periodDeleteEl.addEventListener('click', () => {
|
|
|
|
if (pathWithPeriods.length === 1) return
|
|
|
|
pathWithPeriods = pathWithPeriods.filter((_, i) => i !== index)
|
|
|
|
initPeriodGroups()
|
|
|
|
})
|
|
|
|
periodDuplicateEl.addEventListener('click', () => {
|
|
|
|
pathWithPeriods.push([pathWithPeriods[index][0], [...pathWithPeriods[index][1]]])
|
|
|
|
initPeriodGroups()
|
|
|
|
})
|
2022-04-15 18:33:18 +02:00
|
|
|
periodVariationEl.addEventListener('input', event => {
|
2022-04-16 14:26:31 +02:00
|
|
|
const newVariation = event.target.value
|
|
|
|
const newVariationConfig = variationsConfig[newVariation]
|
2022-04-15 18:33:18 +02:00
|
|
|
startPeriodEl.value = newVariationConfig.default
|
|
|
|
startPeriodEl.max = newVariationConfig.versions.length - 1
|
|
|
|
endPeriodEl.value = newVariationConfig.default
|
2022-04-16 14:44:50 +02:00
|
|
|
endPeriodEl.max = newVariationConfig.versions.length - 1
|
2022-04-24 09:51:41 +02:00
|
|
|
periodVariationEl.previousElementSibling.innerHTML = newVariationConfig.icon;
|
2022-04-23 15:49:22 +02:00
|
|
|
if (startPeriodEl.max == 0) periodGroupEl.classList.add('no-time-slider')
|
|
|
|
else periodGroupEl.classList.remove('no-time-slider')
|
2022-04-16 12:31:56 +02:00
|
|
|
updateTime(newVariationConfig.default, newVariation)
|
2022-04-15 18:33:18 +02:00
|
|
|
})
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-16 12:56:03 +02:00
|
|
|
periodCopyEl.addEventListener("click", event => {
|
|
|
|
const index = parseInt(event.target.id.split('periodCopy')[1])
|
2022-04-22 08:10:03 +02:00
|
|
|
if (event.target.textContent === " Copy") {
|
|
|
|
event.target.className = "period-copy btn btn-primary btn-sm flex-fill";
|
|
|
|
event.target.innerHTML = '<i class="bi bi-clipboard-x" aria-hidden="true"></i> End'
|
2022-04-16 12:56:03 +02:00
|
|
|
periodClipboard.index = index
|
|
|
|
periodClipboard.path = [...pathWithPeriods[index][1]]
|
2022-04-22 08:10:03 +02:00
|
|
|
startPeriodEl.disabled = true;
|
|
|
|
endPeriodEl.disabled = true;
|
2022-04-16 12:56:03 +02:00
|
|
|
updatePeriodGroups()
|
2022-04-22 08:10:03 +02:00
|
|
|
} else if (event.target.textContent === " End") {
|
|
|
|
event.target.className = "period-copy btn btn-secondary btn-sm flex-fill";
|
|
|
|
event.target.innerHTML = '<i class="bi bi-clipboard" aria-hidden="true"></i> Copy'
|
2022-04-16 12:56:03 +02:00
|
|
|
periodClipboard.index = null
|
|
|
|
periodClipboard.path = null
|
2022-04-22 08:10:03 +02:00
|
|
|
startPeriodEl.disabled = false;
|
|
|
|
endPeriodEl.disabled = false;
|
2022-04-16 12:56:03 +02:00
|
|
|
updatePeriodGroups()
|
2022-04-22 08:10:03 +02:00
|
|
|
} else if (event.target.textContent === " Paste") {
|
2022-04-16 12:56:03 +02:00
|
|
|
pathWithPeriods[index][1] = [...periodClipboard.path]
|
|
|
|
if (pathWithPeriods.length > 2) console.log(pathWithPeriods[2])
|
|
|
|
initPeriodGroups()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
periodGroups.appendChild(periodGroupEl)
|
2022-04-15 18:33:18 +02:00
|
|
|
|
2022-04-16 14:26:31 +02:00
|
|
|
for (const variation in variationsConfig) {
|
2022-04-15 18:33:18 +02:00
|
|
|
const optionEl = document.createElement('option')
|
|
|
|
optionEl.value = variation
|
|
|
|
optionEl.textContent = variationsConfig[variation].name
|
|
|
|
periodVariationEl.appendChild(optionEl)
|
|
|
|
}
|
|
|
|
|
|
|
|
periodVariationEl.value = variation
|
2022-04-24 09:51:41 +02:00
|
|
|
periodVariationEl.previousElementSibling.innerHTML = variationsConfig[variation].icon;
|
2022-04-22 08:10:03 +02:00
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
periodGroupElements.push({
|
|
|
|
periodGroupEl,
|
|
|
|
startPeriodEl,
|
|
|
|
endPeriodEl,
|
2022-04-16 12:56:03 +02:00
|
|
|
periodVariationEl,
|
|
|
|
periodCopyEl
|
2022-04-14 08:41:13 +02:00
|
|
|
})
|
|
|
|
})
|
2022-04-15 09:24:08 +02:00
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
updatePeriodGroups()
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePeriodGroups() {
|
2022-04-16 14:44:50 +02:00
|
|
|
let pathToActive = []
|
|
|
|
let lastActivePathIndex
|
|
|
|
let currentActivePathIndex
|
|
|
|
const currentActivePathIndexes = []
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
periodGroupElements.forEach((elements, index) => {
|
2022-04-16 14:26:31 +02:00
|
|
|
const {
|
2022-04-14 08:41:13 +02:00
|
|
|
periodGroupEl,
|
|
|
|
startPeriodEl,
|
|
|
|
endPeriodEl,
|
2022-04-16 12:56:03 +02:00
|
|
|
periodVariationEl,
|
|
|
|
periodCopyEl
|
2022-04-14 08:41:13 +02:00
|
|
|
} = elements
|
|
|
|
|
|
|
|
if (periodGroupEl.dataset.active === "true") lastActivePathIndex = index
|
2022-04-14 19:06:13 +02:00
|
|
|
periodGroupEl.dataset.active = ""
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
if (isOnPeriod(
|
2022-04-16 14:44:50 +02:00
|
|
|
parseInt(startPeriodEl.value),
|
2022-04-14 08:41:13 +02:00
|
|
|
parseInt(endPeriodEl.value),
|
2022-04-15 18:33:18 +02:00
|
|
|
periodVariationEl.value,
|
|
|
|
currentPeriod,
|
|
|
|
currentVariation
|
2022-04-14 08:41:13 +02:00
|
|
|
)) {
|
|
|
|
pathToActive = pathWithPeriods[index][1]
|
|
|
|
currentActivePathIndex = index
|
2022-04-14 19:06:13 +02:00
|
|
|
currentActivePathIndexes.push(index)
|
|
|
|
periodGroupEl.dataset.active = "true"
|
2022-04-10 11:11:34 +02:00
|
|
|
}
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
pathWithPeriods[index][0] = formatPeriod(
|
2022-04-16 14:44:50 +02:00
|
|
|
parseInt(startPeriodEl.value),
|
2022-04-14 08:41:13 +02:00
|
|
|
parseInt(endPeriodEl.value),
|
2022-04-15 18:33:18 +02:00
|
|
|
periodVariationEl.value
|
2022-04-14 08:41:13 +02:00
|
|
|
)
|
2022-04-16 12:56:03 +02:00
|
|
|
|
|
|
|
if (periodClipboard.index !== null) {
|
|
|
|
if (index !== periodClipboard.index) {
|
2022-04-22 08:10:03 +02:00
|
|
|
periodCopyEl.innerHTML = '<i class="bi bi-clipboard-plus" aria-hidden="true"></i> Paste'
|
2022-04-16 12:56:03 +02:00
|
|
|
if (JSON.stringify(pathWithPeriods[index][1]) === JSON.stringify(periodClipboard.path)) {
|
2022-04-22 08:10:03 +02:00
|
|
|
periodCopyEl.innerHTML = '<i class="bi bi-clipboard-check" aria-hidden="true"></i> Paste'
|
2022-04-16 12:56:03 +02:00
|
|
|
periodCopyEl.disabled = true
|
|
|
|
} else {
|
2022-04-22 08:10:03 +02:00
|
|
|
periodCopyEl.innerHTML = '<i class="bi bi-clipboard-plus" aria-hidden="true"></i> Paste'
|
2022-04-16 12:56:03 +02:00
|
|
|
periodCopyEl.disabled = false
|
|
|
|
}
|
|
|
|
} else {
|
2022-04-22 08:10:03 +02:00
|
|
|
periodCopyEl.className = "period-copy btn btn-primary btn-sm flex-fill";
|
|
|
|
periodCopyEl.innerHTML = '<i class="bi bi-clipboard-x" aria-hidden="true"></i> End'
|
2022-04-16 12:56:03 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-04-22 08:10:03 +02:00
|
|
|
periodCopyEl.innerHTML = '<i class="bi bi-clipboard" aria-hidden="true"></i> Copy'
|
2022-04-16 12:56:03 +02:00
|
|
|
periodCopyEl.disabled = false
|
|
|
|
}
|
2022-04-10 11:11:34 +02:00
|
|
|
})
|
|
|
|
|
2022-04-14 09:56:30 +02:00
|
|
|
periodsStatus.textContent = ""
|
2022-04-14 19:06:13 +02:00
|
|
|
|
2022-04-14 08:41:13 +02:00
|
|
|
if (lastActivePathIndex !== undefined) {
|
|
|
|
if (lastActivePathIndex === currentActivePathIndex) {
|
|
|
|
// just update the path
|
2022-04-16 14:26:31 +02:00
|
|
|
const {
|
2022-04-15 18:33:18 +02:00
|
|
|
startPeriodEl,
|
|
|
|
endPeriodEl,
|
|
|
|
periodVariationEl
|
|
|
|
} = periodGroupElements[currentActivePathIndex]
|
2022-04-14 08:41:13 +02:00
|
|
|
pathWithPeriods[currentActivePathIndex] = [
|
|
|
|
formatPeriod(
|
2022-04-15 18:33:18 +02:00
|
|
|
parseInt(startPeriodEl.value),
|
|
|
|
parseInt(endPeriodEl.value),
|
|
|
|
periodVariationEl.value,
|
2022-04-14 08:41:13 +02:00
|
|
|
),
|
|
|
|
path
|
|
|
|
]
|
2022-04-14 19:06:13 +02:00
|
|
|
updatePath()
|
2022-04-14 08:41:13 +02:00
|
|
|
} else if (currentActivePathIndex === undefined) {
|
2022-04-14 09:56:30 +02:00
|
|
|
pathWithPeriods[lastActivePathIndex][1] = path
|
2022-04-14 08:41:13 +02:00
|
|
|
updatePath([])
|
|
|
|
} else {
|
|
|
|
// switch the path
|
2022-04-14 09:56:30 +02:00
|
|
|
pathWithPeriods[lastActivePathIndex][1] = path
|
|
|
|
updatePath(pathToActive)
|
2022-04-14 08:41:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updatePath(pathToActive)
|
|
|
|
}
|
|
|
|
|
2022-04-14 10:37:29 +02:00
|
|
|
drawing = disableDrawingOverride ? false : currentActivePathIndex !== undefined
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
|
|
|
|
2022-04-15 18:33:18 +02:00
|
|
|
function formatPeriod(start, end, variation) {
|
2022-04-16 14:44:50 +02:00
|
|
|
let periodString
|
2022-04-15 18:33:18 +02:00
|
|
|
if (start === end) periodString = start
|
|
|
|
else periodString = start + "-" + end
|
|
|
|
if (variation !== "default") periodString = variationsConfig[variation].code + ":" + periodString
|
|
|
|
return periodString
|
2017-04-04 01:24:46 +02:00
|
|
|
}
|
2022-04-14 08:41:13 +02:00
|
|
|
|
2022-04-15 09:24:08 +02:00
|
|
|
function updatePath(newPath) {
|
|
|
|
if (newPath) path = newPath
|
|
|
|
if (path.length > 3) center = calculateCenter(path)
|
2022-04-14 08:41:13 +02:00
|
|
|
render(path)
|
2022-04-14 13:23:06 +02:00
|
|
|
undoButton.disabled = path.length == 0; // Maybe make it undo the cancel action in the future
|
|
|
|
undoHistory = []
|
2022-04-14 19:06:13 +02:00
|
|
|
|
2022-04-15 09:24:08 +02:00
|
|
|
updateErrors()
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateErrors() {
|
2022-04-14 19:06:13 +02:00
|
|
|
if (path.length === 0) {
|
|
|
|
periodsStatus.textContent = "No paths available on this period!"
|
|
|
|
}
|
|
|
|
|
2022-04-16 14:26:31 +02:00
|
|
|
const [conflicts, invalidPaths, allErrors] = getErrors()
|
2022-04-14 19:06:13 +02:00
|
|
|
|
|
|
|
if (allErrors.length > 0) {
|
|
|
|
periodsStatus.textContent = `Problems detected. Please check the groups indicated by red.`
|
2022-04-15 09:24:08 +02:00
|
|
|
if (conflicts.length > 0) {
|
|
|
|
periodsStatus.textContent += `\nConflicts on ${conflicts.join(', ')}.`
|
|
|
|
currentActivePathIndex = undefined
|
|
|
|
}
|
2022-04-14 19:06:13 +02:00
|
|
|
if (invalidPaths.length > 0) periodsStatus.textContent += `\nInsufficient paths on ${invalidPaths.join(', ')}.`
|
|
|
|
allErrors.forEach(index => {
|
|
|
|
periodGroupElements[index].periodGroupEl.dataset.status = "error"
|
|
|
|
})
|
|
|
|
finishButton.disabled = true
|
|
|
|
} else {
|
|
|
|
periodsStatus.textContent = ``
|
|
|
|
finishButton.disabled = false
|
|
|
|
periodGroupElements.forEach((elements, index) => {
|
2022-04-16 14:26:31 +02:00
|
|
|
const { periodGroupEl } = elements
|
2022-04-14 19:06:13 +02:00
|
|
|
if (periodGroupEl.dataset.active === "true") periodGroupEl.dataset.status = "active"
|
|
|
|
else periodGroupEl.dataset.status = ""
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2022-04-14 19:06:13 +02:00
|
|
|
function getConflicts() {
|
|
|
|
|
|
|
|
let conflicts = new Set()
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2022-04-14 19:06:13 +02:00
|
|
|
for (let i = pathWithPeriods.length - 1; i > 0; i--) {
|
2022-04-16 14:26:31 +02:00
|
|
|
const [start1, end1, period1] = parsePeriod(pathWithPeriods[i][0])
|
2022-04-14 19:06:13 +02:00
|
|
|
for (let j = 0; j < i; j++) {
|
2022-04-16 14:26:31 +02:00
|
|
|
const [start2, end2, period2] = parsePeriod(pathWithPeriods[j][0])
|
2022-04-15 18:33:18 +02:00
|
|
|
if (period1 !== period2) continue
|
2022-04-14 19:06:13 +02:00
|
|
|
if (
|
|
|
|
(start2 <= start1 && start1 <= end2) ||
|
|
|
|
(start2 <= end1 && end1 <= end2) ||
|
|
|
|
(start1 <= start2 && start2 <= end1) ||
|
|
|
|
(start1 <= end2 && end2 <= end1)
|
|
|
|
) {
|
|
|
|
conflicts.add(i)
|
|
|
|
conflicts.add(j)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conflicts = [...conflicts]
|
|
|
|
|
|
|
|
return conflicts
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getErrors() {
|
2022-04-16 14:26:31 +02:00
|
|
|
const conflicts = getConflicts()
|
|
|
|
const invalidPaths = []
|
2022-04-14 19:06:13 +02:00
|
|
|
|
|
|
|
pathWithPeriods.forEach(([period, path], i) => {
|
|
|
|
if (path.length < 3) invalidPaths.push(i)
|
|
|
|
})
|
2022-04-16 14:44:50 +02:00
|
|
|
|
2022-04-15 09:24:08 +02:00
|
|
|
// console.info('conflicts', conflicts)
|
|
|
|
// console.info('invalid paths', invalidPaths)
|
2022-04-14 19:06:13 +02:00
|
|
|
|
|
|
|
return [conflicts, invalidPaths, [...new Set([...conflicts, ...invalidPaths])]]
|
2022-04-14 16:03:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// function compressPeriod(periodsString) {
|
|
|
|
// let periodStrings = periodsString.split(", ")
|
|
|
|
// let validPeriods = new Set()
|
|
|
|
// periodStrings.forEach(periodString => {
|
|
|
|
// let [start, end] = parsePeriod(periodString)
|
|
|
|
// for (var i = start; i <= end; i++) {
|
|
|
|
// validPeriods.add(i)
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// validPeriods = [...validPeriods].sort()
|
2022-04-17 08:31:51 +02:00
|
|
|
// }
|