Skip to content

Commit d7adebe

Browse files
authored
Merge branch 'master' into add_autosave
2 parents 95f08df + 507b459 commit d7adebe

File tree

6 files changed

+122
-31
lines changed

6 files changed

+122
-31
lines changed

js/rpg_core/Graphics.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
1212
Graphics._fontLoaded = null;
1313
Graphics._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
*/
282282
Graphics.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
*/
320322
Graphics.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(/file:.*js\//g, '')
344+
.replace(/http:.*js\//g, '')
345+
.replace(/https:.*js\//g, '')
346+
.replace(/chrome-extension:.*js\//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
*/
674707
Graphics._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
*/
748781
Graphics._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() {
10971165
Graphics._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

js/rpg_core/TilingSprite.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@ TilingSprite.prototype._renderCanvas = function(renderer) {
5151
}
5252
};
5353

54-
/**
55-
* @method _renderWebGL
56-
* @param {Object} renderer
57-
* @private
58-
*/
59-
TilingSprite.prototype._renderWebGL = function(renderer) {
60-
if (this._bitmap) {
61-
this._bitmap.touch();
62-
}
63-
if (this.texture.frame.width > 0 && this.texture.frame.height > 0) {
64-
if (this._bitmap) {
65-
this._bitmap.checkDirty();
66-
}
67-
this._renderWebGL_PIXI(renderer);
68-
}
69-
};
70-
7154
/**
7255
* The image for the tiling sprite.
7356
*

js/rpg_core/WebAudio.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,19 @@ WebAudio._createMasterGainNode = function() {
148148
* @private
149149
*/
150150
WebAudio._setupEventHandlers = function() {
151-
document.addEventListener("touchend", function() {
152-
var context = WebAudio._context;
153-
if (context && context.state === "suspended" && typeof context.resume === "function") {
154-
context.resume().then(function() {
155-
WebAudio._onTouchStart();
156-
})
157-
} else {
151+
var resumeHandler = function() {
152+
var context = WebAudio._context;
153+
if (context && context.state === "suspended" && typeof context.resume === "function") {
154+
context.resume().then(function() {
158155
WebAudio._onTouchStart();
159-
}
160-
});
156+
})
157+
} else {
158+
WebAudio._onTouchStart();
159+
}
160+
};
161+
document.addEventListener("keydown", resumeHandler);
162+
document.addEventListener("mousedown", resumeHandler);
163+
document.addEventListener("touchend", resumeHandler);
161164
document.addEventListener('touchstart', this._onTouchStart.bind(this));
162165
document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this));
163166
};

js/rpg_managers/SceneManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ SceneManager.onKeyDown = function(event) {
180180
SceneManager.catchException = function(e) {
181181
if (e instanceof Error) {
182182
Graphics.printError(e.name, e.message);
183+
Graphics.printStackTrace(e.stack);
183184
console.error(e.stack);
184185
} else {
185186
Graphics.printError('UnknownError', e);

js/rpg_managers/StorageManager.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ StorageManager.localFileDirectoryPath = function() {
195195
var path = require('path');
196196

197197
var base = path.dirname(process.mainModule.filename);
198-
return path.join(base, 'save/');
198+
if (this.canMakeWwwSaveDirectory()) {
199+
return path.join(base, 'save/');
200+
} else {
201+
return path.join(path.dirname(base), 'save/');
202+
}
199203
};
200204

201205
StorageManager.localFilePath = function(savefileId) {
@@ -219,3 +223,21 @@ StorageManager.webStorageKey = function(savefileId) {
219223
return 'RPG File%1'.format(savefileId);
220224
}
221225
};
226+
227+
// Enigma Virtual Box cannot make www/save directory
228+
StorageManager.canMakeWwwSaveDirectory = function() {
229+
if (this._canMakeWwwSaveDirectory === undefined) {
230+
var fs = require('fs');
231+
var path = require('path');
232+
var base = path.dirname(process.mainModule.filename);
233+
var testPath = path.join(base, 'testDirectory/');
234+
try {
235+
fs.mkdirSync(testPath);
236+
fs.rmdirSync(testPath);
237+
this._canMakeWwwSaveDirectory = true;
238+
} catch (e) {
239+
this._canMakeWwwSaveDirectory = false;
240+
}
241+
}
242+
return this._canMakeWwwSaveDirectory;
243+
};

plugins/Community_Basic.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
* @type number
4747
* @desc The file number to auto save when "Transfer Player" (0: off)
4848
* @default 0
49+
*
50+
* @param errorMessage
51+
* @type string
52+
* @desc The message when error occurred
53+
* @default Error occurred. Please ask to the creator of this game.
4954
*/
5055

5156
/*:ja
@@ -96,6 +101,11 @@
96101
* @type number
97102
* @desc 「場所移動」の際にオートセーブするファイル番号 (0でoff)
98103
* @default 0
104+
*
105+
* @param errorMessage
106+
* @type string
107+
* @desc エラーが発生した際に表示するメッセージ
108+
* @default エラーが発生しました。ゲームの作者にご連絡ください。
99109
*/
100110

101111
(function() {
@@ -117,6 +127,7 @@
117127
var windowWidthTo = toNumber(parameters['changeWindowWidthTo'], 0);
118128
var windowHeightTo = toNumber(parameters['changeWindowHeightTo'], 0);
119129
var autoSaveFileId = toNumber(parameters['autoSaveFileId'], 0);
130+
var errorMessage = parameters['errorMessage'];
120131

121132
var windowWidth;
122133
var windowHeight;
@@ -176,4 +187,5 @@
176187
};
177188

178189
DataManager.setAutoSaveFileId(autoSaveFileId);
190+
Graphics.setErrorMessage(errorMessage);
179191
})();

0 commit comments

Comments
 (0)