-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHexes.html
141 lines (98 loc) · 3.79 KB
/
Hexes.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hexagonal Grid</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="hexes.css">
<link rel="stylesheet" href="travellerSubsector.css">
<script type ="module">
import subsectorMap from './travellerSubsector.js';
window.starmap = new subsectorMap();
</script>
<script>
"use strict";
function queueDisplayUpdate() {
window.starmap.buildSubSector(document.getElementById("fname").value)
// //let newSubsector = loadSubsector();
//
//
// let colCount = document.getElementById("cols").value;
// let rowCount = document.getElementById("rows").value;
//
//
// let hexContent = [];
// for (let curCol = 0; curCol < colCount; curCol+=1) {
// hexContent[curCol] = [];
// for(let curRow = 0; curRow < rowCount; curRow+=1) {
// hexContent[curCol][curRow] = `${(curCol < 9 ? '0' : '') + (curCol+1)}` + `${(curRow < 9 ? '0' : '')+(curRow+1)}`;
// }
// }
// drawHexes(hexContent);
drawHexes(window.starmap.getMap());
}
function drawHexes(hexArray) {
//takes an array of arrays (simulating a 2d array)
//first index is column (left to right)
//second index is row (top to bottom)
//content of each is the content of the hex
//first hex is offset up, second down, third up, etc.
//this uses the length of hexArray[0] as the secind dimension.
//Any longer arrays will be truncated, any shorter will have "undefined" in the hexes.
let padSize = 0.5;
let displayStuff = "";
let hexes = "";
let colCount = hexArray.length;
let rowCount = hexArray[0].length;
displayStuff += ":root {"
displayStuff += ` --colCount: ${colCount}; `
displayStuff += ` --rowCount: ${rowCount}; `
displayStuff += ` --padSize: ${padSize}; `
displayStuff += "}"
//hexes += `<h2> ${starmap.getName()} </h2>`;
hexes += `<ul class="hex-grid__list">`
for (let curCol = 0; curCol < colCount; curCol+=1) {
for(let curRow = 0; curRow < rowCount; curRow+=1) {
hexes += `<li class="hex-grid__item" style = "grid-area: ${(((curRow+1)*2) - ((curCol+1)%2) )} / ${(curCol*2)+1} / span 2 / span 3;">`;
hexes += `<div class="hex-grid__background">`;
hexes += `<div class="hex-grid__content">`
//hex numbers
hexes += `<div class="hex-grid__hexNums"> ${hexArray[curCol][curRow][0]}</div>`;
/*Add all the hex content in here.*/
if (hexArray[curCol][curRow][1][0]){
//systems
hexes += '<div class = "system"> ';
hexArray[curCol][curRow][1][0] += (Math.random() > 0.5) ? 1 : 0; // test only
hexes += (hexArray[curCol][curRow][1][0] ===2 ) ? "\u25CB" : "\u25CF"; //fix this. the "w" should be a filled circle for water planets (or vice versa)
hexes += ' </div>';
//starport
hexes += `<div class = "starport"> ${hexArray[curCol][curRow][1][1]} </div>`;
//navy base
hexes += (hexArray[curCol][curRow][1][2] === 1) ? '<div class = "navyBase"> \u2605</div>' : "";
//scout base
hexes += (hexArray[curCol][curRow][1][3] === 1) ? '<div class = "scoutBase"> \u25B2</div>' : "";
//gas giant
hexes += (hexArray[curCol][curRow][1][4] === 1) ? '<div class = "gasGiant"> \u25CF</div>' : "";
//System Name
hexes += `<div class = "sysName"> ${hexArray[curCol][curRow][1][5]} </div>`;
}
/*end of hex content*/
hexes += "</div></div></li>"
}
}
hexes += `</ul>`
document.getElementById("cssVars").innerHTML = displayStuff;
document.getElementById("hexlist").innerHTML = hexes;
}
</script>
</head>
<body>
<style id="cssVars">
<!--This will get replaced by the diplayUpdate function-->
</style>
<input type="text" id="fname" name="fname" value="The Wyldd"> <button type="button" onclick="queueDisplayUpdate()">Show Hex Map!</button>
<div id="hexlist">
<!--This will get replaced by the diplayUpdate function-->
</div>
</body>
</html>