forked from FinalFactoryStation/FinalFactoryHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbp-image.html
More file actions
265 lines (218 loc) · 7.07 KB
/
Copy pathbp-image.html
File metadata and controls
265 lines (218 loc) · 7.07 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html>
<head>
<title>Blueprint Drawing thingy</title>
<style>
.container {
width: 90%;
margin: 0 auto;
padding: 0 20px;
}
canvas {
border: 1px solid black;
}
.canvas-container {
width: 100%;
text-align: center;
}
.canvas-container canvas {
/* position: absolute; */
top: 0;
left: 0;
margin: 0 auto;
}
#blueprint-textbox {
resize: none;
outline: none;
width: 100%;
}
#tooltip {
z-index: 999;
background-color: #fff;
border: 1px solid #ccc;
padding: 10px;
font-family: Arial, sans-serif;
font-size: 14px;
color: #333;
overflow-y: scroll;
margin-bottom: 20px;
max-height: 80px;
}
.tab {
display: flex;
flex-direction: row;
align-items: flex-start;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab-links {
display: flex;
flex-direction: column;
}
.tab-link {
display: block;
padding: 10px;
margin-bottom: 5px;
border: 1px solid #ccc;
border-right: none;
background-color: #f1f1f1;
text-decoration: none;
color: #000;
}
.tab-link:hover {
background-color: #ddd;
}
.tab-link.active {
background-color: #ccc;
}
.tab-content {
flex-grow: 1;
padding: 0px;
border: 1px solid #ccc;
border-left: none;
}
.tab-pane {
display: none;
}
.tab-pane.active {
display: block;
}
.tab-tabs {
overflow-y: scroll;
height: 160px;
}
.groups {
font-size: 16px;
line-height: 1.8;
padding: 10px;
margin: auto;
border: 1px solid #ccc;
background-color: #f9f9f9;
}
</style>
<script>
window.addEventListener('DOMContentLoaded', () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const bpValue = urlParams.get('bp');
const blueprintTextbox = document.getElementById('blueprint-textbox');
blueprintTextbox.value = bpValue;
});
</script>
</head>
<body>
<div class="container">
<form action="" method="get">
<label for="blueprint-textbox">Blueprint:</label><br>
<textarea id="blueprint-textbox" rows="10" cols="50" name="bp"></textarea><br>
<button id="draw-button" type="submit">Draw Blueprint</button>
</form>
<br>
<div>
<div class="tab">
<div class="tab-tabs">
<div class="tab-links"></div>
</div>
<div class="tab-content"></div>
</div>
<div class="canvas-container">
<canvas id="myCanvas" width="500" height="500"></canvas>
</div>
</div>
</div>
<script type="module">
import { InteractiveBlueprint } from "./blueprint-interactive.js";
import { styles } from "./constants.js";
const canvas = document.getElementById('myCanvas');
const queryParams = new URLSearchParams(window.location.search);
const bps = queryParams.get('bp');
// Size of HTML document (same as pageHeight/pageWidth in screenshot).
var win = window,
doc = document,
docElem = doc.documentElement,
body = doc.getElementsByTagName('body')[0],
h = win.innerWidth || docElem.clientWidth || body.clientWidth,
w = win.innerHeight || docElem.clientHeight || body.clientHeight;
console.log(`${h} x ${w}`);
const blueprint = await InteractiveBlueprint.create(bps, canvas, w, h*.8);
blueprint.styleConnections({
fill: "midnightblue"
})
blueprint.style(styles.DEFAULT_ITEM)
blueprint.addEventListener("itemover", e => {
blueprint.styleItem(e.detail.item, styles.HIGHLIGHT_ITEM);
});
blueprint.addEventListener("itemout", e => {
blueprint.styleItem(e.detail.item, styles.DEFAULT_ITEM);
});
// const view = await drawBoxes(canvas, blueprint5);
// view.addEventListener("mouseover", e => {
// console.log(e.item);
// console.log(e.station);
// });
// view.addEventListener("mouseout", e => {
// console.log(e.item);
// console.log(e.station);
// });
// Get the tab links and tab content elements
var tabLinks = document.querySelector('.tab-links');
var tabContent = document.querySelector('.tab-content');
let index = 0;
for (let station of blueprint.stations) {
// Create a button element for the tab link
var link = document.createElement('button');
link.setAttribute('class', 'tab-link');
link.setAttribute('data-group', 'Structure ' + (index + 1));
link.textContent = 'Structure ' + (index + 1);
tabLinks.appendChild(link);
// Create a div element for the tab pane
var pane = document.createElement('div');
pane.setAttribute('class', 'tab-pane');
pane.setAttribute('data-group', 'Structure ' + (index + 1));
pane.innerHTML = `
<div class="groups">Structure: <span id="group">Structure ${index + 1}</span><br />
Contains: <span id="contains">${station.size} stations.</span><br />
Stability. Cost: <span id="stability-cost">${station.totalStabilityCost}</span>, Conferred: <span id="stability-conferred">${station.totalStabilityConferred}</span> <strong>(This does not account for struct or artifacts!)</strong><br />
Power Consumption. Idle: <span id="power-consumption-idle">${station.totalPowerIdle}</span>, Max: <span id="power-consumption-max">${station.totalPowerMax}</span>, Produced: <span id="power-produced">${station.totalPowerProduced}</span><br />
Heat Rate: <span id="heat-rate">${station.totalHeatRate}</span>
</div>`;
tabContent.appendChild(pane);
index += 1;
};
// Get all tab links and tab panes
var tabLinks = document.querySelectorAll('.tab-link');
var tabPanes = document.querySelectorAll('.tab-pane');
// Loop through each tab link and add a click event listener
tabLinks.forEach(function (link) {
link.addEventListener('click', function () {
// Get the data-group value of the clicked tab link
var group = link.getAttribute('data-group');
// Loop through each tab pane and hide/show them as necessary
tabPanes.forEach(function (pane) {
if (pane.getAttribute('data-group') === group) {
pane.classList.add('active');
} else {
pane.classList.remove('active');
}
});
// Loop through each tab link and set/remove the active class as necessary
tabLinks.forEach(function (otherLink) {
if (otherLink === link) {
otherLink.classList.add('active');
} else {
otherLink.classList.remove('active');
}
});
});
});
tabLinks[0].click();
// This is how you can return an image of the canvas with the images rendered. Needed for the bot.
// await view.promise;
// const dataURL = canvas.toDataURL("image/png");
// body = document.body;
// const img = new Image();
// img.src = dataURL;
// body.appendChild(img);
</script>
</body>
</html>