-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
94 lines (84 loc) · 2.73 KB
/
map.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
<!--
Web based map editor for tanki online
Copyright (C) 2023 Pyogenics <https://github.com/Pyogenics>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<html>
<head>
<title>Tanki map toolkit</title>
<link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css">
<style>
.hidden {
display: none !important;
}
</style>
</head>
<body>
<h1>!!Map tool placeholder text!!</h1>
<input type="file" accept=".xml" id="map-input"></input>
<canvas id="viewport" class="hidden"></canvas>
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"MapParser": "./scripts/map/MapParser.js",
"renderer": "./scripts/3d/view.js",
"three": "https://unpkg.com/three/build/three.module.js",
"threeTDSLoader": "https://unpkg.com/three/examples/jsm/loaders/TDSLoader.js"
}
}
</script>
<script type="module">
import { Map } from "MapParser";
import { Renderer } from "renderer";
import * as THREE from "three";
window.onload = init
function init()
{
console.log("Starting...");
const fileSubmit = document.getElementById("map-input");
fileSubmit.addEventListener("change", loadMap);
}
function loadMap(event)
{
console.log("Loading map");
const reader = new FileReader();
reader.addEventListener("load", parseMap);
reader.addEventListener("error", (event) => {
throw event.Error;
});
reader.readAsText(event.target.files[0]);
}
function parseMap(event)
{
const map = new Map();
map.parseFromString(event.target.result);
// Now hide the selection and continue to displaying the map
document.getElementById("map-input").classList.add("hidden");
document.getElementById("viewport").classList.remove("hidden");
showMap();
}
function showMap(map)
{
// Create renderer
const renderer = new Renderer();
renderer.bindToCanvas(document.getElementById("viewport"));
renderer.camera.position.z = 5;
// Add geometry
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
renderer.addObject(cube);
}
</script>
</body>
</html>