forked from HENRYMARTIN5/Clarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditrv2.js
89 lines (71 loc) · 2.72 KB
/
editrv2.js
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
// Abandon hope, all ye who enter here
function init() {
createHiDPICanvas = function () {
let cv = document.createElement("canvas");
cv.width = window.innerWidth;
cv.height = window.innerHeight;
cv.style.width = window.innerWidth + "px";
cv.style.height = window.innerHeight + "px";
cv.id = "editrCanvas";
return cv;
}
readjustCanvas = function (canvas) {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";
game.set_viewport(canvas.width, canvas.height);
}
generateBlockSelectors = function () {
var tileBar = document.querySelector("#tileSelectBar");
var order = [2, 6, 1, 23, 24, 5, 4, 13, 17, 18, 9, 3, 12, 15, 14, 10, 11, 20, 16, 8];
var keys = [];
order.forEach(orderNum => {
keys.push(window.map.keys[orderNum])
})
keys.forEach(tile => {
if (tile.blockname) {
if (tile.img) {
var base64img = tile.img.src;
var htmlImg = `
<img src="{src}" class="tileOption unselected" onmouseover="tooltip('{tilename}', this);" onclick="select({id}, this);" onmouseleave="untooltip(this);" id="selectBlock{id}">
`.replace("{src}", base64img).replace("{id}", tile.id).replace("{id}", tile.id).replace("{tilename}", tile.blockname);
tileBar.innerHTML = tileBar.innerHTML + htmlImg;
} else {
return;
}
}
});
}
//Create canvas with the device resolution.
var canvas = createHiDPICanvas();
ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
generateBlockSelectors();
window.game = new Clarity();
game.set_viewport(canvas.width, canvas.height);
game.load_map(window.map);
// User controls the viewport with WASD. Viewport shan't be limited.
game.limit_viewport = false;
canvas.addEventListener('mousemove', function (evt) {
game.update_mouse(canvas, evt);
}, false);
canvas.addEventListener('mousedown', function (evt) {
game.onClick(evt);
});
canvas.addEventListener('mouseup', function (evt) {
game.onReleaseClick(evt);
});
window.addEventListener('resize', function () {
readjustCanvas(canvas);
}, false);
var Loop = function () {
ctx.fillStyle = '#111';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw the game
game.update();
game.draw(ctx);
};
window.renderInterval = setInterval(Loop, 16.7);
}
init();