-
Notifications
You must be signed in to change notification settings - Fork 0
/
devs.js
161 lines (151 loc) · 5.29 KB
/
devs.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
function devminal(command) {
if (command.substring(0,"printImg(".length)=="printImg(") {
var imgurl=command.substring("printImg".length+1, command.length-1)
addlog("Loading image: "+ imgurl)
document.getElementById("loadimg").src=imgurl
document.getElementById("loadimg").parentElement.style.display="block"
}else if (command=="help") {
//Help log
devminal("clear")
addlog("This is the JuiceFruit virtual world programming language help")
addlog("-------Supported commands-------")
addlog("\nhelp\ndisplays this menu")
addlog("\nprintImg([image url])\nloads image to 3d projector")
addlog("\nclear\nclears the screen")
addlog("\ninfo\nprints information about JFVW")
}else if (command=="clear") {
document.getElementById("consolelog").value=""
}else if (command=="info") {
devminal("clear")
addlog("----------Info----------")
addlog("3D-resolution: 2x2")
addlog("Version: " + version)
}else if (command.substring(0,"createElement{".length)=="createElement{") {
var elementData=command.substring("createElement{".length, command.length-1).replace(/\n/g, "").split(";")
var newelement=document.createElement("div")
for (var i=0; i+1 < elementData.length; i++) {
if (elementData[i].split(":").length==2) {
var attribute=elementData[i].split(":") [0]
var value=elementData[i].split(":") [1]
if (value.charAt(0)==" ") {
value=value.substring(1,value.length)
}
if (attribute.charAt(0)==" ") {
attribute=attribute.substring(1,attribute.length)
}
if (attribute=="width") {
newelement.style.width=value
}
if (attribute=="height") {
newelement.style.height=value
}
if (attribute=="bg-color") {
newelement.style.backgroundColor=value
}
if (attribute=="text-color") {
newelement.style.color=value
}
if (attribute=="top") {
newelement.style.top=value
}
if (attribute=="left") {
newelement.style.left=value
}
if (attribute=="bottom") {
newelement.style.bottom=value
}
if (attribute=="right") {
newelement.style.right=value
}
if (attribute=="id") {
projectorIds.push([value, projectorElements.length])
}
}else{
console.log("error")
addlog("Syntax error: no value for \"" + elementData[i].split(":") [0]+"\"")
}
}
newelement.style.position="absolute"
projectorElements.push(newelement)
}else{
//If an unknown command
addlog("Unknown command: "+ command)
}
}
function devc(event) {
if (event.keyCode==13) {
devminal(document.getElementById("command").value)
document.getElementById("command").value=""
}
}
function runpr(num) {
addlog("Running:" + testpr[num])
var commands=testpr2[num].split("\n")
for (var i=0; i < commands.length; i++) {
devminal(commands[i])
}
}
function addlog(text) {
var logel=document.getElementById("consolelog")
logel.value=logel.value+"\n"+text
logel.scrollTop=logel.scrollHeight
}
function resolutionTest(x,y) {
var resdiv=document.getElementById("resdiv")
resdiv.innerHTML=""
for (var i=0; i < x*y; i++) {
var newelement=document.createElement("span")
newelement.style.display="inline-block"
newelement.style.width=Math.floor(window.innerWidth / x) + "px"
newelement.style.height=Math.floor(window.innerHeight / y) + "px"
if (Math.floor(i/2)==i/2) {
newelement.style.backgroundColor="green"
}
resdiv.appendChild(newelement)
}
resdiv.style.display="block"
}
function balltest() {
document.getElementById('testdiv2').style.display='block'
document.body.style.backgroundColor="black"
document.getElementById("devdiv").style.display="none"
}
function closedev() {
document.getElementById("devbtn").style.display="block"
document.getElementById("devdiv").style.display="none"
}
function show3d() {
var el=document.getElementById("blockdiv")
if (el.style.display=="block") {
el.style.display="none"
}else{
el.style.display="block"
}
}
function showconsole() {
var el=document.getElementById("console")
if (el.style.display=="block") {
el.style.display="none"
}else{
el.style.display="block"
}
}
function showtests() {
var el=document.getElementById("programs")
if (el.style.display=="block") {
el.style.display="none"
}else{
el.style.display="block"
}
}
function changeprojector() {
if (projectormode==0) {
projectormode=1
}else{
projectormode=0
}
}
function createError(name="unknownError", message="Message is not defined!", url="unknown",linenumber="unknown") {
document.getElementById("errordiv").style.display="block"
document.getElementById("errordiv").innerHTML='<h1>ERROR: '+name+'</h1>Message: '+message+'\n<br>URL: '+url+'\n<br>Line Number: '+linenumber;
}