-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (161 loc) · 6.65 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
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
<!DOCTYPE html>
<html>
<head>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>-->
<script src="src/vendor/phaser.min.js"></script>
<script src="src/vendor/hammer.min.js"></script>
<link rel="shortcut icon" href="favicon.gif" />
</head>
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
<script>
window.addEventListener('resize', changeGameSize);
const config = {
type: Phaser.AUTO,
width: document?.documentElement?.clientWidth || window?.innerWidth || 1920,
height: document?.documentElement?.clientHeight || window?.innerHeight || 1200,
scene: { preload, create, update },
};
const game = new Phaser.Game(config);
let controls;
const view = {
isDragged: false,
lastX: 0, lastY: 0,
};
function preload ()
{
//this.load.setBaseURL('http://labs.phaser.io');
// the current solution is to just manually copy it so I don't have to start
// a REAL webserver, as http-server serves .plan as a base64 encoded "image"
this.load.text('adhd_plan', 'main_plan.plan.json');
}
function create ()
{
console.log('create start');
// this.add.text(100, 200, 'this is a test', {color: "white"});
let almostJson = this.cache.text.get('adhd_plan');
console.log('broken json get');
// we need to add an idiotic footer because MasterPlan writes an invalid JSON to optimize seven microseconds of disk operations
almostJson = almostJson + '{"IGNORE": 1}]}';
const planFile = JSON.parse(almostJson);
console.log('json get');
if (!planFile.Tasks) {
this.add.text(100, 150, 'Fatal error while loading JSON plan file.', {color: "#FF5555"});
}
// TODO make a planFile.BoardNames selector
const currentBoardNumber = 0;
const noteTextProps = {
fontFamily: 'segoe ui,roboto,oxygen,ubuntu,cantarell,fira sans,droid sans,helvetica neue,sans-serif',
fontSize: 12,
color: 'white'};
this.add.text(0, 0, planFile.BoardNames[0], {color: "#8899EE", fontFamily: noteTextProps.fontFamily, fontSize: 24});
const texts = [];
const borders = [];
const arrows = [];
const borderPx = 4;
planFile.Tasks.filter(item => {
return item.BoardIndex == currentBoardNumber;
}).map(item => {
let [x, y, taskType, desc] = [
item["Position.X"],
item["Position.Y"],
item["TaskType.CurrentChoice"],
item["Description"],
];
if (taskType === 2) {
// type note
let text1 = this.add.text(x, y, desc, noteTextProps);
// text1.setFontSize(11);
texts.push(text1);
let rekt = this.add.rectangle(x + (text1.width/2) , y + (text1.height/2),
text1.width + (borderPx * 4), text1.height + (borderPx * 4), 0x333399);
rekt.setStrokeStyle(2, 0x1a65ac);
rekt.setDepth(-1000);
borders.push(rekt);
}
else if (taskType === 6) {
// type arrow
const [x2, y2] = [item.LineEndings[0], item.LineEndings[1]];
const line = this.add.graphics();
line.lineStyle(4, 0x2ECC40);
line.beginPath();
line.moveTo(x, y);
line.lineTo(x2, y2);
let angle = Math.atan2(y2 - y, x2 - x); //* (180 / Math.PI)
let angle1 = angle + 0.28;
let angle2 = angle - 0.28;
const arrLen = 30;
let [x3, y3] = [x2 - (Math.cos(angle1) * arrLen), y2 - (Math.sin(angle1) * arrLen)];
let [x4, y4] = [x2 - (Math.cos(angle2) * arrLen), y2 - (Math.sin(angle2) * arrLen)];
line.strokeTriangle(x2, y2, x3, y3, x4, y4);
line.closePath();
line.strokePath();
arrows.push(line);
}
});
console.log('create: processed all tasks');
this.input.on(Phaser.Input.Events.POINTER_WHEEL, handleZoom, this);
this.input.on('pointerup', handleDragEnd, this);
this.input.on('pointerdown', handleDragStart, this);
const key1 = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ONE);
const key2 = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.TWO);
const key3 = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.THREE);
key1.on('down', (key, event) => { this.cameras.main.setZoom(0.5); });
key2.on('down', (key, event) => { this.cameras.main.setZoom(1); });
key3.on('down', (key, event) => { this.cameras.main.setZoom(2); });
const cursors = this.input.keyboard.createCursorKeys();
const controlConfig = {
camera: this.cameras.main,
left: cursors.left,
right: cursors.right,
up: cursors.up,
down: cursors.down,
acceleration: 0.04,
drag: 0.0011,
maxSpeed: 1.2
};
controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
this.cameras.main.setBounds(-8192, -8192, 16384, 16384);
}
function update(_update, delta) {
controls.update(delta);
if (view.isDragged) {
const pointer = this.input.activePointer;
this.cameras.main.scrollX -= (pointer.position.x - view.lastX);
view.lastX = pointer.position.x;
this.cameras.main.scrollY -= (pointer.position.y - view.lastY);
view.lastY = pointer.position.y;
}
}
function handleZoom(event) {
if (event.deltaY > 0) {
this.cameras.main.setZoom(this.cameras.main.zoom * 90/100);
}
else if (event.deltaY < 0) {
this.cameras.main.setZoom(this.cameras.main.zoom * 100/90);
}
}
function handleDragStart(pointer) {
if (!pointer.button) {
view.isDragged = true;
view.lastX = pointer.downX;
view.lastY = pointer.downY;
}
}
function handleDragEnd() {
view.isDragged = false;
}
let gameResizeDelay;
function changeGameSize() {
if (!gameResizeDelay) {
gameResizeDelay = setTimeout(() => {
console.log('-------------- width ', document.documentElement.clientWidth, window.innerWidth);
console.log('-------------- height ', document.documentElement.clientHeight, window.innerHeight);
game.scale.resize(window.innerWidth, window.innerHeight);
clearTimeout(gameResizeDelay);
gameResizeDelay = 0;
}, 300);
}
}
</script>
</body>
</html>