-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (110 loc) · 4.79 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>World Editor</title>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<h1>World Editor</h1>
<canvas id="myCanvas"></canvas>
<div id="controls">
<button onclick="dispose()">🗑️</button>
<button onclick="save()">💾</button>
<button id="graphBtn" onclick="setMode('graph')">🌐</button>
<button id="stopBtn" onclick="setMode('stop')">🛑</button>
<button id="yieldBtn" onclick="setMode('yield')">⚠️</button>
<button id="crossingBtn" onclick="setMode('crossing')">🚶</button>
<button id="parkingBtn" onclick="setMode('parking')">🅿️</button>
<button id="lightBtn" onclick="setMode('light')">🚦</button>
<button id="startBtn" onclick="setMode('start')">🚙</button>
<button id="targetBtn" onclick="setMode('target')">🎯</button>
</div>
<script src="js/world.js"></script>
<script src="js/viewport.js"></script>
<script src="js/markings/marking.js"></script>
<script src="js/markings/stop.js"></script>
<script src="js/markings/start.js"></script>
<script src="js/markings/crossing.js"></script>
<script src="js/markings/parking.js"></script>
<script src="js/markings/light.js"></script>
<script src="js/markings/target.js"></script>
<script src="js/markings/yield.js"></script>
<script src="js/editors/markingEditor.js"></script>
<script src="js/editors/graphEditor.js"></script>
<script src="js/editors/crossingEditor.js"></script>
<script src="js/editors/stopEditor.js"></script>
<script src="js/editors/startEditor.js"></script>
<script src="js/editors/parkingEditor.js"></script>
<script src="js/editors/lightEditor.js"></script>
<script src="js/editors/targetEditor.js"></script>
<script src="js/editors/yieldEditor.js"></script>
<script src="js/items/tree.js"></script>
<script src="js/items/building.js"></script>
<script src="js/math/utils.js"></script>
<script src="js/math/graph.js"></script>
<script src="js/primitives/point.js"></script>
<script src="js/primitives/segment.js"></script>
<script src="js/primitives/polygon.js"></script>
<script src="js/primitives/envelope.js"></script>
<script>
myCanvas.width = 600;
myCanvas.height = 600;
const ctx = myCanvas.getContext("2d");
const graphString = localStorage.getItem("graph");
const graphInfo = graphString ? JSON.parse(graphString) : null;
const graph = graphInfo
? Graph.load(graphInfo)
: new Graph();
const world = new World(graph);
const viewport = new Viewport(myCanvas);
const tools = {
graph: { button: graphBtn, editor: new GraphEditor(viewport, graph) },
stop: { button: stopBtn, editor: new StopEditor(viewport, world) },
crossing: { button: crossingBtn, editor: new CrossingEditor(viewport, world) },
start: { button: startBtn, editor: new StartEditor(viewport, world) },
parking: { button: parkingBtn, editor: new ParkingEditor(viewport, world) },
light: { button: lightBtn, editor: new LightEditor(viewport, world) },
target: { button: targetBtn, editor: new TargetEditor(viewport, world) },
yield: { button: yieldBtn, editor: new YieldEditor(viewport, world) },
};
let oldGraphHash = graph.hash();
setMode("graph");
animate();
function animate() {
viewport.reset();
if (graph.hash() != oldGraphHash) {
world.generate();
oldGraphHash = graph.hash();
}
const viewPoint = scale(viewport.getOffset(), -1);
world.draw(ctx, viewPoint);
ctx.globalAlpha = 0.3;
for (const tool of Object.values(tools)) {
tool.editor.display();
}
requestAnimationFrame(animate);
}
function dispose() {
tools["graph"].editor.dispose();
world.markings.length = 0;
}
function save() {
localStorage.setItem("graph", JSON.stringify(graph));
}
function setMode(mode) {
dissableEditors();
tools[mode].button.style.backgroundColor = "white";
tools[mode].button.style.filter = "";
tools[mode].editor.enable();
}
function dissableEditors() {
for (const tool of Object.values(tools)) {
tool.button.style.backgroundColor = "gray";
tool.button.style.filter = "grayscale(100%)";
tool.editor.disable();
}
}
</script>
</body>
</html>