forked from dmcoles/EstyJs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
esty2-gui.js
176 lines (150 loc) · 4.38 KB
/
esty2-gui.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
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
174
175
176
// main initialisation routines for EstyJs
// written by Darren Coles
"use strict";
var estyjs = null;
setTimeout(mouseLocked, 1250);
function reset() {
estyjs.reset();
}
function pauseResume() {
var running = estyjs.pauseResume();
if (running) {
document.querySelector("#btnPause span").innerHTML = "Pause";
}
else {
document.querySelector("#btnPause span").innerHTML = "Resume";
}
}
function tosSelected(evt) {
var files = evt.target.files;
if (files.length>0) {
if (files[0].name.lastIndexOf('.')!=-1) {
var ext = files[0].name.substr(files[0].name.lastIndexOf('.')).toLowerCase();
if (ext == '.img') {
estyjs.changeTOS(files[0]);
}
}
}
}
function fileSelected(evt) {
var files = evt.target.files;
if (files.length>0) {
if (files[0].name.lastIndexOf('.')!=-1) {
var ext = files[0].name.substr(files[0].name.lastIndexOf('.')).toLowerCase();
if (ext == '.sts') {
estyjs.openSnapshotFile(files[0]);
} else if (ext == '.st' || ext == '.msa') {
estyjs.openFloppyFile('A', files[0]);
} else if (ext == '.zip') {
estyjs.openZipFile('A', files[0]);
}
document.querySelector("#floppy-1").src = 'img/floppy-active.png';
}
}
}
function fileSelected2(evt) {
var files = evt.target.files;
if (files.length > 0) {
if (files[0].name.lastIndexOf('.') != -1) {
var ext = files[0].name.substr(files[0].name.lastIndexOf('.')).toLowerCase();
if (ext == '.sts') {
estyjs.openSnapshotFile(files[0]);
} else if (ext == '.st' || ext == '.msa') {
estyjs.openFloppyFile('B', files[0]);
} else if (ext == '.zip') {
estyjs.openZipFile('B', files[0]);
}
document.querySelector("#floppy-2").src = 'img/floppy-active.png';
}
}
}
function colorToggle() {
estyjs.setMonoMonitor(!estyjs.getMonoMonitor());
if (estyjs.getMonoMonitor()) {
document.querySelector("#screen").style.backgroundImage = "url('img/sm124-bg.png')";
} else {
document.querySelector("#screen").style.backgroundImage = "url('img/sm124-sc-bg.png')";
}
}
function soundToggle() {
var sound = estyjs.soundToggle();
if (sound) {
document.querySelector("#btnSound span").innerHTML = "Sound off";
}
else {
document.querySelector("#btnSound span").innerHTML = "Sound on";
}
}
function openFile(fname) {
estyjs.openFloppyFile('A', fname);
}
function openFileInDrive(fname,drive) {
estyjs.openFloppyFile(drive, fname);
}
function changeJoystick() {
estyjs.setJoystick($('#joystick').prop('checked'));
}
function changeShowPct() {
estyjs.setShowPct($('#showpct').prop('checked'));
}
function changeFrameskip() {
estyjs.setFrameskip($('#frameskip').prop('checked'));
}
function changeRamSize() {
estyjs.setMemory($('#ram').prop('checked'));
}
function lockMouse() {
estyjs.lockMouse();
}
function mouseLocked() {
var locked;
if (estyjs==null) {
locked = false;
} else {
locked = estyjs.getMouseLocked();
}
if (locked) {
document.querySelector("#btnLocked span").innerHTML = "Unlock";
}
else {
document.querySelector("#btnLocked span").innerHTML = "Lock";
}
setTimeout(mouseLocked, 250);
}
function fullScreen() {
const elem = document.getElementById("EstyJsOutput");
if (elem.requestFullscreen) {
elem.requestFullscreen();
}
}
function splashScreen(filename, callback) {
const elem = document.getElementById("EstyJsOutput");
const ctx = elem.getContext('2d');
const img = new Image();
img.src = filename;
ctx.fillStyle ="rgb(0 0 0)";
img.onload = () => {
var alpha = 0;
var da = 0.01;
function draw() {
alpha += da;
if (alpha > 1) {
da = -da;
alpha += da;
return setTimeout(draw, 1000);
}
ctx.globalAlpha = 1;
ctx.fillRect(0,0,elem.clientWidth, elem.clientHeight);
var dx = (elem.clientWidth-img.width)/2;
var dy = (elem.clientHeight-img.height)/2;
ctx.globalAlpha = alpha
if (alpha>0) {
ctx.drawImage(img, dx, dy);
requestAnimationFrame(draw);
} else {
setTimeout(callback, 1000);
}
}
setTimeout(draw, 1000);
}
}