DoubleX RMMV Object Properties
#1
DoubleX RMMV Object Properties

Version: v1.00d

Introduction

* Traces all object properties meeting some conditions linked to the queried object
* Designed as a bug diagnosis tool used by Javascript coders with debug experience


Prerequisites

* Basic knowledge of inspecting object properties in Javascript
* Some Javascript coding proficiency to fully utilize this plugin


Script

Code:
/*============================================================================

 *    ## Plugin Info                                                          
 *----------------------------------------------------------------------------
 *    # Plugin Name                                                           
 *      DoubleX RMMV Object Properties                                        
 *----------------------------------------------------------------------------
 *    # Terms Of Use                                                          
 *      You shall keep this plugin's Plugin Info part's contents intact       
 *      You shalln't claim that this plugin's written by anyone other than    
 *      DoubleX or his aliases                                                
 *     None of the above applies to DoubleX or his aliases                    
 *----------------------------------------------------------------------------
 *    # Prerequisites                                                         
 *      Abilities:                                                            
 *      1. Basic knowledge of inspecting object properties in Javascript      
 *      2. Some Javascript coding proficiency to fully utilize this plugin    
 *----------------------------------------------------------------------------
 *    # Links                                                                 
 *      This plugin:                                                          
 *      1. http://pastebin.com/nZRhF8vc                                       
*      Mentioned Patreon Supporters:
*      https://www.patreon.com/posts/71738797
 *----------------------------------------------------------------------------
 *    # Author                                                                
 *      DoubleX                                                               
 *----------------------------------------------------------------------------
 *    # Changelog                                                             
 *      v1.00d(GMT 1500 27-1-2016):                                           
 *      1. Fixed enumerating this plugin's functions via for in loops bug     
 *      v1.00c(GMT 0100 13-11-2015):                                          
 *      1. Fixed tracing properties from null or non object object bug        
 *      v1.00b(GMT 1100 11-11-2015):                                          
 *      1. Added descriptions that will be shown in the plugin manager        
 *      v1.00a(GMT 1500 27-10-2015):                                          
 *      1. 1st version of this plugin finished                                
 *============================================================================*/
/*:
 * @plugindesc Traces all object properties meeting some conditions linked to
 *             the queried object
 *             Designed as a bug diagnosis tool used by Javascript coders with
 *             debug experience
 * @author DoubleX
 *
 * @help
 *============================================================================
 *    ## Plugin Call Info                                                     
 *       A path in the object property trace will stop if it'd be cyclic      
 *----------------------------------------------------------------------------
 *    # Object manipulations                                                  
 *      1. trace_obj_prop(cond, label)                                        
 *         - Traces all object properties satisfying function cond linked to  
 *           this object                                                      
 *         - Labels all traced object properties with function label          
 *         - cond and label are functions written in                          
 *           Object Property Tracing Condition Function and                   
 *           Object Property Tracing Label Function respectively              
 *      2. _obj_prop_log[cond]                                                
 *         - Returns the log of all traced object properties satisfying       
 *           function cond linked to this object                              
 *============================================================================
 */

"use strict";
var DoubleX_RMMV = DoubleX_RMMV || {};
DoubleX_RMMV["Obj_Prop"] = "v1.00d";

DoubleX_RMMV.Obj_Prop = {

    /*------------------------------------------------------------------------
     *    Object Property Tracing Condition Function                          
     *    - Setups cond used by trace_obj_prop(cond, label)                   
     *------------------------------------------------------------------------*/
    /* cond must be a function taking the object property as the only argument
       The below examples are added to help you setup your own cond functions */

    // Checks if the currently traced object's indeed an object
    cond_obj: function(obj) {
        return typeof obj === "object";
    }, // substitute cond with "cond_obj" to use this function

    // Checks if the currently traced object's an array
    cond_array: function(obj) {
        return Array.isArray(obj);
    }, // substitute cond with "cond_array" to use this function

    // Add your own cond functions here
    

    /*------------------------------------------------------------------------
     *    Object Property Tracing Label Function                              
     *    - Setups label used by trace_obj_prop(cond, label)                  
     *------------------------------------------------------------------------*/
    /* label must be a function taking the object property as the only argument
       All label functions must return a string
       The below examples are added to help you setup your own label functions */

    // Always returns the entire object
    label_obj: function(obj) {
        return obj;
    }, // substitute label with "label_obj" to use this function

    // Always returns the type(including Array) of each traced object property
    label_array: function(obj) {
        return Array.isArray(obj) ? "array" : typeof obj;
    } // substitute label with "label_array" to use this function

    // Add your own label functions here
    

}; // DoubleX_RMMV.Obj_Prop

/*============================================================================
 *    ## Plugin Implementations                                               
 *       You need not edit this part as it's about how this plugin works      
 *----------------------------------------------------------------------------
 *    # Plugin Support Info:                                                  
 *      1. Prerequisites                                                      
 *         - Solid understanding of inspecting object properties in Javascript
 *         - Decent Javascript coding proficiency to fully comprehend this    
 *           plugin                                                           
 *      2. Function documentation                                             
 *         - The 1st part describes why this function's rewritten/extended for
 *           rewritten/extended functions or what the function does for new   
 *           functions                                                        
 *         - The 2nd part describes what the arguments of the function are    
 *         - The 3rd part informs which version rewritten, extended or created
 *           this function                                                    
 *         - The 4th part informs whether the function's rewritten or new     
 *         - The 5th part informs whether the function's a real or potential  
 *           hotspot                                                          
 *         - The 6th part describes how this function works for new functions
 *           only, and describes the parts added, removed or rewritten for    
 *           rewritten or extended functions only                             
 *         Example:                                                           
 * /*----------------------------------------------------------------------
 *  * Why rewrite/extended/What this function does                         
 *  *----------------------------------------------------------------------*/
/* // arguments: What these arguments are                                     
 * function function_name(arguments) // Version X+; Rewrite/New; Hotspot      
 *     // Added/Removed/Rewritten to do something/How this function works     
 *     function_name_code                                                     
 *     //                                                                     
 * end // function_name                                                       
 *----------------------------------------------------------------------------*/

Object.defineProperties(Object.prototype, {

    "trace_obj_prop": {
        /* cond: The function checking whether an object property will be traced
         * label: The function returning the label of an traced object property
         */
        value: function(cond, label) { // New
            if (!this._obj_prop_trace) {
                this._obj_prop_log = {};
                this._obj_prop_trace = {};
            }
            // Stop tracing the object property if the path would be cyclic
            if (this._obj_prop_trace[cond]) { return; }
            //
            this._obj_prop_log[cond] = "";
            this._obj_prop_trace[cond] = {};
            this.log_obj_prop(cond, label);
        }, // Object.prototype.trace_obj_prop
        writable: true,
        configurable: true
    },

    "log_obj_prop": {
        /* cond: The function checking whether an object property will be traced
         * label: The function returning the label of an traced object property
         */
        value: function(cond, label) { // New
            // Checks if currently traced object property has object properties
            var has_obj_prop = false;
            for (var prop in this) {
                if (this.hasOwnProperty(prop) && this.is_obj_prop(prop)) {
                    has_obj_prop = true;
                    break;
                }
            }
            //
            if (!has_obj_prop) { return; }
            this._obj_prop_log[cond] = "{";
            this.traverse_obj_prop_tree(cond, label);
            this._obj_prop_log[cond] += "}";
        }, // Object.prototype.log_obj_prop
        writable: true,
        configurable: true
    },

    /*------------------------------------------------------------------------
     *    Label and use all nonempty subtrees to form the object property tree
     *------------------------------------------------------------------------*/
    "traverse_obj_prop_tree": {
        /* cond: The function checking whether an object property will be traced
         * label: The function returning the label of an traced object property
         */
        value: function(cond, label) { // New
            var op = DoubleX_RMMV.Obj_Prop;
            for (var prop in this) {
                if (this.hasOwnProperty(prop) && this.is_obj_prop(prop)) {
                    var obj = this[prop];
                    // Recursively traverse property tree via Depth First Search
                    if (op[cond](obj)) {
                        this._obj_prop_log[cond] += " " + prop + ": " +
                        op[label](obj) + " ";
                        this._obj_prop_trace[cond][obj] = [prop];
                    }
                    var temp_prop = prop;
                    if (obj === null || typeof obj !== "object") { continue; }
                    obj.trace_obj_prop(cond, label);
                    if (Object.keys(obj._obj_prop_trace[cond]).length > 0) {
                        if (this._obj_prop_trace[cond][obj] === undefined) {
                            this._obj_prop_trace[cond][obj] = [];
                        }
                        this._obj_prop_log[cond] += " " + temp_prop + ": " +
                        obj._obj_prop_log[cond];
                        this._obj_prop_trace[cond][obj].push(
                        obj._obj_prop_trace[cond]);
                    }
                    //
                }
            }
        }, // Object.prototype.traverse_obj_prop_tree
        writable: true,
        configurable: true
    },

    "is_obj_prop": {
        // prop: The current object property to be traced
        value: function(prop) { // New
            // Return false for all object properties added by this plugin
            if (prop === "_obj_prop_log" || prop === "_obj_prop_trace") {
                return false;
            } else if (prop === "trace_obj_prop" || prop === "log_obj_prop") {
                return false;
            }
            return prop !== "traverse_obj_prop_tree" && prop !== "is_obj_prop";
            //
        }, // Object.prototype.is_obj_prop
        writable: true,
        configurable: true
    }

});

/*============================================================================*/

FAQ

* None so far

Credits and Thanks

* None

Author's Notes

* None so far

Terms and Conditions

* You shall keep this plugin's Plugin Info part's contents intact
* You shalln't claim that this plugin's written by anyone other than DoubleX or his aliases
* None of the above applies to DoubleX or his aliases

Changelog

v1.00d(GMT 1500 27-1-2016):
1. Fixed enumerating this plugin's functions via for in loops bug
v1.00c(GMT 0100 13-11-2015):
1. Fixed tracing properties from null or non object object bug
v1.00b(GMT 1100 11-11-2015):
1. Added descriptions that will be shown in the plugin manager
v1.00a(GMT 1500 27-10-2015):
1. 1st version of this script finished
My RMVXA/RMMV/RMMZ scripts/plugins:
http://rpgmaker.net/users/DoubleX/scripts/
Reply }


Messages In This Thread
DoubleX RMMV Object Properties - by DoubleX - 10-30-2015, 11:17 AM
RE: DoubleX RMMV Object Properties - by DoubleX - 11-11-2015, 12:22 PM
RE: DoubleX RMMV Object Properties - by DoubleX - 11-16-2015, 11:36 AM
RE: DoubleX RMMV Object Properties - by DoubleX - 01-29-2016, 01:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   DoubleX RMMV Popularized ATB Compatibility DoubleX 16 23,316 12-26-2022, 06:17 AM
Last Post: DoubleX
   DoubleX RMMV Confusion Edit DoubleX 3 7,658 09-09-2022, 11:12 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Clock DoubleX 2 6,498 03-25-2022, 01:04 PM
Last Post: DoubleX
   DoubleX RMMV Status Bars Compatibility DoubleX 0 1,926 02-06-2022, 07:56 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Bar DoubleX 3 8,583 05-19-2021, 06:10 AM
Last Post: DoubleX
   DoubleX RMMV Skill Hotkeys DoubleX 2 6,032 02-13-2021, 04:59 AM
Last Post: DoubleX
   DoubleX RMMZ Skill Item Cooldown DoubleX 4 6,166 02-07-2021, 04:11 PM
Last Post: DoubleX
   DoubleX RMMZ Skill Item Triggers DoubleX 3 5,603 12-26-2020, 04:00 PM
Last Post: DoubleX
   DoubleX RMMZ TPBS Configurations Edit DoubleX 3 5,697 12-25-2020, 12:30 PM
Last Post: DoubleX
   DoubleX RMMV Superlative ATB DoubleX 2 4,483 12-11-2020, 02:25 PM
Last Post: DoubleX



Users browsing this thread: 1 Guest(s)