Skip to content

Commit 4c2cd6d

Browse files
Added more comments to footer-scripts.html
1 parent 46ee8d1 commit 4c2cd6d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

_includes/footer-scripts.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
<script>
44
// Code for the planet editor page. NEEDS CLEANING UP, SORRY
5+
6+
// If the page doesn't have a planetCanvas, its not the right page to be doing this JS on
7+
// (Hacky, I know, but it works...)
58
if (document.getElementById("planetCanvas")) {
6-
// Get elements from the DOM
9+
// Get elements for later
710
const canvas = document.getElementById('planetCanvas');
811
const ctx = canvas.getContext('2d');
912
const addPlanetBtn = document.getElementById('addPlanetBtn');
@@ -13,6 +16,7 @@
1316
const deletePlanetBtn = document.getElementById('deletePlanetBtn');
1417
const planetProperties = document.querySelector('.planet-properties');
1518

19+
// The input boxes are in a hidden div by default I think, but the are always there
1620
const xinput = document.getElementById("xinput")
1721
const yinput = document.getElementById("yinput")
1822
const zinput = document.getElementById("zinput")
@@ -43,7 +47,7 @@
4347
planetProperties.addEventListener("input", updatePlanet)
4448

4549

46-
// Add a planet with Minecraft coordinates
50+
// Add a planet with Minecraft coordinates 0, 0, 0
4751
function addPlanet() {
4852
const newPlanet = {
4953
x: 0,
@@ -86,11 +90,12 @@
8690

8791
console.log(planets, selectedPlanet)
8892

89-
93+
// They clicked on a planet, so they are now dragging it
9094
if (selectedPlanet) {
9195
openPropertiesMenu(selectedPlanet);
9296
updateProperties()
9397
isDraggingPlanet = true;
98+
// Else, they are trying to drag the canvas
9499
} else {
95100
planetProperties.style.display = 'none';
96101
// Start panning the canvas
@@ -108,6 +113,8 @@
108113
// Update planet Minecraft coordinates based on dragging
109114
selectedPlanet.x = mousePos.x - canvas.width / 2 + cameraOffsetX;
110115
selectedPlanet.z = mousePos.y - canvas.height / 2 + cameraOffsetY;
116+
117+
// To update the input boxes on the planets new position
111118
updateProperties()
112119
drawPlanets();
113120
} else if (isPanning) {
@@ -126,7 +133,7 @@
126133
isPanning = false;
127134
}
128135

129-
// Check if the mouse click is inside the square (planet)
136+
// Check if the mouse click is inside one of the square planets
130137
function isInsidePlanet(mousePos, planet) {
131138
const screenX = canvas.width / 2 + planet.x - cameraOffsetX;
132139
const screenY = canvas.height / 2 + planet.z - cameraOffsetY;
@@ -173,6 +180,7 @@
173180
}
174181
}
175182

183+
// Update menu inputs based on planet properties (for when planet is dragged or a new planet is selected)
176184
function updateProperties() {
177185
if (selectedPlanet) {
178186
xinput.value = selectedPlanet.x

0 commit comments

Comments
 (0)