-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
98 lines (89 loc) · 2.81 KB
/
Copy pathscript.js
File metadata and controls
98 lines (89 loc) · 2.81 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
let inputHolder = document.getElementById('inputHolder')
let xSize
let ySize
let mapName
function submitSize(){
// Taking the input boxes and then galling Generate array
xSize = document.getElementById('xcount').value
ySize = document.getElementById('ycount').value //get array input
mapName = document.getElementById('name').value
if (xSize<=0 || ySize<=0 || mapName == ''){
alert('Invalid Inputs')
} else{
generateArray()
}
}
function generateArray(){
//Making the array of input fields
//And adding EvenListeners
if (xSize > 80 || ySize > 80){
if (window.confirm("Woah Buddy, that's a bigg ass number. Are you sure?") == false){
return
}
}
for (let i = 0; i < xSize;i++){
for (let j = 0; j < ySize;j++){
const emptyField = document.createElement('input')
emptyField.type = 'text'
emptyField.className = 'inputarray'
emptyField.maxLength = 2
emptyField.value = '0'
emptyField.style='display:span;'
emptyField.id = `field(x${i}y${j})`
console.log(`field(x${i}y${j})`)
inputHolder.append(emptyField)
}
inputHolder.append(document.createElement('br'))
}
// Changing the color if the box isnt = to 0 by adding a class
for (let x of inputHolder.childNodes){
x.addEventListener('change',(event)=>{
if (event.target.value != 0){
event.target.classList.add('greyBg')
}
if (event.target.value == 0){
event.target.classList.remove('greyBg')
}
})
}
}
function generateList(){
// build an array, then combine it into a group of arrays, then finish
// to a string
let currentArray = []
let combinedArray = []
let finaltext
let elements = inputHolder.children
for(let i = 0; i < elements.length;i++){
console.log(elements[i].nodeName)
if (elements[i].nodeName == 'INPUT'){
if (typeof(elements[i].value) == 'number'){
currentArray.push(elements[i].value)
console.log('num')
} else {
currentArray.push(`"${elements[i].value}"`)
}
}
if (elements[i].nodeName == 'BR'){
//break array when next line starts and add a new one
console.log(currentArray)
combinedArray.push(`[${currentArray.join(',')}]`)
currentArray = []
}
}
//finish the array building by joining the combinedArrays
finaltext = `[${combinedArray.join(',')}]`
//print to results
finaltext = `'${mapName}': ` + finaltext
document.getElementById('codeResult').innerText = finaltext
document.getElementById('codeResult').scrollIntoView({behavior: 'smooth'}) //After Generating smooth scroll to array
}
function resetGrid(){
let ans = window.confirm( `It's okay to clear this?`)
if (ans != true){
return
}
while (inputHolder.hasChildNodes()){
inputHolder.removeChild(inputHolder.firstChild)
}
}