-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame.js
More file actions
81 lines (73 loc) · 2.72 KB
/
game.js
File metadata and controls
81 lines (73 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function newObjectControl(planet) {
var dock = document.getElementById("game_objects");
// console.log(dock);
//declare elements
let obj = document.createElement("div");
obj.className = "object";
let l = document.createElement("label");
l.innerText = "►";
l.id = planet.label;
let ul = document.createElement("ul");
ul.style.display = "none"
ul.id = "characteristics";
let para = {"mass": `Mass (×10<sup>16</sup> kg) <input type='number' id='${planet.label}' value='${planet.mass/1e16}'>`,
"color": `Color <input type='color' id='${planet.label}' value='${planet.colour}'>`};
for (let p in para) {
let li = document.createElement("li");
li.id = p;
li.innerHTML = para[p];
ul.appendChild(li);
}
let b = `<button onclick='get_planet(${planet.label}).dead = true;$(this).parent().hide()'>Delete</button>`;
let t = `<input type="text" id="labelName" maxlength="14" value="Planet ${planet.label}">`
// add all the stuff to html
obj.appendChild(l);
// obj.appendChild(cb);
obj.appendChild(ul);
dock.appendChild(obj);
$(obj).append(t);
$(obj).append(b);
}
function toggling() {
$(".object label").off();
$(".object label").click(function () {
let t = $(this)[0].innerText;
if (t[0] == "▼") {
$(this)[0].innerText = "►";
try {
get_planet($(this)[0].id).highlighted = false;
} catch(err) {}
} else {
$(this)[0].innerText = "▼";
try {
get_planet($(this)[0].id).highlighted = true;
} catch(err) {}
}
$(" ~ #characteristics", this).slideToggle();
});
// settings
$(".object #mass").change(function () {
// console.log($("input", this)[0].value);
get_planet($("input", this)[0].id).set_mass($("input", this)[0].value * 1e16);
});
$(".object #color").change(function () {
// console.log($("input", this)[0].value);
get_planet($("input", this)[0].id).colour = $("input", this)[0].value;
});
}
$(document).ready(function () {
toggling();
// sun values
let mass_factor = 1e28;
$("#sun #mass input")[0].value = Math.round(sun.mass / mass_factor); // set value
$("#sun #mass input").change(function () { // on change do this
sun.mass = parseInt(this.value, 10) * mass_factor;
});
$("#sun #temp input")[0].value = Math.round(sun.temperature); // set value
$("#sun #temp input").change(function () { // on change do this
sun.temperature = parseInt(this.value, 10);
});
$(".overlay h2").click(function () {
$(".game_settings").slideToggle("slow");
});
});