2023-03-22 16:38:18 +01:00
|
|
|
/*!
|
|
|
|
* The 2022 r/place Atlas
|
|
|
|
* Copyright (c) 2017 Roland Rytz <roland@draemm.li>
|
|
|
|
* Copyright (c) 2022 Place Atlas contributors
|
|
|
|
* Licensed under AGPL-3.0 (https://place-atlas.stefanocoding.me/license.txt)
|
|
|
|
*/
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
function initOverlap() {
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-09 11:27:14 +02:00
|
|
|
window.renderBackground = renderBackground
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2023-03-19 10:07:44 +01:00
|
|
|
// const hovered = []
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
buildObjectsList(null, null)
|
|
|
|
renderBackground(atlas)
|
|
|
|
render()
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-10 11:28:27 +02:00
|
|
|
document.addEventListener('timeupdate', (event) => {
|
|
|
|
sortedAtlas = atlas.concat()
|
|
|
|
resetEntriesList(null, null)
|
2022-05-06 09:41:22 +02:00
|
|
|
renderBackground(sortedAtlas)
|
|
|
|
render()
|
2022-04-10 11:28:27 +02:00
|
|
|
})
|
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
applyView()
|
|
|
|
render()
|
|
|
|
updateLines()
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (window.location.hash) {
|
2022-05-06 09:41:22 +02:00
|
|
|
highlightEntryFromUrl()
|
2017-04-06 23:20:08 +02:00
|
|
|
}
|
|
|
|
|
2022-04-09 11:27:14 +02:00
|
|
|
function renderBackground(atlas) {
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.clearRect(0, 0, canvas.width, canvas.height)
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.fillStyle = "rgba(255, 255, 255, 1)"
|
|
|
|
backgroundContext.fillRect(0, 0, canvas.width, canvas.height)
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
for (let i = 0; i < atlas.length; i++) {
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
const path = atlas[i].path
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.beginPath()
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
if (path[0]) {
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.moveTo(path[0][0], path[0][1])
|
2017-04-06 23:20:08 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
for (let p = 1; p < path.length; p++) {
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.lineTo(path[p][0], path[p][1])
|
2017-04-06 23:20:08 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.closePath()
|
2017-04-06 23:20:08 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
backgroundContext.fillStyle = "rgba(0, 0, 255, 0.2)"
|
|
|
|
backgroundContext.fill()
|
2017-04-06 23:20:08 +02:00
|
|
|
}
|
2017-04-12 17:17:00 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
const pixels = backgroundContext.getImageData(0, 0, backgroundCanvas.width, backgroundCanvas.height).data
|
|
|
|
let blank = 0
|
2017-04-12 17:17:00 +02:00
|
|
|
|
2022-04-16 14:44:50 +02:00
|
|
|
for (let i = 0; i < pixels.length; i += 4) {
|
2023-03-17 18:30:33 +01:00
|
|
|
if (pixels[i] === 255) {
|
2022-05-06 09:41:22 +02:00
|
|
|
blank++
|
2017-04-12 17:17:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-19 07:03:49 +01:00
|
|
|
const blankPercentage = (blank / (canvasSize.x * canvasSize.y)) * 100
|
2022-04-16 15:29:31 +02:00
|
|
|
|
2022-05-06 09:41:22 +02:00
|
|
|
console.info(blank + " blank pixels, which are " + blankPercentage.toPrecision(4) + "% of the canvas (" + (100 - blankPercentage).toPrecision(4) + "% mapped)")
|
2017-04-06 23:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|