-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiScript.js
127 lines (102 loc) · 3.5 KB
/
uiScript.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { setDT } from "./constant.js"
import { saveState,restoreState } from "./canvas.js"
let itemList = document.getElementsByClassName("item")
let subItemList = document.getElementsByClassName("subItemConfig")
let saveStateButton = document.getElementById("saveState")
let restoreStateButton = document.getElementById("restoreState")
let selected = -1
let subSelected = -1
let currentObj;
let gravSwitch = document.getElementById("checkgrav")
let fricSwitch = document.getElementById("checkfric")
let staticSwitch = document.getElementById("checkstatic")
let trajectorySwitch = document.getElementById("checktrajectory")
let VX = document.getElementById("VX")
let VY = document.getElementById("VY")
let previousDT = 0
document.body.onkeyup = function(e) {
if (e.key == " " ||
e.code == "Space" ||
e.keyCode == 32
) {
if (previousDT == 0) {
previousDT = setDT(0)
if(previousDT!= 0 && previousDT != 1) previousDT = 1
} else {
previousDT = setDT(1)
if(previousDT!= 0 && previousDT != 1) previousDT = 0
}
}
}
for(let i = 0; i < itemList.length; i++){
itemList[i].onmousedown = function () {
if(selected == i) return
itemList[i].classList.add("selected")
if (selected != -1) itemList[selected].classList.remove("selected")
selected = i
return true;
};
}
for(let i = 0; i < subItemList.length; i++){
subItemList[i].onmousedown = function () {
if(subSelected == i) return
subItemList[i].classList.add("selected")
if (subSelected != -1) subItemList[subSelected].classList.remove("selected")
subSelected = i
return true;
};
}
gravSwitch.onclick = function (){
if (currentObj){
if(gravSwitch.checked) currentObj.gravity = currentObj.defaultGravity
else currentObj.gravity = 0
}
return true;
}
fricSwitch.onclick = function (){
if (currentObj){
if(fricSwitch.checked) currentObj.friction = currentObj.defaultFriction
else currentObj.friction = 0
}
return true;
}
staticSwitch.onclick = function (){
if (currentObj){
if(staticSwitch.checked) currentObj.static = true
else currentObj.static = false
}
return true;
}
trajectorySwitch.onclick = function() {
if (currentObj) {
if (trajectorySwitch.checked) currentObj.trajectory = true
else currentObj.trajectory = false
}
return true;
}
saveStateButton.onclick = function(){
saveState()
}
restoreStateButton.onclick = function(){
restoreState()
}
function toggleTab(obj){
currentObj = obj
let controlTab = document.getElementById("control")
if(!controlTab.classList.contains("control-open")){
controlTab.classList.remove("control-close")
controlTab.classList.add("control-open")
let controlTabName = document.getElementById("control-name")
controlTabName.textContent = obj.name
gravSwitch.checked = obj.gravity!=0
fricSwitch.checked = obj.friction!=0
staticSwitch.checked = obj.static
trajectorySwitch.checked = obj.trajectory
VX.textContent = "VX : " + obj.vx.toFixed(1)
VY.textContent = "VY : " + obj.vy.toFixed(1)
}else{
controlTab.classList.remove("control-open")
controlTab.classList.add("control-close")
}
}
export { selected, subSelected, toggleTab}