Repository navigation
Expand file tree
/
Copy patheditor.js
More file actions
163 lines (141 loc) · 4.61 KB
/
Copy patheditor.js
File metadata and controls
163 lines (141 loc) · 4.61 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
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
162
163
"use strict";
let b_first=false;
let first = undefined;
let second = undefined;
let input= [];
let selection= [];
function refreshBackground(selection) {
console.log("state",state);
for (var x=0 ; x !== 21; x++) {
for (var y=0; y !== 21; y++) {
var el=document.getElementById(x.toString()+"_"+y.toString());
if (state == "firstChosen") {
//console.log("aqui",[y,x],first); // TODO: investaigate wht reverse
if (x== first[0] && y == first[1]) {
console.log("sdfjhkjsdfjhkdk");
el.style.backgroundColor = "red";
} else {
el.style.backgroundColor = "white";
}
} else {
if (some_selected(selection)) {
if(selection[x][y]) {
el.style.backgroundColor ="green";
}
else {
el.style.backgroundColor ="white";
}
}
}
}
}
}
function some_selected(selection) {
for (var x=0 ; x !==21 ; x++) {
for (var y=0;y !== 21; y++) {
if(selection[x][y]) {
return true;
}
}
}
return false;
}
function create_json(input, selection) {
var result = []
for (var x=0 ; x !==21; x++) {
for (var y=0; y !=21; y++) {
if(some_selected(selection)) {
if( selection[x][y] ){
result.push([x,y,input[x][y]]);
}
} else {
result.push([x,y,input[x][y]]);
}
}
}
return result;
}
let state = "norect";
function constructor(square,input,selection,xx,yy) {
return function(event) {
const select_mode = document.getElementById("select_mode").checked;
const rectangle = document.getElementById("rectangle").checked;
console.log(select_mode, rectangle);
if (!select_mode) {
change_square(square,input,xx,yy);
} else {
if (rectangle) {
if (state==="norect") {
state = "firstChosen";
first=[xx,yy];
selection = [];
for(var x =0; x!==21; x++) {
input.push([]);
selection.push([]);
}
} else {
state = "secondChosen";
second=[xx,yy];
let max_y = Math.max(first[1],second[1]);
let min_y = Math.min(first[1],second[1]);
let max_x = Math.max(first[0],second[0]);
let min_x = Math.min(first[0],second[0]);
for (var x=0 ; x !==21; x++) {
for (var y=0; y !== 21; y++) {
selection[x][y] = false;
}
}
for (var x=min_x; x <= max_x; x++) {
for (var y=min_y; y <= max_y; y++) {
selection[x][y] = true;
}
}
state="norect"
}
} else {
selection[xx][yy] = !selection[xx][yy];
}
}
refreshBackground(selection);
document.getElementsByTagName("pre")[0].textContent= "'"+JSON.stringify({
point_list:create_json(input,selection),
size: 21,
symetries: true,
color_exact: false,
})+"'";
}
};
for(var x =0; x!==21; x++) {
input.push([]);
selection.push([])
for (var y = 0; y!== 21; y++) {
input[x][y] = (x===0 || x===20 || y === 0|| y===20) ? " Z ": " - ";
selection[x][y] = false;
var square = document.getElementById(x.toString()+'_'+y.toString());
refresh(input,x,y);
square.addEventListener('click',constructor(square, input, selection,x, y));
}
}
function change_square(square, input, x, y) {
var r;
switch( input[x][y]) {
case " - ":
r = ' X ';
break;
case " X ":
r= ' O ';
break;
case " O ":
r = " - ";
break;
case " Z " :
r=" Z ";
break;
}
input[x][y] = r;
refresh(input,x,y);
}
function refresh(input, x, y) {
let square = document.getElementById( x.toString()+"_"+y.toString());
square.innerHTML = input[x][y];
}