-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAlliterative Programming.txt
1384 lines (1346 loc) · 47.3 KB
/
Alliterative Programming.txt
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Alliterative Programming
Open sidebar
Alliterative Programming
GPT-4
Is there away to embed my own font in a website html or javascript and display using it?
ChatGPT
Yes, you can embed custom fonts in your website to ensure that your text appears consistently across various devices and browsers. There are several methods to embed fonts, with the most popular being the use of
@font-face
rule in CSS. Here's how you can do it:
Acquire the Web Font
:
Ensure you have the rights to use the font on the web. Many font vendors sell web-specific licenses, or there are free web fonts available from sources like Google Fonts.
Prepare Font Files
:
For broad browser compatibility, you'll want your font in multiple formats like
.woff
,
.woff2
, and
.ttf
. Online converters are available if you only have one format.
Upload Font Files to Your Server
:
Place the font files in a directory on your web server. For this example, we'll assume you've put them in a directory called
fonts
.
Include the
@font-face
Rule in CSS
:
css
Copy code
@font-face
{
font-family
:
'MyCustomFont'
;
/* This is a name you choose */
src
:
url
(
'fonts/MyCustomFont.woff2'
)
format
(
'woff2'
),
url
(
'fonts/MyCustomFont.woff'
)
format
(
'woff'
),
url
(
'fonts/MyCustomFont.ttf'
)
format
(
'truetype'
);
/* Adjust paths accordingly */
font-weight
: normal;
font-style
: normal;
}
Use the Font in Your CSS
:
Once you've defined the font using
@font-face
, you can apply it to elements on your page:
css
Copy code
body
{
font-family
:
'MyCustomFont'
, sans-serif;
/* Use a fallback like sans-serif or serif */
}
Optimizing Performance
:
Subsetting
: If you're only using a small set of characters from a font, consider subsetting the font to include only those characters. This reduces the size of the font file.
Font Display
: Use
font-display
property with values like
swap
to ensure text remains visible during webfont loading.
css
Copy code
@font-face
{
font-family
:
'MyCustomFont'
;
src
:
url
(
'fonts/MyCustomFont.woff2'
)
format
(
'woff2'
);
font-display
: swap;
}
Test Across Different Browsers
:
Always test the appearance and loading of your font in different browsers to ensure consistency.
Consider Accessibility
:
Ensure that your font is readable and accessible. Some fonts might look fancy but could be hard to read for many users or in various contexts.
Remember: While it's tempting to use many custom fonts, each font adds to the page's load time. It's a best practice to limit the number of custom fonts for performance reasons.
It's for a video game. The font will be displayed in standard galactic alphabet and be toggled to Latin (or default) characters when you press z key.
ChatGPT
Creating a toggle effect for fonts, especially in the context of a video game, can be quite engaging for users. I'll provide a basic outline of how you can implement this in a web-based game using HTML, CSS, and JavaScript.
Prepare Your Fonts
:
Ensure you have a font that corresponds to the Standard Galactic Alphabet.
Ensure you have a font for the Latin characters (or you can use a default system font).
Include both using the
@font-face
rule as previously described.
HTML Structure
:
Consider you have a
div
(or any other element) where the game text is displayed:
html
Copy code
<
div
id
=
"gameText"
>
Your game text here...
</
div
>
CSS
:
css
Copy code
.galactic-font
{
font-family
:
'GalacticFont'
, sans-serif;
}
.latin-font
{
font-family
:
'LatinFont'
, sans-serif;
/* Or another default like 'Arial' */
}
JavaScript
:
Listen for the
z
key press.
Toggle the class of the
div
based on the key press.
javascript
Copy code
const
gameTextElement =
document
.
getElementById
(
"gameText"
);
document
.
addEventListener
(
'keydown'
,
function
(
event
) {
if
(event.
key
===
'z'
|| event.
keyCode
===
90
) {
// 90 is the keyCode for 'z'
if
(gameTextElement.
classList
.
contains
(
'galactic-font'
)) {
gameTextElement.
classList
.
remove
(
'galactic-font'
);
gameTextElement.
classList
.
add
(
'latin-font'
);
}
else
{
gameTextElement.
classList
.
remove
(
'latin-font'
);
gameTextElement.
classList
.
add
(
'galactic-font'
);
}
}
});
Initialization
:
Start with one of the fonts (whichever you want as the default):
javascript
Copy code
gameTextElement.
classList
.
add
(
'galactic-font'
);
// or 'latin-font' if you want to start with Latin characters
Integration in Your Game
:
If your game is using a game engine or a framework that manipulates the DOM differently, you might need to adjust the above approach to fit within that context. The fundamental idea remains the same: listen for the
z
key and swap fonts based on the current font setting.
Remember: When changing fonts, especially in a game setting, ensure the change doesn't cause significant shifts in layout, which could disrupt the user experience. If there's a size or spacing difference between the fonts, you might need to make additional CSS adjustments.
What browsers use .woff and .woff2?
ChatGPT
The
.woff
(Web Open Font Format) and
.woff2
(its successor) are modern font formats developed specifically for the web. They are designed to provide lightweight, efficient font transmission and have broad support among web browsers. Here's a general breakdown of browser support:
.woff (Web Open Font Format)
:
Firefox
: 3.6+
Google Chrome
: 5.0+
Internet Explorer
: 9.0+
Safari
: 5.1+
Opera
: 11.1+
iOS Safari
: 5.0+
Android Browser
: 4.4+
Opera Mobile
: 11.0+
Chrome for Android
: Yes
Firefox for Android
: Yes
.woff2 (Web Open Font Format 2.0)
:
This format offers better compression than
.woff
, leading to faster downloads.
Firefox
: 39+
Google Chrome
: 36+
Internet Explorer
: No support
Edge
: 14+
Safari
: 10+
Opera
: 26+
iOS Safari
: 10+
Android Browser
: 67+
Opera Mobile
: 37+
Chrome for Android
: Yes
Firefox for Android
: Yes
It's important to note that browser support can evolve, so it's a good idea to periodically check updated resources, like
Can I use
, for the latest browser compatibility information.
Given the support landscape, many websites opt to include both
.woff
and
.woff2
versions to maximize compatibility and performance. Browsers that support
.woff2
will prioritize it because of its improved compression, while others will fall back to
.woff
.
Ok I put the files in a folder called fonts:
create mode 100644 fonts/Sga-Regular.ttf
create mode 100644 fonts/Sga-Regular.woff
create mode 100644 fonts/Sga-Regular.woff2
ChatGPT
Great! You have your font files in the
fonts
directory. Now, you can use them in your web project with the following steps:
Include the
@font-face
Rule in CSS
:
Since you have
.woff2
,
.woff
, and
.ttf
formats, you can include all three in your
@font-face
declaration for maximum compatibility.
css
Copy code
@font-face
{
font-family
:
'SgaRegular'
;
/* A name for your font; you can choose any */
src
:
url
(
'fonts/Sga-Regular.woff2'
)
format
(
'woff2'
),
url
(
'fonts/Sga-Regular.woff'
)
format
(
'woff'
),
url
(
'fonts/Sga-Regular.ttf'
)
format
(
'truetype'
);
font-weight
: normal;
font-style
: normal;
}
Ensure the path (
fonts/
) matches the directory where you've stored the font files.
Use the Font in Your CSS
:
Now that the font is defined, you can apply it to elements on your page:
css
Copy code
body
{
font-family
:
'SgaRegular'
, sans-serif;
/* 'SgaRegular' is the name we gave in the @font-face declaration */
}
Toggle between Fonts using JavaScript
:
If you want to switch between the Standard Galactic Alphabet and a default Latin font using the
z
key, you can utilize the JavaScript example provided in the earlier response.
Testing
:
Open your website in various browsers to ensure that the font is displayed correctly.
Test the font toggle functionality by pressing the
z
key.
Optimizations & Considerations
:
Ensure you have the appropriate licensing rights to use and distribute the font.
To improve performance, only load the fonts you need. If you're only using
.woff2
for modern browsers and
.woff
for slightly older browsers, you may not need the
.ttf
version unless you want to ensure compatibility with even older browsers or specific devices.
Consider setting
font-display: swap;
in the
@font-face
declaration, which can improve the rendering time of your text, especially if the font takes a while to load.
That's it! With these steps, you should have your custom font working and toggleable on your web page.
Ok I will give you the code and you try to integrate it.
ChatGPT
Of course! Please provide the relevant portions of your HTML, CSS, and JavaScript code, and I'll help you integrate the font toggle functionality.
I don't have a css file yet, and the javascript file is just a list of planets, but there is javascript in the html I think
ChatGPT
Alright, let's start with what you have. Please provide the HTML content, especially the sections where text or content is displayed that you want the font to be applied to. Once I see the structure of your HTML, I can guide you on creating the necessary CSS and integrating the JavaScript functionality for toggling the font.
If there's JavaScript embedded in your HTML, include that too so I can understand the full context.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Starfield</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
display: block;
}
</style>
</head>
<script src="planets.js"></script>
<body>
<script>
let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
document.body.appendChild(canvas);
let spaceship = {
x: canvas.width / 2,
y: canvas.height / 2,
speed: 0,
maxSpeed: 5,
acceleration: 0.1
};
let words = planetsList;
let bubbles = [];
for (let i = 0; i < 1000; i++) {
bubbles.push({
x: Math.random() * canvas.width - spaceship.x,
y: Math.random() * canvas.height - spaceship.y,
z: Math.random() * canvas.width,
size: 3,
speed: Math.random() * 0.5 + 0.1,
word: words[Math.floor(Math.random() * words.length)],
isFocused: false
});
}
let controls = {
up: false, down: false,
leftRotate: false, rightRotate: false,
leftView: false, downView: false,
upView: false, rightView: false
};
let viewRotationX = 0; // Rotation for h and l
let viewRotationY = 0; // Rotation for j and k
function draw() {
context.fillStyle = "#000000";
context.fillRect(0, 0, canvas.width, canvas.height);
for (let bubble of bubbles) {
let verticalMoveFactor = controls.upView ? 1 : controls.downView ? -1 : 0;
bubble.y += verticalMoveFactor * 5;
let scale = canvas.width / bubble.z;
let x = spaceship.x + bubble.x * scale;
let y = spaceship.y + bubble.y * scale;
if (bubble.isFocused) {
context.fillStyle = "#FF0000";
context.fillText("Planetary Brake Activating!", canvas.width / 2 - 100, 30);
}
context.strokeStyle = "#ffffff";
context.beginPath();
context.arc(x, y, bubble.size * scale, 0, Math.PI * 2);
context.fillStyle = "#000";
context.fill();
context.closePath();
context.stroke();
if (scale > 0.1) {
context.fillStyle = "#ffffff";
context.fillText(bubble.word, x, y);
}
}
}
function update() {
if (controls.up) {
spaceship.speed += spaceship.acceleration;
if (spaceship.speed > spaceship.maxSpeed) {
spaceship.speed = spaceship.maxSpeed;
}
} else if (controls.down) {
spaceship.speed -= spaceship.acceleration;
if (spaceship.speed < 0) {
spaceship.speed = 0;
}
}
let rotateViewFactor = controls.rightView ? 0.05 : controls.leftView ? -0.05 : 0;
for (let bubble of bubbles) {
let angle = Math.atan2(bubble.y - spaceship.y, bubble.x - spaceship.x) + viewRotationX;
let distance = Math.sqrt((bubble.x - spaceship.x) ** 2 + (bubble.y - spaceship.y) ** 2);
bubble.x = spaceship.x + distance * Math.cos(angle);
bubble.y = spaceship.y + distance * Math.sin(angle) + viewRotationY;
angle += rotateViewFactor;
distance = Math.sqrt((bubble.x - spaceship.x) ** 2 + (bubble.y - spaceship.y) ** 2);
bubble.x = spaceship.x + distance * Math.cos(angle);
bubble.y = spaceship.y + distance * Math.sin(angle);
}
let rotateFactor = controls.rightRotate ? 1 : controls.leftRotate ? -1 : 0;
for (let bubble of bubbles) {
if (bubble.isFocused) {
bubble.size += 0.05;
}
bubble.z -= spaceship.speed;
bubble.x += rotateFactor * 5;
if (bubble.z < 0.5 || bubble.z > canvas.width || bubble.x < -canvas.width / 2 || bubble.x > canvas.width * 1.5 || bubble.y < -canvas.height / 2 || bubble.y > canvas.height * 1.5) {
bubble.x = Math.random() * canvas.width - spaceship.x;
bubble.y = Math.random() * canvas.height - spaceship.y;
bubble.z = canvas.width;
bubble.isFocused = false;
}
}
// Check for focus
for (let bubble of bubbles) {
let scale = canvas.width / bubble.z;
let x = spaceship.x + bubble.x * scale;
let y = spaceship.y + bubble.y * scale;
if (x > spaceship.x - 20 && x < spaceship.x + 20 && y > spaceship.y - 20 && y < spaceship.y + 20) {
bubble.isFocused = true;
} else {
bubble.isFocused = false;
}
}
}
document.addEventListener("keydown", function(event) {
switch (event.key) {
case 'w':
controls.up = true;
break;
case 's':
controls.down = true;
break;
case 'a':
controls.leftRotate = true;
break;
case 'd':
controls.rightRotate = true;
break;
case 'q':
controls.leftView = true;
break;
case 'e':
controls.rightView = true;
break;
case 'r':
controls.upView = true;
break;
case 'f':
controls.downView = true;
break;
case 'h':
viewRotationX -= 0.05; // You can adjust the value for a faster or slower rotation
break;
case 'l':
viewRotationX += 0.05;
break;
case 'j':
viewRotationY += 5; // Adjust the value for a faster or slower vertical view change
break;
case 'k':
viewRotationY -= 5;
break;
}
});
document.addEventListener("keyup", function(event) {
switch (event.key) {
case 'w':
controls.up = false;
break;
case 's':
controls.down = false;
break;
case 'a':
controls.leftRotate = false;
break;
case 'd':
controls.rightRotate = false;
break;
case 'q':
controls.leftView = false;
break;
case 'e':
controls.rightView = false;
break;
case 'h':
controls.leftView = false;
break;
case 'j':
controls.downView = false;
break;
case 'k':
controls.upView = false;
break;
case 'l':
controls.rightView = false;
break;
case 'r':
controls.upView = false;
break;
case 'f':
controls.downView = false;
break;
}
});
function loop() {
update();
draw();
requestAnimationFrame(loop);
}
loop();
</script>
</body>
</html>
ChatGPT
Alright, let's integrate the font toggling functionality into the provided code:
Include the
@font-face
Rule
:
Add the following
@font-face
rule to the style section in the head of your HTML:
css
Copy code
@font-face
{
font-family
:
'SgaRegular'
;
src
:
url
(
'fonts/Sga-Regular.woff2'
)
format
(
'woff2'
),
url
(
'fonts/Sga-Regular.woff'
)
format
(
'woff'
),
url
(
'fonts/Sga-Regular.ttf'
)
format
(
'truetype'
);
font-weight
: normal;
font-style
: normal;
}
Modify the existing style to include the custom font
:
Modify the existing
<style>
section to include:
css
Copy code
body
{
margin
:
0
;
overflow
: hidden;
font-family
:
'SgaRegular'
;
}
Add the JavaScript code for toggling between fonts
:
Within your existing JavaScript, you can add an event listener for the
z
key to toggle between the custom font and a default one. Here's the integration:
Add a variable at the beginning of your script to keep track of the current font:
javascript
Copy code
let
isUsingCustomFont =
true
;
Inside the
document.addEventListener("keydown", function(event) {...});
section, add a new case:
javascript
Copy code
case
'z'
:
isUsingCustomFont = !isUsingCustomFont;
if
(isUsingCustomFont) {
document
.
body
.
style
.
fontFamily
=
'SgaRegular'
;
}
else
{
document
.
body
.
style
.
fontFamily
=
'sans-serif'
;
}
break
;
This will toggle the font of the entire body between your custom font and a default sans-serif font whenever the
z
key is pressed.
Adjust the font size for visibility
:
Depending on the size of your custom font, you might find the text too small or too large. You can adjust the size by adding this to the
<style>
section:
css
Copy code
body
{
font-size
:
20px
;
/* Adjust this value as needed */
}
With these steps, your code will now include the custom font, and you'll be able to toggle between the custom font and a default one using the
z
key. Ensure that the path to the fonts is correct, and they are available on the server from which you're serving your game.
Additionally, remember to test across different browsers to ensure everything displays as expected!
I fixed up most of the issues in another thread:
Certainly! Here's a summary of our conversation:
1. **Font Loading**:
- You began by mentioning that a custom font, 'Sga Regular', was not being rendered in a "game" but was working in a test file.
- I provided an example of how to properly load the font in a `<style>` tag and set the font for a canvas context.
- You clarified that the test file was loading the font correctly without a canvas, and your concern was about adding the context font line in your game code.
2. **Starfield Game Issue**:
- You shared a detailed HTML and JS code snippet for a "Starfield" game. You mentioned that the "Planetary Brake Activating" sign wasn't working.
- I analyzed the code and highlighted possible reasons, including:
- Overwriting of the `context.fillStyle` property.
- Possibility of multiple bubbles being in focus at the same time.
- Text placement on the canvas.
- Font loading issues.
- Canvas clearing at the start of each draw cycle.
- Font size and style considerations.
- I then provided troubleshooting steps such as using `console.log`, commenting out parts of the code, and checking the browser console.
Throughout our conversation, we primarily focused on identifying and troubleshooting issues related to the custom font loading and the "Planetary Brake Activating" sign in the "Starfield" game.
ChatGPT
Thank you for the summary. Based on our prior conversation and the current code you've shared, let's finalize the font toggling functionality for your Starfield game.
To implement the font toggle functionality:
Use the
@font-face
Rule
:
In the
<style>
section of your HTML, add:
css
Copy code
@font-face
{
font-family
:
'SgaRegular'
;
src
:
url
(
'fonts/Sga-Regular.woff2'
)
format
(
'woff2'
),
url
(
'fonts/Sga-Regular.woff'
)
format
(
'woff'
),
url
(
'fonts/Sga-Regular.ttf'
)
format
(
'truetype'
);
font-weight
: normal;
font-style
: normal;
}
Modify the Text Drawing Style
:
When drawing the text on the canvas, the
font
property of the context needs to be updated. Update this for the "Planetary Brake Activating!" message and for the planet names.
Add this at the start of your
draw()
function:
javascript
Copy code
context.
font
= isUsingCustomFont ?
"20px SgaRegular"
:
"20px sans-serif"
;
Adjust the "20px" based on how you'd like the font size to look.
Font Toggle Mechanism
:
Since you've shared that the
z
key should toggle the font, within your
document.addEventListener("keydown", ...)
function, add:
javascript
Copy code
case
'z'
:
isUsingCustomFont = !isUsingCustomFont;
break
;
And before the key event listeners, declare the
isUsingCustomFont
variable:
javascript
Copy code
let
isUsingCustomFont =
true
;
With these changes, pressing the
z
key while playing the game should toggle between the custom font and a default sans-serif font for both the "Planetary Brake Activating!" message and the planet names.
If you face any issues, do provide feedback. The challenge with canvas is that it does not inherently use the CSS applied to the body or other HTML elements, so we need to specify font styles directly on the canvas context.
There is a glitch in the code the z key seems to scroll the canvas up sometimes
ChatGPT
The behavior you're experiencing is likely due to the default action of the browser when the
z
key is pressed in combination with certain other keys (like Ctrl or Alt). This can trigger browser shortcuts such as "Undo" or "Zoom".
To prevent this default behavior, you can call the
preventDefault()
method on the event object inside the event listener.
Here's how you can modify the
keydown
event listener to prevent the default action:
javascript
Copy code
document
.
addEventListener
(
"keydown"
,
function
(
event
) {
switch
(event.
key
) {
// ... (other cases here)
case
'z'
:
isUsingCustomFont = !isUsingCustomFont;
event.
preventDefault
();
// Prevent the default action
break
;
// ... (other cases here)
}
});
Adding
event.preventDefault();
for the
'z'
case should prevent any default actions from occurring when the
z
key is pressed, thus resolving the glitch you mentioned.
here's how it looks currently : case 'z': // Toggle the font