Advertisement
Eeems

Untitled

Jul 12th, 2011
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Plugins data format
  3.     {
  4.         info: {
  5.             name = "OnJoin Example",
  6.             version = "0.01",
  7.             minVersion = "2.2"
  8.         },
  9.         <event>: function(<arguments>){
  10.             <event handling code>
  11.         },
  12.         options: {
  13.             <name>:{
  14.                 type: <'bool'|'int'|'array'|'string'>,
  15.                 default: <default value>
  16.             }
  17.         },
  18.     }
  19.     Option data format
  20.     {
  21.         name: <name of option>,
  22.         type: <'bool'|'int'|'array'|'string'>,
  23.         value: <current value>,
  24.         plugin: <reference to plugin>
  25.     }
  26. */
  27.  
  28. // Scope ans stuff, since I'm cool
  29. (function( window, undefined ) {
  30.     // Define the default state of the two vars
  31.     var Plugins;
  32.     var Options = [
  33.         // default values here
  34.     ];
  35.     // This function initializes the plugins and sets up Options based on the plugins that are loaded
  36.     Plugins.init = function(){
  37.         for(var i in this.list){
  38.             if(this[i].options!=undefined){
  39.                 var options = this[i].options;
  40.                 for(var ii in options){
  41.                     var o = {
  42.                         type: options[ii].type,
  43.                         plugin: this[i],
  44.                         name: ii,
  45.                         value: this.isset(ii,options[ii])
  46.                     };
  47.                     Options.push(o);
  48.                 }
  49.             }
  50.         }
  51.     };
  52.     // This funciton runs the plugins based off of an event
  53.     Plugins.parse = function(event,data){
  54.         // event is a string containing the signal name (ie: 'join')
  55.         // data is an array of all the arguements to pass to the function
  56.         var output = true;
  57.         for(var i in this.list){
  58.             if(this[i][event]!=undefined){
  59.                 // call the function with the right scope, and pass on the right arguements
  60.                 var r = this[i][event].apply(this[i],data);
  61.                 // I like switch statements more then if/else
  62.                 switch(r){
  63.                     case PLUGIN_BREAK:
  64.                         return output;
  65.                     break;
  66.                     case PLUGIN_NO_OUTPUT:
  67.                         output = false;
  68.                 }
  69.             }
  70.         }
  71.         return output;
  72.     };
  73.     // This makes adding a plugin easier
  74.     Plugins.add = funciton(plugin){
  75.         return plugins.list.push(plugin);
  76.     };
  77.     // define the isset which returns either the default or the actual setting based on if there is an actual set setting
  78.     Plugins.isset = function(ref,option){
  79.         // ref is the reference to the plugin variable
  80.         // option is the option you want to check ( string )
  81.         if(/* setting exists */){
  82.             return /* setting */;
  83.         }
  84.         return ref[option].default;
  85.     }
  86.     // This renders the options panel.
  87.     Plugins.options = function(){
  88.         // render the options panel based on options
  89.     };
  90.     // The array containing all the plugin data
  91.     Plugins.list = [];
  92.     // define Plugins and Options for normal use
  93.     window.Plugins = Plugins;
  94.     window.Options = Options;
  95.     // We are done here
  96. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement