@@ -8,7 +8,7 @@ function Graphics() {
88 throw new Error ( 'This is a static class' ) ;
99}
1010
11- Graphics . _cssFontLoading = document . fonts && document . fonts . ready ;
11+ Graphics . _cssFontLoading = document . fonts && document . fonts . ready && document . fonts . ready . then ;
1212Graphics . _fontLoaded = null ;
1313Graphics . _videoVolume = 1 ;
1414
@@ -36,7 +36,7 @@ Graphics.initialize = function(width, height, type) {
3636 this . _errorPrinter = null ;
3737 this . _canvas = null ;
3838 this . _video = null ;
39- this . _videoUnlocked = ! Utils . isMobileDevice ( ) ;
39+ this . _videoUnlocked = false ;
4040 this . _videoLoading = false ;
4141 this . _upperCanvas = null ;
4242 this . _renderer = null ;
@@ -281,6 +281,7 @@ Graphics.endLoading = function() {
281281 */
282282Graphics . printLoadingError = function ( url ) {
283283 if ( this . _errorPrinter && ! this . _errorShowed ) {
284+ this . _updateErrorPrinter ( ) ;
284285 this . _errorPrinter . innerHTML = this . _makeErrorHtml ( 'Loading Error' , 'Failed to load: ' + url ) ;
285286 var button = document . createElement ( 'button' ) ;
286287 button . innerHTML = 'Retry' ;
@@ -309,6 +310,7 @@ Graphics.eraseLoadingError = function() {
309310 }
310311} ;
311312
313+ // The following code is partly borrowed from triacontane.
312314/**
313315 * Displays the error text to the screen.
314316 *
@@ -319,13 +321,44 @@ Graphics.eraseLoadingError = function() {
319321 */
320322Graphics . printError = function ( name , message ) {
321323 this . _errorShowed = true ;
324+ this . hideFps ( ) ;
322325 if ( this . _errorPrinter ) {
326+ this . _updateErrorPrinter ( ) ;
323327 this . _errorPrinter . innerHTML = this . _makeErrorHtml ( name , message ) ;
328+ this . _makeErrorMessage ( ) ;
324329 }
325330 this . _applyCanvasFilter ( ) ;
326331 this . _clearUpperCanvas ( ) ;
327332} ;
328333
334+ /**
335+ * Shows the stacktrace of error.
336+ *
337+ * @static
338+ * @method printStackTrace
339+ */
340+ Graphics . printStackTrace = function ( stack ) {
341+ if ( this . _errorPrinter ) {
342+ stack = ( stack || '' )
343+ . replace ( / f i l e : .* j s \/ / g, '' )
344+ . replace ( / h t t p : .* j s \/ / g, '' )
345+ . replace ( / h t t p s : .* j s \/ / g, '' )
346+ . replace ( / c h r o m e - e x t e n s i o n : .* j s \/ / g, '' )
347+ . replace ( / \n / g, '<br>' ) ;
348+ this . _makeStackTrace ( decodeURIComponent ( stack ) ) ;
349+ }
350+ } ;
351+
352+ /**
353+ * Sets the error message.
354+ *
355+ * @static
356+ * @method setErrorMessage
357+ */
358+ Graphics . setErrorMessage = function ( message ) {
359+ this . _errorMessage = message ;
360+ } ;
361+
329362/**
330363 * Shows the FPSMeter element.
331364 *
@@ -673,7 +706,7 @@ Graphics._updateRealScale = function() {
673706 */
674707Graphics . _makeErrorHtml = function ( name , message ) {
675708 return ( '<font color="yellow"><b>' + name + '</b></font><br>' +
676- '<font color="white">' + message + '</font><br>' ) ;
709+ '<font color="white">' + decodeURIComponent ( message ) + '</font><br>' ) ;
677710} ;
678711
679712/**
@@ -747,14 +780,49 @@ Graphics._createErrorPrinter = function() {
747780 */
748781Graphics . _updateErrorPrinter = function ( ) {
749782 this . _errorPrinter . width = this . _width * 0.9 ;
750- this . _errorPrinter . height = 40 ;
783+ this . _errorPrinter . height = this . _errorShowed ? this . _height * 0.9 : 40 ;
751784 this . _errorPrinter . style . textAlign = 'center' ;
752785 this . _errorPrinter . style . textShadow = '1px 1px 3px #000' ;
753786 this . _errorPrinter . style . fontSize = '20px' ;
754787 this . _errorPrinter . style . zIndex = 99 ;
788+ this . _errorPrinter . style . userSelect = 'text' ;
789+ this . _errorPrinter . style . webkitUserSelect = 'text' ;
790+ this . _errorPrinter . style . msUserSelect = 'text' ;
791+ this . _errorPrinter . style . mozUserSelect = 'text' ;
792+ this . _errorPrinter . oncontextmenu = null ; // enable context menu
755793 this . _centerElement ( this . _errorPrinter ) ;
756794} ;
757795
796+ /**
797+ * @static
798+ * @method _makeErrorMessage
799+ * @private
800+ */
801+ Graphics . _makeErrorMessage = function ( ) {
802+ var mainMessage = document . createElement ( 'div' ) ;
803+ var style = mainMessage . style ;
804+ style . color = 'white' ;
805+ style . textAlign = 'left' ;
806+ style . fontSize = '18px' ;
807+ mainMessage . innerHTML = '<hr>' + ( this . _errorMessage || '' ) ;
808+ this . _errorPrinter . appendChild ( mainMessage ) ;
809+ } ;
810+
811+ /**
812+ * @static
813+ * @method _makeStackTrace
814+ * @private
815+ */
816+ Graphics . _makeStackTrace = function ( stack ) {
817+ var stackTrace = document . createElement ( 'div' ) ;
818+ var style = stackTrace . style ;
819+ style . color = 'white' ;
820+ style . textAlign = 'left' ;
821+ style . fontSize = '18px' ;
822+ stackTrace . innerHTML = '<br><hr>' + stack + '<hr>' ;
823+ this . _errorPrinter . appendChild ( stackTrace ) ;
824+ } ;
825+
758826/**
759827 * @static
760828 * @method _createCanvas
@@ -1097,6 +1165,8 @@ Graphics._isVideoVisible = function() {
10971165Graphics . _setupEventHandlers = function ( ) {
10981166 window . addEventListener ( 'resize' , this . _onWindowResize . bind ( this ) ) ;
10991167 document . addEventListener ( 'keydown' , this . _onKeyDown . bind ( this ) ) ;
1168+ document . addEventListener ( 'keydown' , this . _onTouchEnd . bind ( this ) ) ;
1169+ document . addEventListener ( 'mousedown' , this . _onTouchEnd . bind ( this ) ) ;
11001170 document . addEventListener ( 'touchend' , this . _onTouchEnd . bind ( this ) ) ;
11011171} ;
11021172
0 commit comments