fix: unsafe connector rotation
This commit is contained in:
parent
9d79a6de7e
commit
dcc65516cd
1 changed files with 31 additions and 33 deletions
|
@ -156,7 +156,7 @@ function construct_AT(elem, tree) {
|
||||||
document.getElementById("atree-active").appendChild(active_tooltip);
|
document.getElementById("atree-active").appendChild(active_tooltip);
|
||||||
|
|
||||||
node_elem.addEventListener('click', function(e) {
|
node_elem.addEventListener('click', function(e) {
|
||||||
if (e.target !== this) {return;}
|
if (e.target !== this) {return;};
|
||||||
let tooltip = document.getElementById("atree-ab-" + node.display_name.replaceAll(" ", ""));
|
let tooltip = document.getElementById("atree-ab-" + node.display_name.replaceAll(" ", ""));
|
||||||
if (tooltip.style.display == "block") {
|
if (tooltip.style.display == "block") {
|
||||||
tooltip.style.display = "none";
|
tooltip.style.display = "none";
|
||||||
|
@ -165,7 +165,7 @@ function construct_AT(elem, tree) {
|
||||||
else {
|
else {
|
||||||
tooltip.style.display = "block";
|
tooltip.style.display = "block";
|
||||||
this.classList.add("atree-selected");
|
this.classList.add("atree-selected");
|
||||||
}
|
};
|
||||||
atree_toggle_state(node);
|
atree_toggle_state(node);
|
||||||
atree_update_connector();
|
atree_update_connector();
|
||||||
});
|
});
|
||||||
|
@ -194,7 +194,7 @@ function resolve_connector(pos, node) {
|
||||||
owners = owners.concat(i.owner);
|
owners = owners.concat(i.owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
owners = [...new Set(owners)]
|
owners = [...new Set(owners)];
|
||||||
|
|
||||||
let connect_elem = document.createElement("div");
|
let connect_elem = document.createElement("div");
|
||||||
|
|
||||||
|
@ -215,18 +215,18 @@ function resolve_connector(pos, node) {
|
||||||
function atree_same_row(node) {
|
function atree_same_row(node) {
|
||||||
for (let i of node.parents) {
|
for (let i of node.parents) {
|
||||||
if (node.display.row == atree_map.get(i).display.row) { return false; }
|
if (node.display.row == atree_map.get(i).display.row) { return false; }
|
||||||
}
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
// draw the connector onto the screen
|
// draw the connector onto the screen
|
||||||
function atree_render_connection() {
|
function atree_render_connection() {
|
||||||
for (let i of atree_connectors_map.keys()) {
|
for (let i of atree_connectors_map.keys()) {
|
||||||
if (atree_connectors_map.get(i).length != 0) {
|
if (atree_connectors_map.get(i).length != 0) {
|
||||||
document.getElementById("atree-row-" + i.split(",")[0]).children[i.split(",")[1]].appendChild(atree_connectors_map.get(i)[0].connector);
|
document.getElementById("atree-row-" + i.split(",")[0]).children[i.split(",")[1]].appendChild(atree_connectors_map.get(i)[0].connector);
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
// toggle the state of a node.
|
// toggle the state of a node.
|
||||||
function atree_toggle_state(node) {
|
function atree_toggle_state(node) {
|
||||||
|
@ -234,8 +234,8 @@ function atree_toggle_state(node) {
|
||||||
atree_map.get(node.display_name).active = false;
|
atree_map.get(node.display_name).active = false;
|
||||||
} else {
|
} else {
|
||||||
atree_map.get(node.display_name).active = true;
|
atree_map.get(node.display_name).active = true;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
// refresh all connector to default state, then try to calculate the connector for all node
|
// refresh all connector to default state, then try to calculate the connector for all node
|
||||||
function atree_update_connector() {
|
function atree_update_connector() {
|
||||||
|
@ -267,52 +267,50 @@ function atree_compute_highlight(node) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// get the current active state of different directions, given a connector coordinate.
|
// get the current active state of different directions, given a connector coordinate.
|
||||||
function atree_get_state(connector) {
|
function atree_get_state(connector) {
|
||||||
let connector_state = {left: 0, right: 0, up: 0, down: 0}
|
let connector_state = [0, 0, 0, 0]; // left, right, up, down
|
||||||
|
|
||||||
for (let abil_name of atree_connectors_map.get(connector)[0].owner) {
|
for (let abil_name of atree_connectors_map.get(connector)[0].owner) {
|
||||||
|
|
||||||
state = atree_map.get(abil_name).active;
|
state = atree_map.get(abil_name).active;
|
||||||
if (atree_map.get(abil_name).display.col > parseInt(connector.split(",")[1])) {
|
if (atree_map.get(abil_name).display.col > parseInt(connector.split(",")[1])) {
|
||||||
if (state) {
|
if (state) {
|
||||||
connector_state.right = 1;
|
connector_state[1] = 1;
|
||||||
} else if (!connector_state.right) {
|
} else if (!connector_state.right) {
|
||||||
connector_state.right = 0;
|
connector_state[1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atree_map.get(abil_name).display.col < parseInt(connector.split(",")[1])) {
|
if (atree_map.get(abil_name).display.col < parseInt(connector.split(",")[1])) {
|
||||||
if (state) {
|
if (state) {
|
||||||
connector_state.left = 1;
|
connector_state[0] = 1;
|
||||||
} else if (!connector_state.left) {
|
} else if (!connector_state.left) {
|
||||||
connector_state.left = 0;
|
connector_state[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atree_map.get(abil_name).display.row < parseInt(connector.split(",")[0])) {
|
if (atree_map.get(abil_name).display.row < parseInt(connector.split(",")[0])) {
|
||||||
if (state) {
|
if (state) {
|
||||||
connector_state.up = 1;
|
connector_state[2] = 1;
|
||||||
} else if (!connector_state.up) {
|
} else if (!connector_state.up) {
|
||||||
connector_state.up = 0;
|
connector_state[2] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atree_map.get(abil_name).display.row > parseInt(connector.split(",")[0])) {
|
if (atree_map.get(abil_name).display.row > parseInt(connector.split(",")[0])) {
|
||||||
if (state) {
|
if (state) {
|
||||||
connector_state.down = 1;
|
connector_state[3] = 1;
|
||||||
} else if (!connector_state.down) {
|
} else if (!connector_state.down) {
|
||||||
connector_state.down = 0;
|
connector_state[3] = 0;
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
console.log(connector_state)
|
|
||||||
return connector_state;
|
return connector_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a sequence of left, right, up, down to appropriate connector image
|
// parse a sequence of left, right, up, down to appropriate connector image
|
||||||
function atree_parse_connector(orient, type) {
|
function atree_parse_connector(orient, type) {
|
||||||
// left, right, up, down
|
// left, right, up, down
|
||||||
// todo
|
|
||||||
let c_connector_dict = {
|
let c_connector_dict = {
|
||||||
"1100": {attrib: "_2_l", rotate: 0},
|
"1100": {attrib: "_2_l", rotate: 0},
|
||||||
"1010": {attrib: "_2_a", rotate: 0},
|
"1010": {attrib: "_2_a", rotate: 0},
|
||||||
|
@ -325,23 +323,23 @@ function atree_parse_connector(orient, type) {
|
||||||
"1011": {attrib: "_3", rotate: 270},
|
"1011": {attrib: "_3", rotate: 270},
|
||||||
"0111": {attrib: "_3", rotate: 90},
|
"0111": {attrib: "_3", rotate: 90},
|
||||||
"1111": {attrib: "", rotate: 0}
|
"1111": {attrib: "", rotate: 0}
|
||||||
}
|
};
|
||||||
|
|
||||||
let t_connector_dict = {
|
let t_connector_dict = {
|
||||||
"1100": {attrib: "_2_l", rotate: 0},
|
"1100": {attrib: "_2_l", rotate: 0},
|
||||||
"1001": {attrib: "_2_a", rotate: "flip"},
|
"1001": {attrib: "_2_a", rotate: "flip"},
|
||||||
"0101": {attrib: "_2_a", rotate: 0},
|
"0101": {attrib: "_2_a", rotate: 0},
|
||||||
"1101": {attrib: "_3", rotate: 0}
|
"1101": {attrib: "_3", rotate: 0}
|
||||||
}
|
};
|
||||||
|
|
||||||
let res = ""
|
let res = "";
|
||||||
for (let i in orient) {
|
for (let i of orient) {
|
||||||
res += orient[i];
|
res += i;
|
||||||
}
|
};
|
||||||
|
|
||||||
if (type == "c") {
|
if (type == "c") {
|
||||||
return c_connector_dict[res];
|
return c_connector_dict[res];
|
||||||
} else {
|
} else {
|
||||||
return t_connector_dict[res];
|
return t_connector_dict[res];
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue