1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-25 01:41:45 +00:00
The-Modding-Tree/js/canvas.js

122 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-08-19 02:50:24 +00:00
var canvas;
2020-08-25 22:42:43 +00:00
var ctx;
2020-08-19 02:50:24 +00:00
window.addEventListener("resize", (_=>resizeCanvas()));
function retrieveCanvasData() {
let treeCanv = document.getElementById("treeCanvas")
2020-08-25 22:42:43 +00:00
let treeTab = document.getElementById("treeTab")
2020-08-19 02:50:24 +00:00
if (treeCanv===undefined||treeCanv===null) return false;
2020-08-25 22:42:43 +00:00
if (treeTab===undefined||treeTab===null) return false;
2020-08-19 02:50:24 +00:00
canvas = treeCanv;
ctx = canvas.getContext("2d");
return true;
}
function resizeCanvas() {
if (!retrieveCanvasData()) return
canvas.width = 0;
canvas.height = 0;
2020-08-25 22:42:43 +00:00
canvas.width = document.getElementById("treeTab").scrollWidth;
canvas.height = document.getElementById("treeTab").scrollHeight;
2020-08-19 02:50:24 +00:00
drawTree();
}
2020-09-07 14:16:04 +00:00
var colors = {
2020-09-14 19:26:10 +00:00
default: {
1: "#ffffff",
2: "#bfbfbf",
3: "#7f7f7f",
},
aqua: {
2020-09-14 21:18:02 +00:00
1: "#bfdfff",
2: "#8fa7bf",
3: "#5f6f7f",
2020-09-14 19:26:10 +00:00
},
2020-09-07 14:16:04 +00:00
}
2020-09-14 19:26:10 +00:00
var colors_theme
2020-09-07 14:16:04 +00:00
2020-08-19 02:50:24 +00:00
function drawTree() {
if (!retrieveCanvasData()) return;
ctx.clearRect(0, 0, canvas.width, canvas.height);
2020-09-11 02:15:05 +00:00
if (layerShown('b')) drawTreeBranch("p", "b")
if (layerShown('g')) drawTreeBranch("p", "g")
if (layerShown('e')) {
2020-08-19 02:50:24 +00:00
drawTreeBranch("b", "e")
drawTreeBranch("g", "e")
}
2020-09-11 02:15:05 +00:00
if (layerShown('t')) drawTreeBranch("b", "t")
if (layerShown('sb')) drawTreeBranch("b", "sb")
if (layerShown('sg')) drawTreeBranch("g", "sg")
if (layerShown('s')) drawTreeBranch("g", "s")
if (layerShown('h')) drawTreeBranch("t", "h")
if (layerShown('q')) drawTreeBranch("e", "q")
if (layerShown('hb')) {
2020-08-29 23:43:53 +00:00
drawTreeBranch("sb", "hb")
drawTreeBranch("t", "hb")
}
2020-09-11 02:15:05 +00:00
if (layerShown('ss')) {
2020-08-29 23:43:53 +00:00
drawTreeBranch("e", "ss")
drawTreeBranch("s", "ss")
}
2020-09-11 02:15:05 +00:00
if (layerShown('hg')) {
2020-09-09 15:20:39 +00:00
drawTreeBranch("sg", "hg")
}
2020-09-11 02:15:05 +00:00
if (layerShown('m')) {
2020-09-03 21:59:23 +00:00
drawTreeBranch("hb", "m")
drawTreeBranch("h", "m")
2020-09-05 17:11:53 +00:00
drawTreeBranch("q", "m")
2020-09-03 21:59:23 +00:00
}
2020-09-11 02:15:05 +00:00
if (layerShown('ba')) {
2020-09-07 14:16:04 +00:00
drawTreeBranch("h", "ba", 2)
2020-09-03 21:59:23 +00:00
drawTreeBranch("q", "ba")
drawTreeBranch("ss", "ba")
}
2020-09-11 02:15:05 +00:00
if (layerShown('sp')) {
2020-09-07 02:33:31 +00:00
drawTreeBranch("m", "sp")
drawTreeBranch("ba", "sp")
}
2020-09-11 02:15:05 +00:00
if (layerShown('l')) {
2020-09-07 02:33:31 +00:00
drawTreeBranch("hb", "l")
drawTreeBranch("m", "l")
}
2020-09-11 02:15:05 +00:00
if (layerShown('ps')) {
2020-09-07 14:16:04 +00:00
drawTreeBranch("h", "ps", 3)
drawTreeBranch("q", "ps", 3)
2020-09-07 02:33:31 +00:00
}
2020-09-11 02:15:05 +00:00
if (layerShown('hs')) {
2020-09-07 02:33:31 +00:00
drawTreeBranch("ss", "hs")
drawTreeBranch("ba", "hs")
}
2020-09-11 02:15:05 +00:00
if (layerShown('i')) {
2020-09-07 02:33:31 +00:00
drawTreeBranch("ss", "i")
2020-09-13 02:38:32 +00:00
drawTreeBranch("sg", "i")
2020-09-07 02:33:31 +00:00
}
2020-09-11 02:15:05 +00:00
if (layerShown('mb')) {
2020-09-10 02:44:25 +00:00
drawTreeBranch("l", "mb")
drawTreeBranch("ps", "mb", 2)
}
2020-09-11 02:15:05 +00:00
if (layerShown('ge')) {
2020-09-10 02:44:25 +00:00
drawTreeBranch("sp", "ge")
}
2020-09-11 02:15:05 +00:00
if (layerShown('ma')) {
2020-09-10 02:44:25 +00:00
drawTreeBranch("hs", "ma")
drawTreeBranch("i", "ma")
}
2020-08-19 02:50:24 +00:00
needCanvasUpdate = false;
}
2020-09-07 14:16:04 +00:00
function drawTreeBranch(num1, num2, color_id = 1) { // taken from Antimatter Dimensions & adjusted slightly
2020-08-19 02:50:24 +00:00
let start = document.getElementById(num1).getBoundingClientRect();
let end = document.getElementById(num2).getBoundingClientRect();
2020-08-25 22:42:43 +00:00
let x1 = start.left + (start.width / 2) + (document.getElementById("treeTab").scrollLeft || document.body.scrollLeft);
let y1 = start.top + (start.height / 2) + (document.getElementById("treeTab").scrollTop || document.body.scrollTop);
let x2 = end.left + (end.width / 2) + (document.getElementById("treeTab").scrollLeft || document.body.scrollLeft);
let y2 = end.top + (end.height / 2) + (document.getElementById("treeTab").scrollTop || document.body.scrollTop);
2020-08-19 02:50:24 +00:00
ctx.lineWidth = 15;
ctx.beginPath();
2020-09-14 19:26:10 +00:00
ctx.strokeStyle = colors_theme[color_id]
2020-08-19 02:50:24 +00:00
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.stroke();
}