Last active
February 10, 2016 18:25
-
-
Save tnsicdr/c1270a22cda2786864af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================= | |
// tnsi_quest_core.js | |
//============================================================================= | |
var Imported = Imported || {}; | |
Imported.tnsi_quest_core = "0.0.1"; | |
/*: | |
* @plugindesc Common quest format | |
* @author ロリ先輩 | |
* | |
* @help ============================================================================ | |
* Terms & Conditions | |
* ============================================================================ | |
* Copyright (c) 2016, tensei nguyen <me[at]tnsi.me> | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
*/ | |
// Register functions for other plugins | |
var tnsi_quest_core = {}; | |
var $gameQuests = null; | |
var $dataQuests = null; | |
(function($) { | |
"use strict"; | |
//--------------------------------------------------------------------------- | |
// TNSI_Quests | |
// | |
// Universal Class For | |
function TNSI_Quests() { | |
this.initialize.apply(this, arguments); | |
} | |
/** | |
* Initialize function | |
*/ | |
TNSI_Quests.prototype.initialize = function() { | |
this.clear(); | |
this.populate(); | |
}; | |
/** | |
* Clear Function | |
*/ | |
TNSI_Quests.prototype.clear = function () { | |
this._data = []; | |
}; | |
/** | |
* Populates the quest data from json | |
*/ | |
TNSI_Quests.prototype.populate = function() { | |
this._data = $dataQuests | |
}; | |
/** | |
* Value Function | |
*/ | |
TNSI_Quests.prototype.value = function(questId) { | |
return this._data[questId] || 0; | |
}; | |
/** | |
* Sets the current stage for a quest to the given one | |
* @param {number} questId Quest ID | |
* @param {number} questStage Quest stage | |
* @return {[type]} [description] | |
*/ | |
TNSI_Quests.prototype.setStage = function(questId, questStage) { | |
if (questId > 0 && questId <= this._data.length - 1) { | |
if (typeof questStage === 'number') { | |
questStage = Math.floor(questStage); | |
} | |
// set stage to 0 if invalid | |
if(questStage > this._data[questId].stages.length - 1 || questStage < 0) { | |
this._data[questId].curStage = 0; | |
} else { | |
this._data[questId].curStage = questStage; | |
} | |
this.onChange(); | |
} | |
}; | |
/** | |
* Stage Accessor | |
* @param {number} questId Quest ID | |
* @return {number} The current stage | |
*/ | |
TNSI_Quests.prototype.getStage = function(questId) { | |
return this._data[questId].curStage; | |
}; | |
/** | |
* Quest Title Accessor | |
* @param {number} questId Quest ID | |
* @return {string} QUest Title | |
*/ | |
TNSI_Quests.prototype.getQuestTitle = function(questId) { | |
return this._data[questId].questTitle; | |
}; | |
/** | |
* Get Description Accessor | |
* @param {number} questId Quest ID | |
* @return {number} Quest cost | |
*/ | |
TNSI_Quests.prototype.getQuestDescription = function(questId) { | |
return this._data[questId].questDesc; | |
}; | |
/** | |
* Quest Cost Accessor | |
* @param {number} questId Quest ID | |
* @return {number} Quest cost | |
*/ | |
TNSI_Quests.prototype.getQuestCost = function(questId) { | |
return this._data[questId].questCost; | |
}; | |
/** | |
* Return the text entry for the current quest stage | |
* @param {number} questId ID of the Quest | |
* @return {string} Text Entry | |
*/ | |
TNSI_Quests.prototype.getQuestEntry = function(questId) { | |
var stage = this.getStage(questId) | |
return this._data[questId].stages[stage].hint; | |
} | |
/** | |
* On Change | |
*/ | |
TNSI_Quests.prototype.onChange = function() { | |
$gameMap.requestRefresh(); | |
}; | |
// DataManager | |
DataManager._databaseFiles.push( | |
{name: "$dataQuests", src: 'Quests.json'} | |
); | |
var tnsi_dm_cgo = DataManager.createGameObjects; | |
DataManager.createGameObjects = function() { | |
$gameQuests = new TNSI_Quests(); | |
tnsi_dm_cgo(); | |
}; | |
var tnsi_dm_msc = DataManager.makeSaveContents; | |
DataManager.makeSaveContents = function() { | |
var contents = tnsi_dm_msc(); | |
contents.quests = $gameQuests; | |
return contents; | |
}; | |
var tnsi_dm_esc = DataManager.extractSaveContents; | |
DataManager.extractSaveContents = function(contents) { | |
$gameQuests = contents.quests; | |
tnsi_dm_esc(contents); | |
}; | |
})(tnsi_quest_core); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment