Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn fixes #1418

Merged
merged 5 commits into from Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions Extensions/DialogueTree/dialoguetools.js
Expand Up @@ -120,6 +120,7 @@ gdjs.dialogueTree.completeClippedTextScrolling = function() {
* Useful to prevent the user from skipping to next line before the current one has been printed fully.
*/
gdjs.dialogueTree.hasClippedScrollingCompleted = function() {
if (!this.dialogueIsRunning) return false;
if (this.dialogueData && this.dialogueText.length) {
return this.clipTextEnd >= this.dialogueText.length;
}
Expand All @@ -131,8 +132,8 @@ gdjs.dialogueTree.hasClippedScrollingCompleted = function() {
* Used with the scrollClippedText to achieve a classic scrolling text, as well as any <<wait>> effects to pause scrolling.
*/
gdjs.dialogueTree.getClippedLineText = function() {
return this.dialogueText.length
? this.dialogueText.substring(0, this.clipTextEnd)
return this.dialogueIsRunning && this.dialogueText.length
? this.dialogueText.substring(0, this.clipTextEnd + 1)
: '';
};

Expand All @@ -142,7 +143,9 @@ gdjs.dialogueTree.getClippedLineText = function() {
*/
gdjs.dialogueTree.getLineText = function() {
this.completeClippedTextScrolling();
return this.dialogueText.length ? this.dialogueText : '';
return this.dialogueIsRunning && this.dialogueText.length
? this.dialogueText
: '';
};

/**
Expand Down Expand Up @@ -177,6 +180,8 @@ gdjs.dialogueTree.getCommandParameter = function(paramIndex) {
* @param {string} command The command you want to check for being called. Write it without the `<<>>`.
*/
gdjs.dialogueTree.isCommandCalled = function(command) {
if (!this.dialogueIsRunning) return false;

var commandCalls = gdjs.dialogueTree.commandCalls;
var clipTextEnd = gdjs.dialogueTree.clipTextEnd;
var dialogueText = gdjs.dialogueTree.dialogueText;
Expand Down Expand Up @@ -225,7 +230,7 @@ gdjs.dialogueTree._cycledOptionIndex = function(optionIndex) {
* @param {number} optionIndex The index of the option you want to get
*/
gdjs.dialogueTree.getLineOption = function(optionIndex) {
if (!this.options.length) return [];
if (!this.dialogueIsRunning || !this.options.length) return [];
optionIndex = gdjs.dialogueTree._normalizedOptionIndex(optionIndex);
return this.options[optionIndex];
};
Expand All @@ -239,7 +244,7 @@ gdjs.dialogueTree.getLineOptionsText = function(
optionSelectionCursor,
addNewLine
) {
if (!this.options.length) return '';
if (!this.dialogueIsRunning || !this.options.length) return '';
var textResult = '';
this.options.forEach(function(optionText, index) {
if (index === gdjs.dialogueTree.selectedOption) {
Expand All @@ -266,7 +271,7 @@ gdjs.dialogueTree.getLineOptionsTextVertical = function(optionSelectionCursor) {
* @returns {number} The number of options
*/
gdjs.dialogueTree.getLineOptionsCount = function() {
if (this.options.length) {
if (this.dialogueIsRunning && this.options.length) {
return this.optionsCount;
}
return 0;
Expand All @@ -278,6 +283,7 @@ gdjs.dialogueTree.getLineOptionsCount = function() {
* This will advance the dialogue tree to the dialogue branch was selected by the player.
*/
gdjs.dialogueTree.confirmSelectOption = function() {
if (!this.dialogueIsRunning) return;
if (
this.dialogueData.select &&
!this.selectedOptionUpdated &&
Expand All @@ -301,6 +307,7 @@ gdjs.dialogueTree.confirmSelectOption = function() {
* Select next option during Options type line parsing. Hook this to your game input.
*/
gdjs.dialogueTree.selectNextOption = function() {
if (!this.dialogueIsRunning) return;
if (this.dialogueData.select) {
this.selectedOption += 1;
this.selectedOption = gdjs.dialogueTree._cycledOptionIndex(
Expand All @@ -314,6 +321,7 @@ gdjs.dialogueTree.selectNextOption = function() {
* Select previous option during Options type line parsing. Hook this to your game input.
*/
gdjs.dialogueTree.selectPreviousOption = function() {
if (!this.dialogueIsRunning) return;
if (this.dialogueData.select) {
this.selectedOption -= 1;
this.selectedOption = gdjs.dialogueTree._cycledOptionIndex(
Expand All @@ -328,6 +336,7 @@ gdjs.dialogueTree.selectPreviousOption = function() {
* @param {number} optionIndex The index of the option to select
*/
gdjs.dialogueTree.selectOption = function(optionIndex) {
if (!this.dialogueIsRunning) return;
if (this.dialogueData.select) {
this.selectedOption = gdjs.dialogueTree._normalizedOptionIndex(
this.selectedOption
Expand All @@ -341,6 +350,7 @@ gdjs.dialogueTree.selectOption = function(optionIndex) {
* @returns {number} The index of the currently selected option
*/
gdjs.dialogueTree.getSelectedOption = function() {
if (!this.dialogueIsRunning) return;
if (this.dialogueData.select) {
return this.selectedOption;
}
Expand Down
8 changes: 7 additions & 1 deletion GDJS/Runtime/jsonmanager.js
Expand Up @@ -56,7 +56,7 @@ gdjs.JsonManager.prototype.preloadJsons = function(onProgress, onComplete) {
/** @type JsonManagerRequestCallback */
var onLoad = function(error, jsonContent) {
if (error) {
console.error("Error while preloading a json resource:" + error);
console.error('Error while preloading a json resource:' + error);
}

loaded++;
Expand Down Expand Up @@ -104,6 +104,12 @@ gdjs.JsonManager.prototype.loadJson = function(resourceName, callback) {
return;
}

// Don't fetch again an object that is already in memory
if (this._loadedJsons[resourceName]) {
callback(null, this._loadedJsons[resourceName]);
return;
}

var that = this;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
Expand Down