/[drupal]/contributions/modules/rpg/rpg.module
ViewVC logotype

Diff of /contributions/modules/rpg/rpg.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.58, Sat Mar 8 00:31:03 2008 UTC revision 1.59, Sat Apr 26 01:03:25 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: rpg.module,v 1.56 2008/02/10 03:32:07 aaron Exp $  // $Id: rpg.module,v 1.58 2008/03/08 00:31:03 aaron Exp $
3    
4  /**  /**
5   *  @mainpage RPG   *  @mainpage RPG
# Line 62  function rpg_menu($may_cache) { Line 62  function rpg_menu($may_cache) {
62   *    but may not necessarily edit overall game settings (which is in the domain of 'administer rpg')   *    but may not necessarily edit overall game settings (which is in the domain of 'administer rpg')
63   */   */
64  function rpg_perm() {  function rpg_perm() {
65    return array('play rpg', 'view rpg objects', 'create pc rpg object', 'administer rpg', 'create rpg object', 'edit own pc rpg object', 'edit own rpg object', 'edit rpg object', 'super in-game rpg');    return array('play rpg', 'view rpg objects', 'create pc rpg object', 'administer rpg', 'create rpg object', 'edit own pc rpg object', 'edit own rpg object', 'edit rpg object', 'super rpg');
66  }  }
67    
68  /**  /**
# Line 793  function rpg_create_page() { Line 793  function rpg_create_page() {
793      return rpg_create_pc_page();      return rpg_create_pc_page();
794    }    }
795    if (!$type) {    if (!$type) {
796        global $user;
797      $types = rpg_types();      $types = rpg_types();
798      $pc_types = rpg_available_pc_types();      $pc_types = rpg_available_pc_types($user);
799      $admin_access = user_access('rpg admin');      $admin_access = user_access('rpg admin');
800      if (empty($types) && $admin_access) {      if (empty($types) && $admin_access) {
801        $output .= t('There are currently no RPG object types defined. You may define these at the !admin.', array('!admin' => l(t('types admin page'), 'admin/rpg/types')));        $output .= t('There are currently no RPG object types defined. You may define these at the !admin.', array('!admin' => l(t('types admin page'), 'admin/rpg/types')));
# Line 897  function rpg_create_object_page($type, $ Line 898  function rpg_create_object_page($type, $
898    return theme('rpg_create_object_page', $object, $type, $form);    return theme('rpg_create_object_page', $object, $type, $form);
899  }  }
900    
901  function rpg_available_pc_types() {  function rpg_available_pc_types($user) {
902    static $avail;    static $avail;
903    
904    if (!isset($avail)) {    if (!isset($avail)) {
905      $avail = array();      $avail = array();
906      $pc_types = module_invoke_all('rpg_pc_types');      $pc_types = module_invoke_all('rpg_pc_types', $user);
907      $types = rpg_types();      $types = rpg_types();
908      foreach ($pc_types as $type) {      foreach ($pc_types as $type) {
909        if (isset($types[$type])) {        if (isset($types[$type])) {
# Line 914  function rpg_available_pc_types() { Line 915  function rpg_available_pc_types() {
915  }  }
916    
917  function rpg_create_pc_page() {  function rpg_create_pc_page() {
918    $pc_types = rpg_available_pc_types();    global $user;
919      $pc_types = rpg_available_pc_types($user);
920    global $user;    global $user;
921    $pc_type = arg(3);    $pc_type = arg(3);
922    if ($pc_type && isset($pc_types[$pc_type])) {    if ($pc_type && isset($pc_types[$pc_type])) {
# Line 961  function rpg_form_object($object) { Line 963  function rpg_form_object($object) {
963      '#value' => $object->uid,      '#value' => $object->uid,
964    );    );
965    $form['types'] = array(    $form['types'] = array(
966      '#type' => 'value',       '#type' => 'value',
967      '#value' => $object->types,       '#value' => $object->types,
968    );    );
969      if (user_access('administer rpg')) {
970        $options = array();
971        foreach (rpg_types() as $type) {
972          $options[$type['type']] = $type['name'];
973        }
974        $form['types'] = array(
975          '#type' => 'select',
976          '#title' => t('Types'),
977          '#options' => $options,
978          '#default_value' => $object->types,
979          '#description' => t('Select the type(s) for this object. Note that conflicts may arise when using multiple types.'),
980          '#multiple' => TRUE,
981        );
982      }
983    $form['created'] = array(    $form['created'] = array(
984      '#type' => 'value',      '#type' => 'value',
985      '#value' => $object->created,      '#value' => $object->created,
# Line 1025  function rpg_form_object_submit($form_id Line 1041  function rpg_form_object_submit($form_id
1041      );      );
1042    
1043      $object = (object) $object;      $object = (object) $object;
1044        rpg_save_rpg($object);//print_r($form_values);//exit();
1045      rpg_save_rpg($object);print_r($form_values);exit();      foreach(rpg_object_attributes($object) as $attribute) {//print_r($attribute);
1046      foreach ((array)$form_values['data'] as $attr => $value) {        if (isset($form_values['data'][$attribute['attribute']])) {drupal_set_message('attr: ' . $attribute['attribute'].', '.$form_values['data'][$attribute['attribute']]);
1047        rpg_set($attr, $object, $value);          rpg_set($attribute['attribute'], $object, $form_values['data'][$attribute['attribute']]);
1048          }
1049          else if ($attribute['default_value']) {drupal_set_message('attr: '.$attribute['attribute'].', default: '.$attribute['default']);
1050            rpg_set($attribute['attribute'], $object, $attribute['default_value']);
1051          }
1052      }      }
1053    //     foreach ((array)$form_values['data'] as $attr => $value) {
1054    //       rpg_set($attr, $object, $value);
1055    //     }
1056    }    }
1057    
1058    _rpg_save_all_marked_objects();    _rpg_save_all_marked_objects();
# Line 1620  function rpg_drupal_alter($type, &$data) Line 1643  function rpg_drupal_alter($type, &$data)
1643   *   *
1644   *  @param $object   *  @param $object
1645   *  the object id to fetch attributes   *  the object id to fetch attributes
1646     *  @param $which
1647     *  if NULL, return all attributes. otherwise, only the attribute asked for
1648   *  @param $cached   *  @param $cached
1649   *  if true, then we fetch the existing attributes from the cache   *  if true, then we fetch the existing attributes from the cache
1650   *  otherwise, we compute them again.   *  otherwise, we compute them again.
# Line 1633  function rpg_object_attributes($object, Line 1658  function rpg_object_attributes($object,
1658      }      }
1659      else {      else {
1660        $attributes[$id] = array();        $attributes[$id] = array();
1661        $object = rpg_object($object);        if (!is_array($object->types)) {
1662            $object = rpg_object($object);
1663          }
1664        if (is_array($object->types)) {        if (is_array($object->types)) {
1665          foreach ($object->types as $type) {          foreach ($object->types as $type) {
1666            $type = rpg_types($type);            $type = rpg_types($type);

Legend:
Removed from v.1.58  
changed lines
  Added in v.1.59

  ViewVC Help
Powered by ViewVC 1.1.2