Advertisement
Double_X

DoubleX RMMV Skill Progress Unit Test v100a

Dec 3rd, 2019 (edited)
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name
  5.  *      DoubleX RMMV Skill Progress Unit Test
  6.  *----------------------------------------------------------------------------
  7.  *    # Introduction
  8.  *    1. This plugin performs some rudimetary invariants checking for the
  9.  *       implementations of DoubleX RMMV Skill Progress, and some elementary
  10.  *       value validity checking for the parameters/configurations/notetags of
  11.  *       DoubleX RMMV Skill Progress
  12.  *    2. You can setup how this plugin displays the failed test messages with
  13.  *       their stacktraces
  14.  *----------------------------------------------------------------------------
  15.  *    # Terms Of Use
  16.  *      1. Commercial use's always allowed and crediting me's always optional.
  17.  *      2. You shall keep this plugin's Plugin Info part's contents intact.
  18.  *      3. You shalln't claim that this plugin's written by anyone other than
  19.  *         DoubleX or my aliases. I always reserve the right to deny you from
  20.  *         using any of my plugins anymore if you've violated this.
  21.  *      4. If you repost this plugin directly(rather than just linking back),
  22.  *         you shall inform me of these direct repostings. I always reserve
  23.  *         the right to request you to edit those direct repostings.
  24.  *      5. CC BY 4.0, except those conflicting with any of the above, applies
  25.  *         to this plugin, unless you've my permissions not needing follow so.
  26.  *      6. I always reserve the right to deny you from using this plugin
  27.  *         anymore if you've violated any of the above.
  28.  *----------------------------------------------------------------------------
  29.  *    # Prerequisites
  30.  *      Plugins:
  31.  *      1. DoubleX RMMV Skill Progress
  32.  *      Abilities:
  33.  *      1. Nothing special for most ordinary cases
  34.  *      2. Little RMMV plugin development proficiency to fully utilize this
  35.  *----------------------------------------------------------------------------
  36.  *    # Author Notes
  37.  *      1. Using this plugin might lead to noticeable performance penalties
  38.  *----------------------------------------------------------------------------
  39.  *    # Links
  40.  *      DoubleX RMMV Skill Progress:
  41.  *      1. https://pastebin.com/6XdtFJYD
  42.  *      This plugin:
  43.  *      1. https://pastebin.com/NzQVER8u
  44.  *      Mentioned Patreon Supporters:
  45.  *      https://www.patreon.com/posts/71738797
  46.  *----------------------------------------------------------------------------
  47.  *    # Instructions
  48.  *      1. Place this plugin right below DoubleX RMMV Skill Progress
  49.  *----------------------------------------------------------------------------
  50.  *    # Author
  51.  *      DoubleX
  52.  *----------------------------------------------------------------------------
  53.  *    # Changelog
  54.  *      v1.00a(GMT 1000 4-Dec-2019):
  55.  *      1. 1st version of this plugin finished
  56.  *============================================================================*/
  57. /*:
  58.  * @plugindesc Lets you run some unit tests for DoubleX RMMV Skill Progress
  59.  * This plugin's entirely optional and is mainly for debuggers/developers
  60.  * @author DoubleX
  61.  *
  62.  *============================================================================
  63.  */
  64.  
  65. var DoubleX_RMMV = DoubleX_RMMV || {};
  66. DoubleX_RMMV["Skill Progress Unit Test"] = "v1.00a";
  67.  
  68. /*============================================================================
  69.  *    ## Plugin Configurations
  70.  *       You only need to edit this part as it's about what this plugin does
  71.  *----------------------------------------------------------------------------*/
  72.  
  73. DoubleX_RMMV.Skill_Progress_Unit_Test = {
  74.  
  75.     /**
  76.      * Shows the failed parameter test with its value, condition and error
  77.      * Hotspot/No-op
  78.      * @since v1.00a @version v1.00a
  79.      * @param {*} val - The actual parameter value
  80.      * @param {String} param - The parameter being tested
  81.      * @param {String} cond - The parameter validity condition description
  82.      */
  83.     showFailMsg: function(val, param, cond) {
  84.         try { x; } catch (err) {
  85.             console.warn([
  86.                 "The " + param + " in DoubleX RMMV Skill Progress has value:",
  87.                 val,
  88.                 "Which isn't valid because:",
  89.                 cond,
  90.                 "The source is shown by this stacktrace:",
  91.                 err.stack
  92.             ].join("\n"));
  93.         }
  94.     } // showFailMsg
  95.  
  96. }; // DoubleX_RMMV.Skill_Progress
  97.  
  98. /*============================================================================
  99.  *    ## Plugin Implementations
  100.  *       You need not edit this part as it's about how this plugin works
  101.  *----------------------------------------------------------------------------
  102.  *    # Plugin Support Info:
  103.  *      1. Prerequisites
  104.  *         - Basic knowledge on what unit tests do
  105.  *         - Some RMMV plugin development proficiency to fully comprehend this
  106.  *----------------------------------------------------------------------------*/
  107.  
  108. if (DoubleX_RMMV["Skill Progress"]) {
  109.  
  110. /*----------------------------------------------------------------------------*/
  111.  
  112. (function(SP, SPUT) {
  113.  
  114.     "use strict";
  115.  
  116.     // Stores all the original parameter/configuration/notetag functions
  117.     SPUT.orig = { params: {}, cfgs: {}, notes: {} };
  118.     //
  119.  
  120.     // Stores all the parameter/configuration/notetag function unit tests
  121.     SPUT.unitTest = {
  122.         // Stores all the parameter function unit tests
  123.         params: {
  124.             isEnabled: "checkBool",
  125.             condNotePriority: "checkArrayDataType",
  126.             condNoteChainingRule: "checkChainBoolRule",
  127.             defaultMax: "checkPositiveNum",
  128.             maxNotePriority: "checkArrayDataType",
  129.             maxNoteChainingRule: "checkChainNumRule",
  130.             defaultUseGain: "checkNum",
  131.             useGainNotePriority: "checkArrayDataType",
  132.             useGainNoteChainingRule: "checkChainNumRule",
  133.             defaultHitGain: "checkNum",
  134.             hitGainNotePriority: "checkArrayDataType",
  135.             hitGainNoteChainingRule: "checkChainNumRule",
  136.             nextNotePriority: "checkArrayDataType",
  137.             nextNoteChainingRule: "checkChainListRule",
  138.             defaultKeepCurrent: "checkBool",
  139.             keepCurrentNotePriority: "checkArrayDataType",
  140.             keepCurrentNoteChainingRule: "checkChainBoolRule",
  141.             // There's no need to test this parameter as it returns nothing
  142.             willEnd: "",
  143.             //
  144.             willEndNotePriority: "checkArrayDataType",
  145.             willEndNoteChainingRule: "checkChainListRule",
  146.             // There's no need to test this parameter as it returns nothing
  147.             didEnd: "",
  148.             //
  149.             didEndNotePriority: "checkArrayDataType",
  150.             didEndNoteChainingRule: "checkChainListRule",
  151.             cmdLineH: "checkPositiveNum",
  152.             cmdFontSize: "checkPositiveNum",
  153.             cmdPadding: "checkNonnegativeNum",
  154.             cmdTextPadding: "checkNonnegativeNum",
  155.             cmdBackOpacity: "checkOpacity",
  156.             cmdTranslucentOpacity: "checkOpacity",
  157.             cmdSpacing: "checkNonnegativeNum",
  158.             cmdWinW: "checkPositiveNum",
  159.             cmdWinH: "checkPositiveNum",
  160.             cmdWinX: "checkNum",
  161.             cmdWinY: "checkNum",
  162.             cmdView: "checkString",
  163.             cmdUse: "checkString",
  164.             statLineH: "checkPositiveNum",
  165.             statFontSize: "checkPositiveNum",
  166.             statPadding: "checkNonnegativeNum",
  167.             statTextPadding: "checkNonnegativeNum",
  168.             statBackOpacity: "checkOpacity",
  169.             statTranslucentOpacity: "checkOpacity",
  170.             statSpacing: "checkNonnegativeNum",
  171.             statWinW: "checkPositiveNum",
  172.             statWinH: "checkPositiveNum",
  173.             statWinX: "checkNum",
  174.             statWinY: "checkNum",
  175.             condLineH: "checkPositiveNum",
  176.             condFontSize: "checkPositiveNum",
  177.             condPadding: "checkNonnegativeNum",
  178.             condTextPadding: "checkNonnegativeNum",
  179.             condBackOpacity: "checkOpacity",
  180.             condTranslucentOpacity: "checkOpacity",
  181.             condSpacing: "checkNonnegativeNum",
  182.             condWinW: "checkPositiveNum",
  183.             condWinH: "checkPositiveNum",
  184.             condWinX: "checkNum",
  185.             condWinY: "checkNum",
  186.             nextLineH: "checkPositiveNum",
  187.             nextFontSize: "checkPositiveNum",
  188.             nextPadding: "checkNonnegativeNum",
  189.             nextTextPadding: "checkNonnegativeNum",
  190.             nextBackOpacity: "checkOpacity",
  191.             nextTranslucentOpacity: "checkOpacity",
  192.             nextSpacing: "checkNonnegativeNum",
  193.             nextWinW: "checkPositiveNum",
  194.             nextWinH: "checkPositiveNum",
  195.             nextWinX: "checkNum",
  196.             nextWinY: "checkNum",
  197.             varIds: "checkIdVarArrayNoteFactorObj",
  198.             switchIds: "checkIdSwitchArrayNoteFactorObj"
  199.         }, // params
  200.         // Stores all the configuration function unit tests
  201.         cfgs: {
  202.           // There's no need to test this parameter as it returns nothing
  203.           drawStat: ""
  204.           //
  205.         }, // cfgs
  206.         //
  207.         notes: {}, // Stores all the notetag function unit tests
  208.         // Stores all the notetag type result unit tests
  209.         noteTypes: {
  210.             cond: "checkArray",
  211.             max: "checkPositiveNumArray",
  212.             useGain: "checkNumArray",
  213.             hitGain: "checkNumArray",
  214.             next: "checkIdSkillArray",
  215.             keepCurrent: "checkArray",
  216.             // There's no need to test these parameters as they return nothing
  217.             willEnd: "",
  218.             didEnd: ""
  219.             //
  220.         },
  221.         //
  222.         // Stores all the chained notetag type result unit tests
  223.         chainedNoteTypes: {
  224.             cond: "checkBoolObj",
  225.             max: "checkPositiveNum",
  226.             useGain: "checkNum",
  227.             hitGain: "checkNum",
  228.             next: "checkIdSkillArray",
  229.             keepCurrent: "checkBool",
  230.             // There's no need to test these parameters as they return nothing
  231.             willEnd: "",
  232.             didEnd: ""
  233.             //
  234.         }
  235.         //
  236.     }; // SPUT.unitTest
  237.  
  238.     // There's no need to test this parameter as it's always valid
  239.     var notes = SPUT.unitTest.notes, checkFunc = new Function("val", "");
  240.     //
  241.     Object.keys(SP.notes).forEach(function(note) { notes[note] = checkFunc; });
  242.  
  243.     // Stores all the unit test value validity checks
  244.     SPUT.checkFuncs = {
  245.  
  246.         /**
  247.          * Hotspot/Pure Function
  248.          * @param {*} val - The actual parameter value
  249.          * @param {String} param - The parameter being tested
  250.          * @returns {Boolean} The check result
  251.          * @since v1.00a @version v1.00a
  252.          */
  253.         checkArray: function(val, param) {
  254.             if (Array.isArray(val)) return true;
  255.             return SPUT.showFailMsg(val, param, "It should be an Array!");
  256.         }, // checkArray
  257.  
  258.         /**
  259.          * Hotspot/No-op
  260.          * @param {*} val - The actual parameter value
  261.          * @param {String} param - The parameter being tested
  262.          * @since v1.00a @version v1.00a
  263.          */
  264.         checkArrayDataType: function(val, param) {
  265.             SPUT.checkFuncs.checkArrayVals(val, param,
  266.                     ["states", "armors", "weapons", "currentClass", "actor"]);
  267.         }, // checkArrayDataType
  268.  
  269.         /**
  270.          * Hotspot/No-op
  271.          * @param {*} val - The actual parameter value
  272.          * @param {String} param - The parameter being tested
  273.          * @param {[]} vals - The list of valid primitive values
  274.          * @since v1.00a @version v1.00a
  275.          */
  276.         checkArrayVals: function(val, param, vals) {
  277.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  278.             var cond = [
  279.                 "These elements should be within " + vals + ":"
  280.             ].concat(val.map(function(v, i) {
  281.                 return vals.indexOf(v) >= 0 ? "" : v + " with index " + i;
  282.             }).filter(function(m) { return m; }));
  283.             if (cond.length <= 1) return;
  284.             SPUT.showFailMsg(JSON.stringify(val), param, cond.join("\n"));
  285.         }, // checkArrayVals
  286.  
  287.         /**
  288.          * Hotspot/No-op
  289.          * @param {*} val - The actual parameter value
  290.          * @param {String} param - The parameter being tested
  291.          * @since v1.00a @version v1.00a
  292.          */
  293.         checkBool: function(val, param) {
  294.             if (val === !!val) return;
  295.             SPUT.showFailMsg(val, param, "It should be a Boolean!");
  296.         }, // checkBool
  297.  
  298.         /**
  299.          * Hotspot/No-op
  300.          * @param {*} val - The actual parameter value
  301.          * @param {String} param - The parameter being tested
  302.          * @since v1.00a @version v1.00a
  303.          */
  304.         checkBoolObj: function(val, param) {
  305.             if (!SPUT.checkFuncs.checkObj(val, param)) return;
  306.             Object.keys(val).forEach(function(key) {
  307.                 SPUT.checkFuncs.checkBool(val[key], JSON.stringify({
  308.                     param: param,
  309.                     key: key
  310.                 }));
  311.             });
  312.         }, // checkBoolObj
  313.  
  314.         /**
  315.          * Hotspot/No-op
  316.          * @param {*} val - The actual parameter value
  317.          * @param {String} param - The parameter being tested
  318.          * @since v1.00a @version v1.00a
  319.          */
  320.         checkChainBoolRule: function(val, param) {
  321.             SPUT.checkFuncs.checkVal(
  322.                     val, param, ["first", "every", "last", "some"]);
  323.         }, // checkChainBoolRule
  324.  
  325.         /**
  326.          * Hotspot/No-op
  327.          * @param {*} val - The actual parameter value
  328.          * @param {String} param - The parameter being tested
  329.          * @since v1.00a @version v1.00a
  330.          */
  331.         checkChainListRule: function(val, param) {
  332.             SPUT.checkFuncs.checkVal(val, param, Object.keys(
  333.                     SP.Game_SkillProgressRules._RUN_CHAINING_RULES));
  334.         }, // checkChainListRule
  335.  
  336.         /**
  337.          * Hotspot/No-op
  338.          * @param {*} val - The actual parameter value
  339.          * @param {String} param - The parameter being tested
  340.          * @since v1.00a @version v1.00a
  341.          */
  342.         checkChainNumRule: function(val, param) {
  343.             SPUT.checkFuncs.checkVal(val, param,
  344.                     ["first", "+", "-", "*", "/", "%", "=", "last"]);
  345.         }, // checkChainNumRule
  346.  
  347.         /**
  348.          * Hotspot/No-op
  349.          * @param {*} val - The actual parameter value
  350.          * @param {String} param - The parameter being tested
  351.          * @param {[{}]} data - The list of data to check the id array
  352.          * @param {String} type - The data container name
  353.          * @since v1.00a @version v1.00a
  354.          */
  355.         checkIdDataArray: function(val, param, data, type) {
  356.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  357.             var cond = [
  358.                 "These elements should be a valid " + type + " id :"
  359.             ].concat(val.map(function(v, i) {
  360.                 var d = data[v];
  361.                 return d || d === false ? "" : v + " with index " + i;
  362.             }).filter(function(m) { return m; }));
  363.             if (cond.length <= 1) return;
  364.             SPUT.showFailMsg(JSON.stringify(val), param, cond.join("\n"));
  365.         }, // checkIdDataArray
  366.  
  367.         /**
  368.          * Hotspot/No-op
  369.          * @param {*} val - The actual parameter value
  370.          * @param {String} param - The parameter being tested
  371.          * @param {[{}]} data - The list of data to check the id array
  372.          * @param {String} type - The data container name
  373.          * @since v1.00a @version v1.00a
  374.          */
  375.         checkIdGameArrayNoteFactorObj: function(val, param, data, type) {
  376.             if (Array.isArray(val)) {
  377.                 return SPUT.checkFuncs.checkIdDataArray(val, param, data, type);
  378.             }
  379.             if (!SPUT.checkFuncs.checkObj(val, param)) return;
  380.             var ids = Object.keys(val);
  381.             SPUT.checkFuncs.checkIdDataArray(ids.map(function(id) {
  382.                 return +id;
  383.             }), param, data, type);
  384.             var _SP = SP.Game_SkillProgressCache;
  385.             var notes = _SP._NOTES, factors = _SP._FACTORS;
  386.             ids.forEach(function(id) {
  387.                 var noteFactors = ids[id];
  388.                 SPUT.checkFuncs.checkArrayVals(noteFactors.notes, param, notes);
  389.                 SPUT.checkFuncs.checkArrayVals(
  390.                         noteFactors.factors, param, factors);
  391.             });
  392.         }, // checkIdGameArrayNoteFactorObj
  393.  
  394.         /**
  395.          * Hotspot/No-op
  396.          * @param {*} val - The actual parameter value
  397.          * @param {String} param - The parameter being tested
  398.          * @since v1.00a @version v1.00a
  399.          */
  400.         checkIdSkillArray: function(val, param) {
  401.             SPUT.checkFuncs.checkIdDataArray(
  402.                     val, param, $dataSkills, "skill");
  403.         }, // checkIdSkillArray
  404.  
  405.         /**
  406.          * Hotspot/No-op
  407.          * @param {*} val - The actual parameter value
  408.          * @param {String} param - The parameter being tested
  409.          * @since v1.00a @version v1.00a
  410.          */
  411.         checkIdSwitchArrayNoteFactorObj: function(val, param) {
  412.             SPUT.checkFuncs.checkIdGameArrayNoteFactorObj(
  413.                     val, param, $gameSwitches._data, "switch");
  414.         }, // checkIdSwitchArrayNoteFactorObj
  415.  
  416.         /**
  417.          * Hotspot/No-op
  418.          * @param {*} val - The actual parameter value
  419.          * @param {String} param - The parameter being tested
  420.          * @since v1.00a @version v1.00a
  421.          */
  422.         checkIdVarArrayNoteFactorObj: function(val, param) {
  423.             SPUT.checkFuncs.checkIdGameArrayNoteFactorObj(
  424.                     val, param, $gameVariables._data, "variable");
  425.         }, // checkIdVarArrayNoteFactorObj
  426.  
  427.         /**
  428.          * Hotspot/No-op
  429.          * @param {*} val - The actual parameter value
  430.          * @param {String} param - The parameter being tested
  431.          * @since v1.00a @version v1.00a
  432.          */
  433.         checkNonnegativeNum: function(val, param) {
  434.             if (isNaN(val) || val < 0) SPUT.showFailMsg(
  435.                     val, param, "It should be a nonnegative Number!");
  436.         }, // checkNonnegativeNum
  437.  
  438.         /**
  439.          * Hotspot/No-op
  440.          * @param {*} val - The actual parameter value
  441.          * @param {String} param - The parameter being tested
  442.          * @since v1.00a @version v1.00a
  443.          */
  444.         checkNum: function(val, param) {
  445.             if (!isNaN(val)) return;
  446.             SPUT.showFailMsg(val, param, "It should be a Number!");
  447.         }, // checkNum
  448.  
  449.         /**
  450.          * Hotspot/No-op
  451.          * @param {*} val - The actual parameter value
  452.          * @param {String} param - The parameter being tested
  453.          * @since v1.00a @version v1.00a
  454.          */
  455.         checkNumArray: function(val, param) {
  456.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  457.             val.forEach(function(v, i) {
  458.                 SPUT.checkFuncs.checkNum(v,
  459.                         JSON.stringify({ array: val, index: i, param: param }));
  460.             });
  461.         }, // checkNumArray
  462.  
  463.         /**
  464.          * Hotspot/No-op
  465.          * @param {*} val - The actual parameter value
  466.          * @param {String} param - The parameter being tested
  467.          * @returns {Boolean} The check result
  468.          * @since v1.00a @version v1.00a
  469.          */
  470.         checkObj: function(val, param) {
  471.             if (val === Object(val)) return true;
  472.             return SPUT.showFailMsg(val, param, "It should be an Object!");
  473.         }, // checkObj
  474.  
  475.         /**
  476.          * Hotspot/No-op
  477.          * @param {*} val - The actual parameter value
  478.          * @param {String} param - The parameter being tested
  479.          * @since v1.00a @version v1.00a
  480.          */
  481.         checkOpacity: function(val, param) {
  482.               if (isNaN(val) || val < 0 && val > 255) SPUT.showFailMsg(val,
  483.                       param, "It should be a Number ranging from 0 to 255!");
  484.         }, // checkOpacity
  485.  
  486.         /**
  487.          * Hotspot/No-op
  488.          * @param {*} val - The actual parameter value
  489.          * @param {String} param - The parameter being tested
  490.          * @since v1.00a @version v1.00a
  491.          */
  492.         checkPositiveNum: function(val, param) {
  493.             if (!isNaN(val) && val > 0) return;
  494.             SPUT.showFailMsg(val, param, "It should be a positive Number!");
  495.         }, // checkPositiveNum
  496.  
  497.         /**
  498.          * Hotspot/No-op
  499.          * @param {*} val - The actual parameter value
  500.          * @param {String} param - The parameter being tested
  501.          * @since v1.00a @version v1.00a
  502.          */
  503.         checkPositiveNumArray: function(val, param) {
  504.             if (!SPUT.checkFuncs.checkArray(val, param)) return;
  505.             val.forEach(function(v, i) {
  506.                 SPUT.checkFuncs.checkPositiveNum(v,
  507.                         JSON.stringify({ array: val, index: i, param: param }));
  508.             });
  509.         }, // checkPositiveNumArray
  510.  
  511.         /**
  512.          * Hotspot/No-op
  513.          * @param {*} val - The actual parameter value
  514.          * @param {String} param - The parameter being tested
  515.          * @since v1.00a @version v1.00a
  516.          */
  517.         checkString: function(val, param) {
  518.             if (typeof val === "string" || val instanceof String) return;
  519.             SPUT.showFailMsg(val, param, "It should be a String!");
  520.         }, // checkString
  521.  
  522.         /**
  523.          * Hotspot/No-op
  524.          * @param {*} val - The actual parameter value
  525.          * @param {String} param - The parameter being tested
  526.          * @param {[*]} vals - The list of valid values
  527.          * @since v1.00a @version v1.00a
  528.          */
  529.         checkVal: function(val, param, vals) {
  530.             if (vals.indexOf(val) >= 0) return;
  531.             SPUT.showFailMsg(val, param, "It should be within " + vals + "!");
  532.         } // checkVal
  533.  
  534.     }; // SPUT.checkFuncs
  535.     //
  536.  
  537.     /**
  538.      * Pure function
  539.      * @param {String} type - The parameter/configuration/notetag indicator
  540.      * @param {String} param - The parameter being tested
  541.      * @param {(*, String)} checkFunc - The function checking the actual value
  542.      * @returns {() -> *} The function returning the original result
  543.      * @since v1.00a @version v1.00a
  544.      */
  545.     SPUT.unitTestFunc = function(type, param, checkFunc) {
  546.         /**
  547.          * The this pointer refers to that of the original function counterpart
  548.          * Nullipotent
  549.          * @author DoubleX
  550.          * @returns {*} The requested result
  551.          * @since v1.00a
  552.          * @version v1.00a
  553.          */
  554.         return function() {
  555.             // It's possible that SPUT.orig[type][param] will change on the fly
  556.             var val = SPUT.orig[type][param].apply(this, arguments);
  557.             //
  558.             // Added to test the parameter/configuration/notetag value validity
  559.             checkFunc(val, type + "." + param);
  560.             //
  561.             return val;
  562.         };
  563.  
  564.     }; // SPUT.unitTestFunc
  565.  
  566. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  567.  
  568. /*----------------------------------------------------------------------------
  569.  *    # Edit class: DataManager
  570.  *      - Extends all parameter/configuration/notetag functions upon load game
  571.  *----------------------------------------------------------------------------*/
  572.  
  573. (function(SP, SPUT) {
  574.  
  575.     "use strict";
  576.  
  577.     SP.DataManager.unitTest = { orig: {}, new: {} };
  578.     var _SP = SP.DataManager.new;
  579.     var _DM = SP.DataManager.unitTest.orig, _UT = SP.DataManager.unitTest.new;
  580.  
  581.     _DM._extractFuncContent = _SP._extractFuncContent;
  582.     _SP._extractFuncContent = function(funcType, content) {
  583.     // v1.00a - v1.00a; Extended
  584.         _DM._extractFuncContent.apply(this, arguments);
  585.         // Added to unit test the value validity of param/cfg/note functions
  586.         _UT._extractFuncContent.call(this, funcType, content);
  587.         //
  588.     }; // _SP._extractFuncContent
  589.  
  590.     /**
  591.      * The this pointer is DataManager
  592.      * @param {String} funcType - The parameter/configuration/notetag label
  593.      * @param {String} content - The name of the stored function content
  594.      * @since v1.00a @version v1.00a
  595.      */
  596.     _UT._extractFuncContent = function(funcType, content) {
  597.         // This function should be so stable that it shouldn't be changed later
  598.         var checkFunc = SPUT.checkFuncs[SPUT.unitTest[funcType][content]];
  599.         //
  600.         if (!checkFunc) return;
  601.         SPUT.orig[funcType][content] = SP[funcType][content];
  602.         // Using partial application here would erase the function context
  603.         SP[funcType][content] = SPUT.unitTestFunc(funcType, content, checkFunc);
  604.         //
  605.     }; // _UT._extractFuncContent
  606.  
  607. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  608.  
  609. /*----------------------------------------------------------------------------
  610.  *    # Edit class: Game_System
  611.  *      - Extends all parameter/configuration/notetag functions upon load game
  612.  *----------------------------------------------------------------------------*/
  613.  
  614. (function(SP, SPUT) {
  615.  
  616.     "use strict";
  617.  
  618.     SP.Game_System.unitTest = { orig: {}, new: {} };
  619.     var _SP = SP.Game_System.new;
  620.     var _GS = SP.Game_System.unitTest.orig, _UT = SP.Game_System.unitTest.new;
  621.  
  622.     _GS._storeParam = _SP._storeParam;
  623.     _SP._storeParam = function(params, param) { // v1.00a - v1.00a; Extended
  624.         // Added to prevent storing the extended parameter function contents
  625.         if (SPUT.orig.params[param]) return;
  626.         //
  627.         _GS._storeParam.apply(this, arguments);
  628.         // Added to unit test the value validity of all parameter functions
  629.         _UT._storeCfg.call(this, "params", param);
  630.         //
  631.     }; // _SP._storeParam
  632.  
  633.     _GS._storeCfg = _SP._storeCfg;
  634.     _SP._storeCfg = function(cfgType, cfg) { // v1.00a - v1.00a; Extended
  635.         // Edited to prevent storing the extended cfg/note function contents
  636.         if (SPUT.orig[cfgType][cfg]) return;
  637.         //
  638.         _GS._storeCfg.apply(this, arguments);
  639.         // Added to unit test the value validity of all cfg/note functions
  640.         _UT._storeCfg.call(this, cfgType, cfg);
  641.         //
  642.     }; // _SP._storeCfg
  643.  
  644.     /**
  645.      * The this pointer is Game_Actor.prototype
  646.      * @param {String} cfgType - The configuration type label
  647.      * @param {String} cfg - The name of the configuration
  648.      * @since v1.00a @version v1.00a
  649.      */
  650.     _UT._storeCfg = function(cfgType, cfg) {
  651.         // This function should be so stable that it shouldn't be changed later
  652.         var checkFunc = SPUT.checkFuncs[SPUT.unitTest[cfgType][cfg]];
  653.         //
  654.         if (!checkFunc) return;
  655.         SPUT.orig[cfgType][cfg] = SP[cfgType][cfg];
  656.         // Using partial application here would erase the function context
  657.         SP[cfgType][cfg] = SPUT.unitTestFunc(cfgType, cfg, checkFunc);
  658.         //
  659.     }; // _UT._storeCfg
  660.  
  661. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  662.  
  663. /*----------------------------------------------------------------------------
  664.  *    # Edit class: Game_Actor
  665.  *      - Unit tests all the nontrivial non-tautological class invariants
  666.  *----------------------------------------------------------------------------*/
  667.  
  668. (function(SP, SPUT) {
  669.  
  670.     "use strict";
  671.  
  672.     SP.Game_Actor.unitTest = { orig: {}, new: {} };
  673.     var _SP = SP.Game_Actor.new, $ = Game_Actor.prototype;
  674.     var _GA = SP.Game_Actor.unitTest.orig, _UT = SP.Game_Actor.unitTest.new;
  675.  
  676.     // Only interfaces will have their argument invariants checked
  677.     Object.keys(_SP._RESULT_FUNCS).concat([
  678.         "onUseGainSkillProgress",
  679.         "onHitGainSkillProgress"
  680.     ]).forEach(function(func) {
  681.         _GA[func] = $[func];
  682.         _UT[func] = $[func] = function(skillId, target, value) {
  683.         // v1.00a - v1.00a; Extended
  684.             var result = _GA[func].apply(this, arguments);
  685.             // Added to check whether the skillId and value arguments are valid
  686.             SPUT.checkFuncs.checkIdSkillArray(
  687.                     [skillId], "_GA." + func + " skillId");
  688.             if (value) SPUT.checkFuncs.checkNum(
  689.                     value, "_GA." + func + " value");
  690.             //
  691.             return result;
  692.         }; // $[func]
  693.     });
  694.  
  695.     ["current", "can", "is"].forEach(function(f) {
  696.         var func = f + "SkillProgress";
  697.         _GA[func] = $[func];
  698.         _UT[func] = $[func] = function(skillId) { // v1.00a - v1.00a; Extended
  699.             var result = _GA[func].apply(this, arguments);
  700.             // Added to check whether the skillId argument is a valid skill id
  701.             SPUT.checkFuncs.checkIdSkillArray(
  702.                     [skillId], "_GA." + func + " skillId");
  703.             //
  704.             return result;
  705.         }; // $[func]
  706.     });
  707.  
  708.     _GA.setCurrentSkillProgress = $.setCurrentSkillProgress;
  709.     _UT.setCurrentSkillProgress = $.setCurrentSkillProgress = function(skillId, value) {
  710.      // v1.00a - v1.00a; Extended
  711.         _GA.setCurrentSkillProgress.apply(this, arguments);
  712.         // Added to check whether the skillId and value arguments are valid
  713.         SPUT.checkFuncs.checkIdSkillArray(
  714.                 [skillId], "_GA.setCurrentSkillProgress skillId");
  715.         SPUT.checkFuncs.checkNonnegativeNum(
  716.                 value, "_GA.setCurrentSkillProgress value");
  717.         //
  718.     }; // $.setCurrentSkillProgress
  719.     //
  720.  
  721.     _GA._progressSkill = _SP._progressSkill;
  722.     _SP._progressSkill = function(skillId) { // v1.00a - v1.00a; Extended
  723.         _GA._progressSkill.apply(this, arguments);
  724.         // Added to unit test class invariants involving this function
  725.         _UT._checkProgressSkill.call(this, skillId);
  726.         //
  727.     }; // _SP._progressSkill
  728.  
  729.     /**
  730.      * The this pointer is Game_Actor.prototype
  731.      * No-op
  732.      * @param {Id} skillId - The id of the skill involved
  733.      * @since v1.00a @version v1.00a
  734.      */
  735.     _UT._checkProgressSkill = function(skillId) {
  736.         // It's reasonable to assume that nextSkillProgress won't be random
  737.         var next = this.nextSkillProgress(skillId).filter(function(id) {
  738.             return !this.isLearnedSkill(id);
  739.         }, this);
  740.         //
  741.         if (next.length > 0) SPUT.showFailMsg(JSON.stringify({
  742.             skillId: skillId,
  743.             nextSkillProgress: nextSkillProgress
  744.         }), "_GA._progressSkill", "They should be learnt!");
  745.         // It's reasonable to assume that isKeepSkillProgress won't be random
  746.         var isKeep = this.isKeepSkillProgress(skillId);
  747.         //
  748.         if (isKeep !== this.isLearnedSkill(skillId)) {
  749.             SPUT.showFailMsg(JSON.stringify({
  750.                 skillId: skillId,
  751.                 isKeepSkillProgress: isKeepSkillProgress
  752.             }), "_GA._progressSkill",
  753.                     isKeep ? "It should be kept" : "It should be forgotten!");
  754.         }
  755.         if (this._skillProgress.isEnded[skillId]) return;
  756.         SPUT.showFailMsg("isEnded", "_GA._progressSkill", "It should be true!");
  757.     }; // _UT._checkProgressSkill
  758.  
  759. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  760.  
  761. /*----------------------------------------------------------------------------
  762.  *    # Edit class: Game_SkillProgressNotes
  763.  *      - Unit tests the chained note results to ensure proper chainings
  764.  *----------------------------------------------------------------------------*/
  765.  
  766.  (function(SP, SPUT) {
  767.  
  768.      "use strict";
  769.  
  770.      var GSPN = SP.Game_SkillProgressNotes.unitTest = { orig: {}, new: {} };
  771.      var $ = Game_SkillProgressNotes.prototype;
  772.      var _GSPN = GSPN.orig, _UT = GSPN.new;
  773.  
  774.     // Only interfaces will have their argument invariants checked
  775.     _GSPN.result = $.result;
  776.     _UT.result = $.result = function(note, skillId, target, value) {
  777.     // v1.00a - v1.00a; Extended
  778.         var result = _GSPN.result.apply(this, arguments);
  779.         // Added to check whether the arguments except target are valid
  780.         SPUT.checkFuncs.checkVal(
  781.                 note, "_GSPN.result note", SP.Game_SkillProgressCache._NOTES);
  782.         SPUT.checkFuncs.checkIdSkillArray([skillId], "_GSPN.result skillId");
  783.         if (value) SPUT.checkFuncs.checkNum(value, "_GSPN.result value");
  784.         //
  785.         return result;
  786.     }; // $.result
  787.  
  788.     _GSPN.run = $.run;
  789.     _UT.run = $.run = function(notes, skillId) {
  790.     // v1.00a - v1.00a; Extended
  791.         _GSPN.run.apply(this, arguments);
  792.         // Added to check whether the notes and skillId arguments are valid
  793.         SPUT.checkFuncs.checkArrayVals(
  794.                 notes, "_GSPN.run notes", SP.Game_SkillProgressCache._NOTES);
  795.         SPUT.checkFuncs.checkIdSkillArray([skillId], "_GSPN.run skillId");
  796.         //
  797.     }; // $.run
  798.     //
  799.  
  800.     _GSPN._uncachedResult = $._uncachedResult;
  801.     _UT._uncachedResult = $._uncachedResult = function(note, skillId, target, value) {
  802.     // v1.00a - v1.00a; Extended
  803.         var result = _GSPN._uncachedResult.apply(this, arguments);
  804.         // Added to unit test the chained result of this note type
  805.         _UT._checkUncachedResult.call(
  806.                 this, note, skillId, target, value, result);
  807.         //
  808.         return result;
  809.     }; // $._uncachedResult
  810.  
  811.     /**
  812.      * @since v1.00a @version v1.00a
  813.      * @param {String} note - The note to have its end result retrieved
  814.      * @param {Id} skillId - The id of the skill involved
  815.      * @param {Game_Battler?} target - The target hit by the skill involved
  816.      * @param {Number?} value - The damage of the hit involved
  817.      * @param {*} result - The result from all effective notetags involved
  818.      */
  819.     _UT._checkUncachedResult = function(note, skillId, target, value, result) {
  820.         var func = SPUT.checkFuncs[SPUT.unitTest.chainedNoteTypes[note]];
  821.         if (func) func(result, JSON.stringify({
  822.             note: note,
  823.             skillId: skillId,
  824.             target: target ? target.name() : "No target",
  825.             hitDamage: value || "No hit"
  826.         }));
  827.     }; // _UT._checkUncachedResult
  828.  
  829. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  830.  
  831. /*----------------------------------------------------------------------------
  832.  *    # Edit class: Game_SkillProgressPairs
  833.  *      - Unit tests all data notetags to pinpoint the data with faulty notes
  834.  *----------------------------------------------------------------------------*/
  835.  
  836.  (function(SP, SPUT) {
  837.  
  838.      "use strict";
  839.  
  840.      var GSPP = SP.Game_SkillProgressPairs.unitTest = { orig: {}, new: {} };
  841.      var $ = Game_SkillProgressPairs.prototype;
  842.      var _GSPP = GSPP.orig, _UT = GSPP.new;
  843.  
  844.     _GSPP.run = $.run;
  845.     _UT.run = $.run = function(skillId, note, datum, target, value) {
  846.     // v1.00a - v1.00a; Extended
  847.         var results = _GSPP.run.apply(this, arguments);
  848.         // Added to unit test the notetag result of this datum
  849.         _UT._checkRun.call(this, skillId, note, datum, target, value, results);
  850.         //
  851.         return results;
  852.     }; // $.run
  853.  
  854.     /**
  855.      * @since v1.00a @version v1.00a
  856.      * @param {Id} skillId - The id of the skill involved
  857.      * @param {String} note - The note to have its contents run
  858.      * @param {{*}} datum - The datum having the note to have its contents run
  859.      * @param {Game_Battler?} target - The target hit by the skill involved
  860.      * @param {Number?} value - The damage of the hit involved
  861.      * @param {[*]} results - The result of the notetag function involved
  862.      */
  863.     _UT._checkRun = function(skillId, note, datum, target, value, results) {
  864.         var func = SPUT.checkFuncs[SPUT.unitTest.noteTypes[note]];
  865.         if (func) func(results, JSON.stringify({
  866.             skillId: skillId,
  867.             note: note,
  868.             dataId: datum ? datum.id : "No datum",
  869.             dataName: datum ? datum.name : "No datum",
  870.             target: target ? target.name() : "No target",
  871.             hitDamage: value || "No hit"
  872.         }));
  873.     }; // _UT._checkRun
  874.  
  875. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  876.  
  877. /*----------------------------------------------------------------------------
  878.  *    # Edit class: Window_SkillProgressStat/Cond/Next
  879.  *      - Unit tests all the interface argument invariants
  880.  *----------------------------------------------------------------------------*/
  881.  
  882. (function(SP, SPUT) {
  883.  
  884.     "use strict";
  885.  
  886.     var classes = {
  887.         Window_SkillProgressStat: Window_SkillProgressStat.prototype,
  888.         Window_SkillProgressCond: Window_SkillProgressCond.prototype,
  889.         Window_SkillProgressNext: Window_SkillProgressNext.prototype
  890.     };
  891.     Object.keys(classes).forEach(function(klass) {
  892.  
  893.         SP[klass] = { unitTest: { orig: {}, new: {} } };
  894.         var WSP = SP[klass].unitTest, $ = classes[klass];
  895.         var _WSP = WSP.orig, _UT = WSP.new;
  896.  
  897.         _WSP.setup = $.setup;
  898.         _UT.setup = $.setup = function(skillId) { // v1.00a - v1.00a; Extended
  899.             _WSP.setup.apply(this, arguments);
  900.             // Added to check whether the skillId argument is a valid skill id
  901.             SPUT.checkFuncs.checkIdSkillArray([skillId], klass + ".setup");
  902.             //
  903.         }; // $.setup
  904.  
  905.     });
  906.  
  907. })(DoubleX_RMMV.Skill_Progress, DoubleX_RMMV.Skill_Progress_Unit_Test);
  908.  
  909. /*----------------------------------------------------------------------------*/
  910.  
  911. } else {
  912.     alert("To use Skill Progress Unit Test, place it below Skill Progress.");
  913. } // if (DoubleX_RMMV["Skill Progress"])
  914.  
  915. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement