| 1 |
<?php
|
| 2 |
// $Id: fsgame.admin.inc,v 1.10 2008/06/11 17:09:01 aaron Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Admin functions for the 5 Second Game engine.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Configure 5 Second Game; menu callback for admin/settings/fsgame.
|
| 11 |
*/
|
| 12 |
function fsgame_settings() {
|
| 13 |
$form = array();
|
| 14 |
|
| 15 |
if (!count(fsgame_world_load('classes', NULL, TRUE))) {
|
| 16 |
drupal_set_message(t("No character classes found. !enable_a_module that defines a 5 Second Game world.",
|
| 17 |
array('!enable_a_module' => l(t('Enable a module'), 'admin/build/modules'))), 'error');
|
| 18 |
}
|
| 19 |
|
| 20 |
$form['attributes'] = array(
|
| 21 |
'#collapsible' => TRUE,
|
| 22 |
'#description' => t('All characters have three base attributes, and the engine resolves conflicts using a simple rock-paper-scissors comparison, where rock beats scissors beats paper. You may change the names and definitions of these attributes here. When using modules that add classes, skills, and modifiers such as equipment, the attributes used in those modules will be translated to the terms you\'ve defined here.'),
|
| 23 |
'#title' => t('Attributes'),
|
| 24 |
'#type' => 'fieldset',
|
| 25 |
);
|
| 26 |
foreach (fsgame_base_attributes() as $attribute) {
|
| 27 |
$form['attributes'][$attribute['id']] = array(
|
| 28 |
'#collapsible' => TRUE,
|
| 29 |
'#collapsed' => TRUE,
|
| 30 |
'#title' => t(drupal_ucfirst($attribute['id'])),
|
| 31 |
'#type' => 'fieldset',
|
| 32 |
);
|
| 33 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_title'] = array(
|
| 34 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_title', t(drupal_ucfirst($attribute['title']))),
|
| 35 |
'#description' => t("The name shown to users of the internal '@attribute' attribute.", array('@attribute' => $attribute['id'])),
|
| 36 |
'#title' => t('Title'),
|
| 37 |
'#type' => 'textfield',
|
| 38 |
);
|
| 39 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_description'] = array(
|
| 40 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_description', ''),
|
| 41 |
'#description' => t("The description shown to users of the internal '@attribute' attribute.", array('@attribute' => $attribute['id'])),
|
| 42 |
'#title' => t('Description'),
|
| 43 |
'#type' => 'textfield',
|
| 44 |
);
|
| 45 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_default'] = array(
|
| 46 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_default', 1),
|
| 47 |
'#description' => t("The default value of the '@attribute' attribute for starting characters.", array('@attribute' => $attribute['id'])),
|
| 48 |
'#title' => t('Default value'),
|
| 49 |
'#type' => 'textfield',
|
| 50 |
);
|
| 51 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_minimum'] = array(
|
| 52 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_minimum', 0),
|
| 53 |
'#description' => t("The minimum value of the '@attribute' attribute.", array('@attribute' => $attribute['id'])),
|
| 54 |
'#title' => t('Minimum value'),
|
| 55 |
'#type' => 'textfield',
|
| 56 |
);
|
| 57 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_maximum'] = array(
|
| 58 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_maximum', 0),
|
| 59 |
'#description' => t("The maximum value of the '@attribute' attribute. If set to 0 (the default), there is no upper limit.", array('@attribute' => $attribute['id'])),
|
| 60 |
'#title' => t('Maximum value'),
|
| 61 |
'#type' => 'textfield',
|
| 62 |
);
|
| 63 |
$form['attributes'][$attribute['id']]['fsgame_attributes_'. $attribute['id'] .'_trumps'] = array(
|
| 64 |
'#default_value' => variable_get('fsgame_attributes_'. $attribute['id'] .'_trumps', $attribute['trumps']),
|
| 65 |
'#description' => t("When resolving ties, the '@attribute' attribute is weighted higher than the attribute selected here.", array('@attribute' => $attribute['id'])),
|
| 66 |
'#options' => fsgame_base_attributes_fapi(),
|
| 67 |
'#title' => t('Trumps'),
|
| 68 |
'#type' => 'select',
|
| 69 |
);
|
| 70 |
}
|
| 71 |
|
| 72 |
$form['#validate'][] = 'fsgame_settings_validate';
|
| 73 |
return system_settings_form($form);
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* FormAPI #validate callback for fsgame_settings().
|
| 78 |
*/
|
| 79 |
function fsgame_settings_validate($form, &$form_state) {
|
| 80 |
foreach (fsgame_base_attributes() as $attribute) {
|
| 81 |
if ($form_state['values']['fsgame_attributes_' . $attribute['id'] . '_trumps'] == $attribute['id']) {
|
| 82 |
form_set_error('fsgame_attributes_' . $attribute['id'] . '_trumps', t("The '@attribute' attribute can not trump itself.", array('@attribute' => $attribute['id'])));
|
| 83 |
}
|
| 84 |
}
|
| 85 |
}
|