Import Rulesets

Events happening in the community are now at Drupal community events on www.drupal.org.
aaron's picture

After a conversation with dmitrig01, I think I found the way to best integrate the flexibility I can see with the current system with the robustness & speed of using php include files that was part of RPG originally. Because I'm not near my computer this weekend, I'm going to just add some notes here directly to remind myself this direction when I get back to programming next week:

Import Rulesets

Module-defined rulesets may include their own types, attributes, classes, and actions. Each may be activated or deactivated by check boxes in the appropriate fieldset.

Rulesets

Drudge
Submitting this page will import the checked elements below from the Drudge Ruleset. Any element may be overridden as usual in the admin screens. If there are conflicts between imported elements and existing elements in the database, they will be resolved as follows (from the following radio buttons):
0 Override the database with the new element.
0 Ignore the new element, preserving the database.

(From the next screen, if there are conflicts, they will be listed, giving the admin a chance to confirm or cancel the import if they realize they made a mistake.)

<?php
function rpg_drudge_info() {
 
$info = array();
 
$info['types'] = array();
 
$info['types']['tangible'] = array();
 
$info['types']['tangible']['parents'] = array();
 
$info['types']['tangible']['attributes'] = array();
 
$info['types']['tangible']['attributes']['location'] = array(
   
'class' => 'number', // this determines mainly how the attribute tables are created for objects, but may also affect processing
   
'verify' => '_rpg_drudge_location_verify', // this function will be called before setting the attribute, and must return true to continue
   
'set' => '_rpg_drudge_location_set', // this function will be called when setting the attribute on an object
 
);
 
$info['types']['tangible']['attributes']['moveable'] = array(
   
'class' => 'boolean',
   
'default_value' => true, // objects of this type will begin with this value for the attribute
 
);
 
$info['types']['tangible']['attributes']['may_take'] = array(
   
'class' => 'figured', // figured class attributes may not be manually set
   
'get' => '_rpg_drudge_may_take', // this function will be called to return the value of an attribute.
 
);
 
$info['types']['tangible']['actions'] = array();
 
$info['types']['tangible']['actions']['take'] = array(
   
'action' => '_rpg_drudge_take', // this is the function called when using this action
 
);
 
// etc...
 
return $info;
}
?>

RPG Types will continue to be held in a cached array, and built from the database. When types, attributes, etc., are imported, they will be stored into the database, rebuilding the cache. From this point, they may be modified, renamed, deleted, as any other type or attribute. Now the 'get', 'set', and 'verify' strings are for functions that will be called (assuming they exist) when invoking that attribute. In addition, there are 'get_php', 'set_php', and 'verify_php' blocks also available from the admin screens (when the admin has the appropriate permissions). These are eval'd only if the get/set/verify string is also blank.

The core functions called in most cases when manipulating or accessing attributes are rpg_get, rpg_verify, rpg_set, rpg_action_allowed, and rpg_action. rpg_object is also allowed, which will return the rpg object directly, but is generally not used except in low-level cases, as it can cause problems if used incorrectly -- for instance, figured attributes may not be figured correctly, proper verify hooks may not be called, and changes to attributes may not be saved to the database. Using the higher-level functions ensure processing is done in the correct order and that changes are saved properly.

<?php
function rpg_get() {
 
$args = func_get_args();
 
$object = rpg_object(array_shift($args));
 
array_unshift($args, $object);
 
$attribute = $object['attributes'][array_shift($args))];
  if (
function_exists($attribute['get'])) {
    return
call_user_func_array($attribute['get'], $args);
  }
  if (
$attributes['get_php']) {
   
// is there a way to add our $args to this as variables available to eval? also, devel allows malformed php evals to not crash the browser. how??
   
return drupal_eval($attributes['get_php']);
  }
 
$value = $object['attributes'][$attribute['type']];
  if (!
is_null($value)) {
    return
$value;
  }
  return
$attribute['default_value'];
}
?>

More later!

Aaron Winborn
Drupal RPG, home of the Drupal RPG module.
Spindowners, and upcoming web-based sci-fi RPG being built with the module.

Games

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: