- Joined
- Mar 9, 2017
- Messages
- 34
- Reaction score
- 4
- First Language
- English
- Primarily Uses
- RMMV
I'm trying to create a window that functions similarly to the Items list, but for a set of objects that provide notes on characters and locations.
I've confirmed (to the best of my ability) that everything in the code is working as expected, right up until I actually try to open the new menu command.
The first spoiler contains all of the bits defining how the plugin itself and the Intel objects work; I've included it for the sake of completeness.
This is the section where I'm pretty sure I've messed up:
I've confirmed that the initialization is working, and that the item is being successfully added to $gameParty.IntelList: after the corresponding event that calls the Plugin command to add the item from the json file, Intel becomes selectable.
However, no menu is actually drawn; all that happens is that the screen empties of the other menus (but stays blurred as if still in the menu system). Since the "cancel" event has been bound to the window it should allow me to back out, but does not. This means that I've either royally screwed up the window creation (probably because I've forgotten something critical), or the program is getting stuck in a loop somewhere.
EDIT: Fixed a typo that broke one of the SPOILER tags.
I've confirmed (to the best of my ability) that everything in the code is working as expected, right up until I actually try to open the new menu command.
The first spoiler contains all of the bits defining how the plugin itself and the Intel objects work; I've included it for the sake of completeness.
Code:
//Get the plugin parameters.
var intelParameters = PluginManager.parameters('IntelSystem');
//Get the intel data from the json file.
DataManager.loadDataFile('$dataIntel', intelParameters.JsonFileName);
//Define getter for the DataManager.
DataManager.getIntelData = function(id) {
return $dataIntel[id];
};
//Add the plugin commands.
Game_Interpreter.prototype.pluginCommand = (function (original) {
"use strict";
// Define the function that will replace the original.
function pluginCommand(command, args) {
original.call(this, command, args);
if (command == "Intel") {
var intelData = GetIntelItem(args);
//If argument is 'add', run add function.
if (args[0] = "add") {
var result = $gameParty.IntelList.addIntel(intelData);
//TODO: create popup window.
} else if (args[0] = "check") {
return $gameParty.IntelList.hasIntel(intelData);
} else if (args[0] = "showAlerts") {
intelParameters.ShowAlerts = args[1];
} else { return;}
} else { return;}
}
return pluginCommand;
}(Game_Interpreter.prototype.pluginCommand));
//Function fetches an intelItem for use by the above commands.
function GetIntelItem(args) {
var idNum = Number(args[1]);
var intelFromData = DataManager.getIntelData(idNum);
var argsIndex = 2;
var contents = [];
if (args.length < 3 && args[0] != "check") {
contents = intelFromData.contents;
} else {
while (argsIndex < args.length) {
var contentsIndex = Number(args[argsIndex]);
//If the number is within the contents array, AND the item hasn't already been added...
if (contentsIndex < intelFromData.contents.length && contents.indexOf(intelFromData.contents[contentsIndex]) === -1) {
//...Add the contents item
contents.push(intelFromData.contents[contentsIndex]);
}
argsIndex++;
}
}
return new IntelItem(idNum, intelFromData.topic, intelFromData.category, contents);
}
/*----------------------------------------------------------------------------*
* CORE FUNCTIONS *
*----------------------------------------------------------------------------*/
//Object constructor for IntelItem.
function IntelItem(idnum, topic, category, contents) {
//ID is used to simplify the lookup process.
this.id = idnum;
//Topics are what the specific informatoin will appear on: IE, the subject of the intel.
this.topic = topic;
//Categories are used for in-game filtering.
this.category = category;
//Array representing specific lines of information.
this.contents = contents;
}
//Function is used as part of evaluation of whether a new intel item's contents are already in the player's Intel inventory.
IntelItem.prototype.matches = function (intelFromList) {
var index = 0;
//isMatch first checks if the topics match; while loop won't even start if they don't.
var isMatch = (this.id === intelFromList.id);
while (isMatch && index < this.contents.length) {
//Step through the contents of the calling IntelItem; if the IntelItem from the list is missing any of them, return false.
isMatch = (intelFromList.contents.indexOf(this.contents[index]) > -1);
index++;
}
return isMatch;
};
//Function adds contents FROM the calling function TO the item given as an argument; the intent is that the item passed as an argument accesses the info from IntelList.
IntelItem.prototype.addNewContents = function(intelFromList){
var newContentsAdded = false;
for (var index = 0; index < this.contents.length; index++) {
if (intelFromList.contents.indexOf(this.contents[index]) === -1) {
intelFromList.contents.push(this.contents[index]);
newContentsAdded = true;
}
}
return newContentsAdded;
};
//Function returns the IntelItem.contents array as a single formated string, ready to be written into the menu.
IntelItem.prototype.getContents = function(){
var result = "";
for (var x = 0; x < this.contents.length; x++) {
result += " " + this.contents[x];
}
return result;
};
//IntelList handles in-game inventory of IntelItems, provides sorting functionality.
function IntelList() {
this.IntelItems = [];
this.intelCategories = [];
}
//Function updates the intel listing with new items, new categories, and new contents for extant items. Returns a string for use with alerts.
IntelList.prototype.addIntel = function(targetIntel) {
//Premature break if a null argument is added.
if (!targetIntel) return;
//Insert category if it isn't in the categories list.
if (this.intelCategories.indexOf(targetIntel.category) === -1) {
this.intelCategories.push(targetIntel.category);
this.intelCategories.sort();
}
var result = null;
var dexVal = this.findIndex(targetIntel);
if (dexVal === this.IntelItems.length) {
this.IntelItems.push(targetIntel);
result = "New intelligence file: " + targetIntel.topic;
} else {
var intelAtIndex = this.IntelItems[dexVal];
if (intelAtIndex.id != targetIntel.id) {
this.IntelItems.splice(dexVal+ 1, 0, targetIntel);
result = "New intelligence file: " + targetIntel.topic;
} else {
var contentsCheck = targetIntel.addNewContents(intelAtIndex);
if (contentsCheck){
result = "Information updated: " + targetIntel.topic;
}
}
}
if (intelParameters.ShowAlerts) {
return result;
} else {
return null;
}
};
//Helper function for addIntel function; makes sure new intel is inserted alphabetically.
IntelList.prototype.findIndex = function (targetIntel) {
var index = 0;
var resultVal = 1;
while (index < this.IntelItems.length && resultVal < 0) {
resultVal = targetIntel.topic.localeCompare(this.IntelItems[index].topic);
if (resultVal > 0) { index++; }
}
return index;
};
//Function determines whether or not the specified intel is present in the player's intel inventory.
IntelList.prototype.hasIntel = function(targetIntel) {
//searchFunction must be defined this way due to how Array.some handles the function.
var searchFunction = function(intelFromList){
//The IntelItem.matches function checks to see if the intel item taken from the list has the same ID as well as all of the contents it has.
return targetIntel.matches(intelFromList);
};
return this.IntelItems.some(searchFunction);
};
//Returns an array of IntelItems with the specified topic.
IntelList.prototype.getIntelFromCategory = function(categoryName){
var result = [];
for (var index = 0; index < this.IntelItems.length; index++) {
if (this.IntelItems[index].category === categoryName) {
result.push(this.IntelItems[index]);
}
}
return result;
};
//Add initialization of IntelList to $gameParty
Game_Party.prototype.initialize = (function (original) {
"use strict";
function initialize() {
original.call(this);
this.IntelList = new IntelList();
}
return initialize;
}(Game_Party.prototype.initialize));
This is the section where I'm pretty sure I've messed up:
Code:
/*----------------------------------------------------------------------------*
* SCENE FUNCTIONS *
*----------------------------------------------------------------------------*/
//Patch in the handler for the Intel command.
Scene_Menu.prototype.createCommandWindow = (function (original) {
"use strict";
function createCommandWindow() {
original.call(this);
this._commandWindow.setHandler("intel", function () {
SceneManager.push(Scene_Intel);
});
}
return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));
//Patch the Intel command into the list of commands on the in-game menu.
Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
"use strict";
function addOriginalCommands() {
original.call(this);
this.addCommand("Intel", "intel", ($gameParty.IntelList.IntelItems.length > 0));
}
return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));
//Define initialization, prototype, and constructor.
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};
//Define creation and termination events.
Scene_Intel.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
//TODO: Add Help Window.
//TODO: Add Categories Window.
this.createIntelWindow();
};
Scene_Intel.prototype.terminate = function() {
Scene_MenuBase.prototype.terminate.call(this);
};
//Creates the windows that form the .
Scene_Intel.prototype.createIntelWindow = function() {
this._intelWindow = new Window_IntelList();
this._intelWindow.setHandler('cancel', this.popScene.bind(this));
this.addWindow(this._intelWindow);
};
/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
*----------------------------------------------------------------------------*/
function Window_IntelList() {this.initialize.apply(this, arguments);}
Window_IntelList.prototype = Object.create(Window_Selectable.prototype);
Window_IntelList.prototype.constructor = Window_IntelList;
Window_IntelList.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this._category = 'none';
this._data = [];
};
Window_IntelList.prototype.windowWidth = function() {
return Math.floor(Graphics.boxWidth * 0.4);
};
Window_IntelList.prototype.windowHeight = function() {
return Graphics.boxHeight;
};
Window_IntelList.prototype.maxCols = function() {return 1;};
Window_IntelList.prototype.maxItems = function() {return this._data ? this._data.length : 1; };
Window_IntelList.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding; };
Window_IntelList.prototype.item = function() {
var index = this.index();
return this._data && index >= 0 ? this._data[index] : null;
};
Window_IntelList.prototype.makeIntelList = function() {
//TODO: add category filtering.
this._data = $gameParty.IntelList.IntelItems;
};
Window_IntelList.prototype.drawAllTopics = function() {
for (var index = 0; index < this._data.length; index++) {
this.drawTopic(index);
};
};
Window_IntelList.prototype.drawTopic = function(index) {
var intel = this._data[index];
if (intel) {
var rect = this.itemRect(index);
rect.width -= this.textPadding();
this.drawText(intel.topic, rect.x, rect.y, rect.width);
}
};
I've confirmed that the initialization is working, and that the item is being successfully added to $gameParty.IntelList: after the corresponding event that calls the Plugin command to add the item from the json file, Intel becomes selectable.
However, no menu is actually drawn; all that happens is that the screen empties of the other menus (but stays blurred as if still in the menu system). Since the "cancel" event has been bound to the window it should allow me to back out, but does not. This means that I've either royally screwed up the window creation (probably because I've forgotten something critical), or the program is getting stuck in a loop somewhere.
EDIT: Fixed a typo that broke one of the SPOILER tags.
Last edited:
