Pretty Plugin Parameters - Death to the Note Tag!

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
Pretty Plugin Params v1.0

Introduction

Note: You do not need this plugin for any FROG plugins. This functionality has been baked into FROG_Core from the beginning. This is for you to use in your own plugins. My hope is that this plugin will be included in future versions of the RPG Maker MV software.

The new MV 1.5 plugin parameters are awesome! They really make things easy on developers. No more learning how each and every plugin maker designs their note tags. No more learning a bunch of note tag commands for every plugin in order just to use it. No more typos which cause things not to work or perhaps even crash your game. You just tell the plugin what values it needs and what types of data they collect.

It's much cleaner too. Asking a game dev to enter in complex data into note tags is just asking them to make mistakes and creates a lot of frustration. They might end up not even using your plugin if they can't get it to work. You also get the advantage of being able to supply a default configuration which makes it easy for devs to play around with your plugin without having to invest a lot of time and energy trying to set things up just to test.

But the designers of RMMV dropped the ball on one thing. As great as the new plugin parameters are, they didn't give plugin developers an easy way to get the data out in a usable fashion. When you read the data, you do get an object but only for the first layer. Everything contained within the this single layer of object properties is a big mess of strings that need to be run through JSON.parse constantly. It really gets in your way and largely becomes more trouble than it's worth. Because of this, most plugin developers have stuck with using note tags and all of the problems they bring. It's just too much work.

json3.PNG

Not any longer, though! This plugin completely corrects the major problem with using the MV 1.5 plugin parameter format by converting them from a gnarly mess of string data into a nice, easy to use JSON object like they were intended to be. With this plugin and one line of code, you'll get a cleanly formatted object with all of the data properly typed. Strings remain strings, numbers remain numbers, arrays stay arrays, objects are still objects and arrays of objects come out as arrays of objects. It's a beautiful thing, really. Brings a tear of joy to your eye.

json2.PNG


Features
  • Just one feature, converts plugin parameters into an easy to use JSON object.
  • Allows you to get complex with plugin parameters while also making it easy to retrieve this data.
  • Makes it easy to save this data along with the game data.

How to Use

Place this plugin above any other plugins that use it.

Just define a variable to store the plugin parameters and then pass it and the plugin parameters to the convert function.

Code:
var variable = {};
convertPluginParams(paramerters, variable);
Example:
Code:
var $pluginParams = {};
convertPluginParams(PluginManager.parameters('Filename of your plugin without the .js'), $pluginParams);
That's it! All of your plugin parameters, no matter how complex, can now be accessed in the variable you provided. Couldn't get much easier than that!

In addition to easily reading in plugin parameters, there's a couple of other things you can do with this. Now that your plugin parameters are all neatly tucked away in a JSON object, they are super simple to change in-game now. Say you have a parameter that sorts Quests either ascending or descending. You can give your players the option to change this to their liking in the game. If you allow these parameters to be changed in-game, though, you probably want to save these changes so that they aren't lost when the player closes the game, comes back later and the reloads their game. That's really easy to do now.

The example below assumes that there is a plugin parameter named saveParamObject (or Save Param Object if camel-case is turned on). It aliases setupNewGame, makeSaveContents and extractSaveContents to handle resetting parameters on new game, saving them and loading them so that any changes can be preserved. I now include these options by default in every plugin I make.

Code:
// Refresh plugin parameters on new game
var alias_DataManager_setupNewGame = DataManager.setupNewGame;
DataManager.setupNewGame = function () {
    alias_DataManager_setupNewGame.call(this);
    convertPluginParams(PluginManager.parameters('Filename'), $pluginParams);
}

// Save File
var alias_DataManager_MakeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
    var contents = alias_DataManager_MakeSaveContents.call(this);
    if ($pluginParams.saveParamObject === true) {
        contents.pluginParams = $pluginParams;
    }
    return contents;
}

// Load File
var alias_DataManager_ExtractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
    alias_DataManager_ExtractSaveContents.call(this, contents);
    if ($pluginParams.saveParamObject === true) {
        $pluginParams = contents.pluginParams;
    }
}

Camel-case Properties - This option will convert your plugin's parameter names into more usable property names. By default, the property names come over as the @param used in the plugin editor and will often contain white space so you'll end up with something like Class Id. This forces you to use these property names with the less desirable bracket notation, something like $params['Class Id']. Who wants to do that? This option will ditch the spaces and lowercase the first letter so that you can reference the property as $params.classId which is much cleaner.

There is an option to define your parameter labels with @text and then use @param to make your property name anything you want (like classId). This is actually a better option and if you set up your plugin this way, leave this option off.


Terms of Use

MIT License

Copyright (c) 2018 Stephen Sandford (Frogboy) <https://frogboymv.github.io/>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Change Log
  • Version 1.0 - Initial release

Download

https://github.com/FrogboyMV/MiscPlugins

Demo project also available if you want an easy way to see this in action.
 
Last edited:

Roguedeus

It's never too late to procrastinate...
Veteran
Joined
Mar 19, 2013
Messages
527
Reaction score
106
First Language
English
Primarily Uses
N/A
Good idea. ;)

I was going to use your Core for this.
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
Good idea. ;)

I was going to use your Core for this.
Yeah, you don't need to tie your work to mine just for this. I feel that this functionality should have been included with the 1.5 plugin format from the start. Feel free to use the plugin as is or include it into your own core plugin if you make one. That's why I open sourced it and didn't specifically make this a FROG plugin.
 
Last edited:

Roguedeus

It's never too late to procrastinate...
Veteran
Joined
Mar 19, 2013
Messages
527
Reaction score
106
First Language
English
Primarily Uses
N/A
Just noticed that some of the functionality may need some clarification.

The way that object properties are created, auto generates Camel Case keys. This is not very clear in the use instructions.

Also, the fact that you'll need to keep that change in mind when comparing it to the JSON.parse TEXT generated by the tool set.

{"Require Actor Select":"true"} is Object.requireActorSelect now.

Perhaps a few examples would help. :)

Edit:
You may also want to demonstrate how easy this plugin makes editing the parameters while in game...

I am going to be making regular use of your save/extract code for this!

Edit2:
I may have just found a bug with the Save Param Object functionality.

When accessing the Parameter Object from a new game, after just ending a game by returning to title (rather than shutting down to windows) the object data does not get recreated for the new game.

Moving the DataManager.isDatabaseLoaded alias into the DataManager.setupNewGame function fixed it for me. Is there a reason this shouldn't be moved there?

Example:

Code:
$.DataManager_setupNewGame = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
  $.DataManager_setupNewGame.call(this);
  if($.Parameters) {
    convertPluginParams(PluginManager.parameters('RD_template'), $.Parameters);
  }
}
 
Last edited:

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
The way that object properties are created, auto generates Camel Case keys. This is not very clear in the use instructions.
You're right. I should go into more detail on this.

You may also want to demonstrate how easy this plugin makes editing the parameters while in game..
I can do this as well. Give some example code for this.

When accessing the Parameter Object from a new game, after just ending a game by returning to title (rather than shutting down to windows) the object data does not get recreated for the new game.
Good catch! I'm going to have to update most of my plugins to account for this. Thanks for pointing that out. Well, I know what I'll be doing tonight. :)
 

eXalted

Veteran
Veteran
Joined
Oct 29, 2017
Messages
30
Reaction score
14
First Language
English
Primarily Uses
RMMV
This is beautiful and really got me thinking why something like this is not included. Have you contacted the RPG Maker devs?
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
@eXalted
I have not. Not sure how I should go about doing such a thing. Looks like I need to do a little updating to the docs for this one first but I'd be happy to request an official "this should be added to the core code" if I learn the proper channels.
 

LTN Games

Veteran
Veteran
Joined
Jun 25, 2015
Messages
645
Reaction score
504
First Language
English
Primarily Uses
RMMV
If all you're trying to do with this is convert the parameters to their correct type value, arrays, numbers, objects etc then you have a whole lot of code for a simple task. Mind you, you may have a reason for this in which case it's all good but I've found out about a month ago how over complicated I made my convert parameters as well. Mine was about 60+ lines code, and I found out that you can do it in about half of that and without all the extra type checking and converting. I was mind boggled because I swear I did it this way(code below) a long time ago but it never worked correctly with nested lists etc but I believe I did it wrong all that time ago and made a much more complicated version. You can thank @waynee95 for bringing it to my attention about a month ago.

PHP:
const parseParameters = function (params) {
  let obj
  const isObject = () => params && typeof params === 'object'

  try {
    obj = JSON.parse(isObject() ? JSON.stringify(params) : params)
  } catch (e) {
    throw new Error(e)
  }

  if (isObject()) {
    Object.keys(obj).forEach(key => {
      obj[key] = parseParameters(obj[key])

      if (obj[key] === '') {
        obj[key] = null
      }
    })
  }
  return obj
}
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
@LTN Games
Looks sweet! I don't doubt that what I'm doing can be done in less code. I tend to be more verbose to keep things easy to read and understand. I can play around with this a bit, though. Do you think that this might not have originally worked due to the earlier version of ES support? I feel like I originally tried something similar but had to separate handling Arrays from handling Objects. Perhaps the update to ES6 is what makes this easier to condense?

Thanks for the input. I do want to make sure this stays compatible with 1.5 due to the high number of devs who are still on it but I'll check to see if this same logic can be used to tighten it up.
 

LTN Games

Veteran
Veteran
Joined
Jun 25, 2015
Messages
645
Reaction score
504
First Language
English
Primarily Uses
RMMV
I don't think it has to do with ES6, I believe all the magic is in this one line of code. I think when I originally tried it I never did a check to stringify the params if it's an object and simply attempted to parse the params as they were given.

PHP:
 JSON.parse(isObject() ? JSON.stringify(params) : params)
Mind you this way of doing it assumes your parameters are setup like this

Code:
 * @param myParam
 * @text My Parameter
 * @desc This is my parameter
 * @type boolean
 * @default false
Either way I figured I would share this as I was kind of awe struck when I first heard about it and I figured you would benefit from it too, or be totally awe struck like I was :p
 

Frogboy

I'm not weak to fire
Veteran
Joined
Apr 19, 2016
Messages
1,676
Reaction score
2,122
First Language
English
Primarily Uses
RMMV
@LTN Games
Yeah, it's funny. When I originally wrote this, I didn't know about parameter attribute that sets its property name which is why I used the pseudo camel-case conversion. I'll have to think about removing this and just having the dev specify exactly what name they want to use as that fits with the intention of the 1.5 plugin format anyway.

Ah, I see. Didn't think JavaScript would auto-type the properties like that but it's definitely cool that it does. You didn't run into any exceptions with this method, I assume.


Updated this plugin to, well, I'm still calling it v1.0
  • Mostly added more clarification to the documentation and some examples of how to reset, save and load plugin parameters if you want to allow them to be changed in-game.
  • I did add an option to turn the automatic camel-casing of parameter names on or off in case you don't want to use this feature.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Writing out an idea for the No Travel Game Jam. I have a general plot and challenge written out, it's just a matter of filling the rest in and making it interesting.
A definite difficult time right now. How is everyone doing during this pandemic? I already have seen furloughs and layoffs.
Hollow 1977 wrote on Archeia's profile.
Hope you and your family are doing well during this difficult time. :)
My elderly neighbor whom I've been buying groceries for just got carried out of his home on a stretcher by guys with hazmat suits. Considering I've been his only point of contact for the past month it's probably safe to say my boss was right to tell me to stay home once I developed a mild cough after all.
Damn. All these new features to the forums. Takes some getting used to.

Forum statistics

Threads
95,641
Messages
930,672
Members
125,962
Latest member
seogenics
Top