@@ -12,6 +12,7 @@ document.addEventListener('DOMContentLoaded', async () => {
12
12
const elInpHeight = document . querySelector ( '#height' )
13
13
const elSelFormat = document . querySelector ( '#resolution' )
14
14
const elBtnDownload = document . querySelector ( '#download' )
15
+ const elChkAntiAliasing = document . querySelector ( '#antialiasing' )
15
16
const elSelResolution = document . querySelector ( '#resolution' )
16
17
const elMonacoEditor = document . querySelector ( '#editor' )
17
18
const elCanvas = document . querySelector ( '#gameCanvas' )
@@ -64,10 +65,18 @@ document.addEventListener('DOMContentLoaded', async () => {
64
65
const apply = ( ) => {
65
66
const code = monacoEditor . getValue ( )
66
67
gly . load ( `return {init=function()end,loop=function()end,draw=function(std)\n${ code } \nend}` )
67
- gly . resize ( elInpWidth . value , elInpHeight . value )
68
68
window . requestAnimationFrame ( gly . update )
69
69
}
70
70
71
+ const resizeAndApply = ( ) => {
72
+ gly . resize ( elInpWidth . value , elInpHeight . value )
73
+ apply ( )
74
+ }
75
+
76
+ const toggleAntiAliasing = ( ) => {
77
+ elCanvas . style . imageRendering = elChkAntiAliasing . checked ? '' : 'pixelated'
78
+ }
79
+
71
80
monacoEditor . onDidChangeModelContent ( ( ) => {
72
81
clearTimeout ( monacoTimeout ) ;
73
82
monacoTimeout = setTimeout ( ( ) => {
@@ -79,7 +88,9 @@ document.addEventListener('DOMContentLoaded', async () => {
79
88
const [ width , height ] = elSelResolution . value . split ( 'x' ) . map ( Number ) ;
80
89
elInpWidth . value = width ;
81
90
elInpHeight . value = height ;
82
- apply ( ) ;
91
+ elChkAntiAliasing . checked = width > 128 ;
92
+ toggleAntiAliasing ( ) ;
93
+ resizeAndApply ( ) ;
83
94
} )
84
95
85
96
elBtnDownload . addEventListener ( 'click' , ( ev ) => {
@@ -94,8 +105,10 @@ document.addEventListener('DOMContentLoaded', async () => {
94
105
URL . revokeObjectURL ( url )
95
106
} )
96
107
97
- elInpWidth . addEventListener ( 'change' , apply ) ;
98
- elInpHeight . addEventListener ( 'change' , apply ) ;
108
+ elChkAntiAliasing . addEventListener ( 'change' , toggleAntiAliasing ) ;
109
+ elInpWidth . addEventListener ( 'change' , resizeAndApply ) ;
110
+ elInpHeight . addEventListener ( 'change' , resizeAndApply ) ;
99
111
100
- apply ( ) ;
112
+ toggleAntiAliasing ( )
113
+ resizeAndApply ( ) ;
101
114
} )
0 commit comments