mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-09-27 20:48:56 +02:00
Fix prefer-const problems (ESLint)
This commit is contained in:
parent
48f7361306
commit
4be8a36839
6 changed files with 69 additions and 69 deletions
|
@ -24,7 +24,7 @@ window.addEventListener("error", function (e) {
|
|||
|
||||
function getPositionOfEntry(entry){
|
||||
let startX = 2000, startY = 2000;
|
||||
for(let [x, y] of entry.path){
|
||||
for(const [x, y] of entry.path){
|
||||
startX = Math.min(x, startX);
|
||||
startY = Math.min(y, startY)
|
||||
}
|
||||
|
|
|
@ -263,8 +263,8 @@ function initDraw(){
|
|||
exportObject.center[key] = calculateCenter(value)
|
||||
})
|
||||
|
||||
let inputWebsite = document.getElementById("websiteField").value.split('\n').map(line => line.trim()).filter(line => line)
|
||||
let inputSubreddit = document.getElementById("subredditField").value.split('\n').map(line => line.trim().replace(/^\/?r\//, '')).filter(line => line)
|
||||
const inputWebsite = document.getElementById("websiteField").value.split('\n').map(line => line.trim()).filter(line => line)
|
||||
const inputSubreddit = document.getElementById("subredditField").value.split('\n').map(line => line.trim().replace(/^\/?r\//, '')).filter(line => line)
|
||||
|
||||
if (inputWebsite.length) exportObject.links.website = inputWebsite
|
||||
if (inputSubreddit.length) exportObject.links.subreddit = inputSubreddit
|
||||
|
@ -425,7 +425,7 @@ function initDraw(){
|
|||
return {}
|
||||
}
|
||||
|
||||
let params = new URLSearchParams(document.location.search)
|
||||
const params = new URLSearchParams(document.location.search)
|
||||
|
||||
if (params.has('id')) {
|
||||
entry = getEntry(params.get('id'))
|
||||
|
@ -508,18 +508,18 @@ function initPeriodGroups() {
|
|||
// console.log(pathWithPeriods)
|
||||
|
||||
pathWithPeriods.forEach(([period, path], index) => {
|
||||
let periodGroupEl = periodGroupTemplate.cloneNode(true)
|
||||
const periodGroupEl = periodGroupTemplate.cloneNode(true)
|
||||
periodGroupEl.id = "periodGroup" + index
|
||||
|
||||
let startPeriodEl = periodGroupEl.querySelector('.period-start')
|
||||
let endPeriodEl = periodGroupEl.querySelector('.period-end')
|
||||
let periodVisibilityEl = periodGroupEl.querySelector('.period-visible')
|
||||
let periodDeleteEl = periodGroupEl.querySelector('.period-delete')
|
||||
let periodDuplicateEl = periodGroupEl.querySelector('.period-duplicate')
|
||||
let periodVariationEl = periodGroupEl.querySelector('.period-variation')
|
||||
let periodCopyEl = periodGroupEl.querySelector('.period-copy')
|
||||
const startPeriodEl = periodGroupEl.querySelector('.period-start')
|
||||
const endPeriodEl = periodGroupEl.querySelector('.period-end')
|
||||
const periodVisibilityEl = periodGroupEl.querySelector('.period-visible')
|
||||
const periodDeleteEl = periodGroupEl.querySelector('.period-delete')
|
||||
const periodDuplicateEl = periodGroupEl.querySelector('.period-duplicate')
|
||||
const periodVariationEl = periodGroupEl.querySelector('.period-variation')
|
||||
const periodCopyEl = periodGroupEl.querySelector('.period-copy')
|
||||
|
||||
let [start, end, variation] = parsePeriod(period)
|
||||
const [start, end, variation] = parsePeriod(period)
|
||||
// console.log(period, start, end, variation)
|
||||
|
||||
startPeriodEl.id = "periodStart" + index
|
||||
|
@ -555,8 +555,8 @@ function initPeriodGroups() {
|
|||
initPeriodGroups()
|
||||
})
|
||||
periodVariationEl.addEventListener('input', event => {
|
||||
let newVariation = event.target.value
|
||||
let newVariationConfig = variationsConfig[newVariation]
|
||||
const newVariation = event.target.value
|
||||
const newVariationConfig = variationsConfig[newVariation]
|
||||
startPeriodEl.value = newVariationConfig.default
|
||||
startPeriodEl.max = newVariationConfig.versions.length - 1
|
||||
endPeriodEl.value = newVariationConfig.default
|
||||
|
@ -587,7 +587,7 @@ function initPeriodGroups() {
|
|||
|
||||
periodGroups.appendChild(periodGroupEl)
|
||||
|
||||
for (let variation in variationsConfig) {
|
||||
for (const variation in variationsConfig) {
|
||||
const optionEl = document.createElement('option')
|
||||
optionEl.value = variation
|
||||
optionEl.textContent = variationsConfig[variation].name
|
||||
|
@ -619,7 +619,7 @@ function updatePeriodGroups() {
|
|||
var currentActivePathIndexes = []
|
||||
|
||||
periodGroupElements.forEach((elements, index) => {
|
||||
let {
|
||||
const {
|
||||
periodGroupEl,
|
||||
startPeriodEl,
|
||||
endPeriodEl,
|
||||
|
@ -686,7 +686,7 @@ function updatePeriodGroups() {
|
|||
if (lastActivePathIndex !== undefined) {
|
||||
if (lastActivePathIndex === currentActivePathIndex) {
|
||||
// just update the path
|
||||
let {
|
||||
const {
|
||||
startPeriodEl,
|
||||
endPeriodEl,
|
||||
periodVariationEl
|
||||
|
@ -743,7 +743,7 @@ function updateErrors() {
|
|||
periodsStatus.textContent = "No paths available on this period!"
|
||||
}
|
||||
|
||||
let [conflicts, invalidPaths, allErrors] = getErrors()
|
||||
const [conflicts, invalidPaths, allErrors] = getErrors()
|
||||
|
||||
if (allErrors.length > 0) {
|
||||
periodsStatus.textContent = `Problems detected. Please check the groups indicated by red.`
|
||||
|
@ -760,7 +760,7 @@ function updateErrors() {
|
|||
periodsStatus.textContent = ``
|
||||
finishButton.disabled = false
|
||||
periodGroupElements.forEach((elements, index) => {
|
||||
let { periodGroupEl } = elements
|
||||
const { periodGroupEl } = elements
|
||||
if (periodGroupEl.dataset.active === "true") periodGroupEl.dataset.status = "active"
|
||||
else periodGroupEl.dataset.status = ""
|
||||
})
|
||||
|
@ -772,9 +772,9 @@ function getConflicts() {
|
|||
let conflicts = new Set()
|
||||
|
||||
for (let i = pathWithPeriods.length - 1; i > 0; i--) {
|
||||
let [start1, end1, period1] = parsePeriod(pathWithPeriods[i][0])
|
||||
const [start1, end1, period1] = parsePeriod(pathWithPeriods[i][0])
|
||||
for (let j = 0; j < i; j++) {
|
||||
let [start2, end2, period2] = parsePeriod(pathWithPeriods[j][0])
|
||||
const [start2, end2, period2] = parsePeriod(pathWithPeriods[j][0])
|
||||
if (period1 !== period2) continue
|
||||
if (
|
||||
(start2 <= start1 && start1 <= end2) ||
|
||||
|
@ -795,8 +795,8 @@ function getConflicts() {
|
|||
}
|
||||
|
||||
function getErrors() {
|
||||
let conflicts = getConflicts()
|
||||
let invalidPaths = []
|
||||
const conflicts = getConflicts()
|
||||
const invalidPaths = []
|
||||
|
||||
pathWithPeriods.forEach(([period, path], i) => {
|
||||
if (path.length < 3) invalidPaths.push(i)
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
function createInfoBlock(entry) {
|
||||
// console.log(entry)
|
||||
function createInfoParagraph(name, value){
|
||||
let entryParagraphPositionElement = document.createElement("p");
|
||||
let nameElement = document.createElement("span");
|
||||
const entryParagraphPositionElement = document.createElement("p");
|
||||
const nameElement = document.createElement("span");
|
||||
nameElement.style.fontWeight = "bold";
|
||||
nameElement.innerText = name;
|
||||
let valueElement = document.createElement("span");
|
||||
const valueElement = document.createElement("span");
|
||||
valueElement.innerText = value;
|
||||
entryParagraphPositionElement.appendChild(nameElement);
|
||||
entryParagraphPositionElement.appendChild(valueElement);
|
||||
|
@ -30,8 +30,8 @@ function createInfoBlock(entry) {
|
|||
var element = document.createElement("div");
|
||||
element.className = "object";
|
||||
|
||||
let headerElement = document.createElement("h2");
|
||||
let linkElement = document.createElement("a");
|
||||
const headerElement = document.createElement("h2");
|
||||
const linkElement = document.createElement("a");
|
||||
linkElement.href = "#" + entry.id;
|
||||
linkElement.innerText = entry.name;
|
||||
headerElement.appendChild(linkElement);
|
||||
|
@ -39,28 +39,28 @@ function createInfoBlock(entry) {
|
|||
element.appendChild(headerElement);
|
||||
|
||||
if (entry.diff) {
|
||||
let diffElement = createInfoParagraph("Diff: ", entry.diff);
|
||||
const diffElement = createInfoParagraph("Diff: ", entry.diff);
|
||||
diffElement.className = entry.diff;
|
||||
element.appendChild(diffElement);
|
||||
}
|
||||
|
||||
if (entry.description) {
|
||||
let descElement = document.createElement("p");
|
||||
const descElement = document.createElement("p");
|
||||
descElement.innerText = entry.description;
|
||||
element.appendChild(descElement);
|
||||
}
|
||||
|
||||
let [x, y] = entry.center;
|
||||
const [x, y] = entry.center;
|
||||
element.appendChild(createInfoParagraph("Position: ", `${Math.floor(x)}, ${Math.floor(y)}`));
|
||||
|
||||
if(entry.path){
|
||||
let area = calcPolygonArea(entry.path);
|
||||
const area = calcPolygonArea(entry.path);
|
||||
element.appendChild(createInfoParagraph("Area: ", `${area} pixels`));
|
||||
}
|
||||
|
||||
entry.links.subreddit.forEach(subreddit => {
|
||||
subreddit = "/r/" + subreddit;
|
||||
let subredditLinkElement = document.createElement("a");
|
||||
const subredditLinkElement = document.createElement("a");
|
||||
subredditLinkElement.target = "_blank";
|
||||
subredditLinkElement.href = "https://reddit.com" + subreddit;
|
||||
subredditLinkElement.innerText = subreddit;
|
||||
|
@ -68,7 +68,7 @@ function createInfoBlock(entry) {
|
|||
})
|
||||
|
||||
entry.links.website.forEach(link => {
|
||||
let websiteLinkElement = document.createElement("a");
|
||||
const websiteLinkElement = document.createElement("a");
|
||||
websiteLinkElement.target = "_blank";
|
||||
websiteLinkElement.href = link;
|
||||
websiteLinkElement.innerText = "Website";
|
||||
|
@ -76,7 +76,7 @@ function createInfoBlock(entry) {
|
|||
})
|
||||
|
||||
entry.links.discord.forEach(link => {
|
||||
let websiteLinkElement = document.createElement("a");
|
||||
const websiteLinkElement = document.createElement("a");
|
||||
websiteLinkElement.target = "_blank";
|
||||
websiteLinkElement.href = "https://discord.gg/" + link;
|
||||
websiteLinkElement.innerText = "Discord";
|
||||
|
@ -84,18 +84,18 @@ function createInfoBlock(entry) {
|
|||
})
|
||||
|
||||
entry.links.wiki.forEach(link => {
|
||||
let websiteLinkElement = document.createElement("a");
|
||||
const websiteLinkElement = document.createElement("a");
|
||||
websiteLinkElement.target = "_blank";
|
||||
websiteLinkElement.href = "https://place-wiki.stefanocoding.me/wiki/" + link.replace(/ /g, '_');
|
||||
websiteLinkElement.innerText = "Wiki Article";
|
||||
element.appendChild(websiteLinkElement);
|
||||
})
|
||||
|
||||
let idElement = createInfoParagraph("ID: ", entry.id);
|
||||
const idElement = createInfoParagraph("ID: ", entry.id);
|
||||
element.appendChild(idElement);
|
||||
|
||||
if (!entry.diff || entry.diff !== "delete") {
|
||||
let editElement = document.createElement("a");
|
||||
const editElement = document.createElement("a");
|
||||
editElement.innerText = "Edit"
|
||||
editElement.className = "objectEdit"
|
||||
editElement.href = "./?mode=draw&id=" + entry.id
|
||||
|
|
|
@ -75,7 +75,7 @@ init();
|
|||
async function init(){
|
||||
// For Reviewing Reddit Changes
|
||||
//let resp = await fetch("../tools/temp_atlas.json");
|
||||
let resp = await fetch("./atlas.json");
|
||||
const resp = await fetch("./atlas.json");
|
||||
atlas = await resp.json();
|
||||
atlas.sort(function (a, b) {
|
||||
if (a.center[1] < b.center[1]) {
|
||||
|
@ -116,9 +116,9 @@ async function init(){
|
|||
|
||||
// Backwards compatibility for old links using "search" id arg
|
||||
if (params.has('id') && params.get('mode') !== 'draw') {
|
||||
let id = params.get('id')
|
||||
const id = params.get('id')
|
||||
params.delete('id')
|
||||
let newLocation = new URL(window.location)
|
||||
const newLocation = new URL(window.location)
|
||||
newLocation.hash = id
|
||||
newLocation.search = params
|
||||
window.history.replaceState({}, '', newLocation)
|
||||
|
@ -140,12 +140,12 @@ async function init(){
|
|||
}
|
||||
} else if(mode.startsWith("diff")){
|
||||
try {
|
||||
let liveResp = await fetch("https://place-atlas.stefanocoding.me/atlas.json");
|
||||
const liveResp = await fetch("https://place-atlas.stefanocoding.me/atlas.json");
|
||||
let liveJson = await liveResp.json();
|
||||
liveJson = updateAtlasAll(liveJson)
|
||||
// console.log(liveJson)
|
||||
|
||||
let liveAtlasReduced = liveJson.reduce(function(a, c) {
|
||||
const liveAtlasReduced = liveJson.reduce(function(a, c) {
|
||||
a[c.id] = c;
|
||||
return a;
|
||||
},{});
|
||||
|
@ -160,11 +160,11 @@ async function init(){
|
|||
});
|
||||
|
||||
// Mark removed entries
|
||||
let atlasReduced = atlasAll.reduce(function(a, c) {
|
||||
const atlasReduced = atlasAll.reduce(function(a, c) {
|
||||
a[c.id] = c;
|
||||
return a;
|
||||
},{});
|
||||
let removedEntries = liveJson.filter(entry =>
|
||||
const removedEntries = liveJson.filter(entry =>
|
||||
atlasReduced[entry.id] === undefined
|
||||
).map(entry => {
|
||||
entry.diff = "delete"
|
||||
|
@ -508,19 +508,19 @@ async function init(){
|
|||
|
||||
function updateAtlasAll(atlas) {
|
||||
if (!atlas) atlas = atlasAll
|
||||
for (let atlasIndex in atlas) {
|
||||
for (const atlasIndex in atlas) {
|
||||
if (Array.isArray(atlas[atlasIndex].path)) {
|
||||
let currentPath = atlas[atlasIndex].path
|
||||
const currentPath = atlas[atlasIndex].path
|
||||
atlas[atlasIndex].path = {}
|
||||
atlas[atlasIndex].path[defaultPeriod] = currentPath
|
||||
}
|
||||
if (Array.isArray(atlas[atlasIndex].center)) {
|
||||
let currentCenter = atlas[atlasIndex].center
|
||||
const currentCenter = atlas[atlasIndex].center
|
||||
atlas[atlasIndex].center = {}
|
||||
atlas[atlasIndex].center[defaultPeriod] = currentCenter
|
||||
}
|
||||
if (atlas[atlasIndex].links) {
|
||||
let currentLinks = atlas[atlasIndex].links
|
||||
const currentLinks = atlas[atlasIndex].links
|
||||
atlas[atlasIndex].links = {
|
||||
website: [],
|
||||
subreddit: [],
|
||||
|
|
|
@ -88,7 +88,7 @@ const imageCache = {}
|
|||
|
||||
const variantsEl = document.getElementById("variants")
|
||||
|
||||
for (let variation in variationsConfig) {
|
||||
for (const variation in variationsConfig) {
|
||||
codeReference[variationsConfig[variation].code] = variation
|
||||
const optionEl = document.createElement('option')
|
||||
optionEl.value = variation
|
||||
|
@ -104,7 +104,7 @@ let currentUpdateIndex = 0
|
|||
let updateTimeout = setTimeout(null, 0)
|
||||
|
||||
let currentVariation = "default"
|
||||
let defaultPeriod = variationsConfig[currentVariation].default
|
||||
const defaultPeriod = variationsConfig[currentVariation].default
|
||||
let currentPeriod = defaultPeriod
|
||||
window.currentPeriod = currentPeriod
|
||||
window.currentVariation = currentVariation
|
||||
|
@ -150,7 +150,7 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren
|
|||
abortController.abort()
|
||||
abortController = new AbortController()
|
||||
currentUpdateIndex++
|
||||
let myUpdateIndex = currentUpdateIndex
|
||||
const myUpdateIndex = currentUpdateIndex
|
||||
currentPeriod = newPeriod
|
||||
// console.log(newPeriod, newVariation)
|
||||
const variationConfig = variationsConfig[newVariation]
|
||||
|
@ -165,14 +165,14 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren
|
|||
const configObject = variationConfig.versions[currentPeriod];
|
||||
if (typeof configObject.url === "string") {
|
||||
if (imageCache[configObject.url] === undefined) {
|
||||
let fetchResult = await fetch(configObject.url, {
|
||||
const fetchResult = await fetch(configObject.url, {
|
||||
signal: abortController.signal
|
||||
});
|
||||
if (currentUpdateIndex !== myUpdateIndex) {
|
||||
hideLoading()
|
||||
return
|
||||
}
|
||||
let imageBlob = await fetchResult.blob()
|
||||
const imageBlob = await fetchResult.blob()
|
||||
imageCache[configObject.url] = URL.createObjectURL(imageBlob)
|
||||
}
|
||||
image.src = imageCache[configObject.url]
|
||||
|
@ -181,16 +181,16 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren
|
|||
const context = canvas.getContext('2d')
|
||||
context.canvas.width = 2000
|
||||
context.canvas.height = 2000
|
||||
for await (let url of configObject.url) {
|
||||
for await (const url of configObject.url) {
|
||||
if (imageCache[url] === undefined) {
|
||||
let fetchResult = await fetch(url, {
|
||||
const fetchResult = await fetch(url, {
|
||||
signal: abortController.signal
|
||||
});
|
||||
if (currentUpdateIndex !== myUpdateIndex) {
|
||||
hideLoading()
|
||||
break
|
||||
}
|
||||
let imageBlob = await fetchResult.blob()
|
||||
const imageBlob = await fetchResult.blob()
|
||||
imageCache[url] = URL.createObjectURL(imageBlob)
|
||||
}
|
||||
const imageLayer = new Image()
|
||||
|
@ -224,14 +224,14 @@ async function updateTime(newPeriod = currentPeriod, newVariation = currentVaria
|
|||
for ( var atlasIndex in atlasAll ) {
|
||||
let pathChosen, centerChosen, chosenIndex
|
||||
|
||||
let validPeriods2 = Object.keys(atlasAll[atlasIndex].path)
|
||||
const validPeriods2 = Object.keys(atlasAll[atlasIndex].path)
|
||||
|
||||
// console.log(chosenIndex)
|
||||
|
||||
for (let i in validPeriods2) {
|
||||
let validPeriods = validPeriods2[i].split(', ')
|
||||
for (let j in validPeriods) {
|
||||
let [start, end, variation] = parsePeriod(validPeriods[j])
|
||||
for (const i in validPeriods2) {
|
||||
const validPeriods = validPeriods2[i].split(', ')
|
||||
for (const j in validPeriods) {
|
||||
const [start, end, variation] = parsePeriod(validPeriods[j])
|
||||
// console.log(start, end, variation, newPeriod, newVariation)
|
||||
if (isOnPeriod(start, end, variation, newPeriod, newVariation)) {
|
||||
// console.log("match", start, end, variation, newPeriod, newVariation, i)
|
||||
|
@ -285,7 +285,7 @@ function parsePeriod(periodString) {
|
|||
let variation = "default"
|
||||
periodString = periodString + ""
|
||||
if (periodString.split(':').length > 1) {
|
||||
let split = periodString.split(':')
|
||||
const split = periodString.split(':')
|
||||
variation = codeReference[split[0]]
|
||||
periodString = split[1]
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ function parsePeriod(periodString) {
|
|||
var [start, end] = periodString.split('-').map(i => parseInt(i))
|
||||
return [start, end, variation]
|
||||
} else {
|
||||
let periodNew = parseInt(periodString)
|
||||
const periodNew = parseInt(periodString)
|
||||
return [periodNew, periodNew, variation]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -558,12 +558,12 @@ async function render(){
|
|||
context.drawImage(backgroundCanvas, 0, 0);
|
||||
|
||||
if(hovered.length === 1 && hovered[0].path.length && hovered[0].overrideImage){
|
||||
let undisputableHovered = hovered[0];
|
||||
const undisputableHovered = hovered[0];
|
||||
// Find the left-topmost point of all the paths
|
||||
let entryPosition = getPositionOfEntry(undisputableHovered);
|
||||
const entryPosition = getPositionOfEntry(undisputableHovered);
|
||||
if(entryPosition){
|
||||
const [startX, startY] = entryPosition;
|
||||
let overrideImage = new Image();
|
||||
const overrideImage = new Image();
|
||||
const loadingPromise = new Promise((res, rej) => {
|
||||
overrideImage.onerror = rej;
|
||||
overrideImage.onload = res;
|
||||
|
@ -691,7 +691,7 @@ function highlightEntryFromUrl(){
|
|||
});
|
||||
|
||||
if (entries.length === 1){
|
||||
let entry = entries[0];
|
||||
const entry = entries[0];
|
||||
|
||||
document.title = entry.name + " on the 2022 /r/place Atlas";
|
||||
|
||||
|
|
Loading…
Reference in a new issue