Parent Directory
|
Revision Log
|
Revision Graph
fix character creation process, so it correctly selects the character change object insertion so it uses rpg_set instead of _rpg_set_raw
| 1 | <?php |
| 2 | // $Id: rpg.admin.inc,v 1.16 2008/01/10 02:44:17 aaron Exp $ |
| 3 | |
| 4 | /** |
| 5 | * @file |
| 6 | * This includes internal form calls for various admin screens. They are used rarely, and only called from within |
| 7 | * admin setup screens, so are only loaded when needed. |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * this returns a cached menu, called from rpg_menu() |
| 12 | */ |
| 13 | function _rpg_menu_cache() { |
| 14 | $items = array(); |
| 15 | $admin_access = user_access('administer rpg'); |
| 16 | |
| 17 | // the main game playing page |
| 18 | $items[] = array( |
| 19 | 'path' => 'rpg', |
| 20 | 'title' => t('RPG'), |
| 21 | 'callback' => 'rpg_page', |
| 22 | 'access' => ($admin_access || user_access('play rpg')), |
| 23 | ); |
| 24 | $items[] = array( |
| 25 | 'path' => 'rpg/play', |
| 26 | 'title' => t('Play game'), |
| 27 | 'callback' => 'rpg_play', |
| 28 | 'access' => ($admin_access || user_access('play rpg')), |
| 29 | ); |
| 30 | $items[] = array( |
| 31 | 'path' => 'rpg/select', |
| 32 | 'title' => t('Select character'), |
| 33 | 'callback' => 'rpg_character_select_page', |
| 34 | 'access' => ($admin_access || user_access('play rpg')), |
| 35 | ); |
| 36 | // the page to create rpg objects |
| 37 | $items[] = array( |
| 38 | 'path' => 'rpg/create', |
| 39 | 'title' => t('Create RPG Object'), |
| 40 | 'callback' => 'rpg_create_page', |
| 41 | 'access' => ($admin_access || user_access('create rpg object') || user_access('create pc rpg object')), |
| 42 | ); |
| 43 | $items[] = array( |
| 44 | 'path' => 'rpg/edit', |
| 45 | 'title' => t('Edit RPG Object'), |
| 46 | 'callback' => 'rpg_edit_page', |
| 47 | 'access' => ($admin_access || user_access('edit rpg object') || user_access('edit own rpg object') || user_access('edit own pc rpg object')), |
| 48 | // access controlled at rpg_edit_page |
| 49 | ); |
| 50 | $items[] = array( |
| 51 | 'path' => 'rpg/view', |
| 52 | 'title' => t('View RPG Object'), |
| 53 | 'callback' => 'rpg_view_page', |
| 54 | 'access' => ($admin_access || user_access('play rpg')), |
| 55 | ); |
| 56 | $items[] = array( |
| 57 | 'path' => 'admin/rpg', |
| 58 | 'title' => t('RPG configuration'), |
| 59 | 'description' => t('Adjust RPG configuration options.'), |
| 60 | 'position' => 'right', |
| 61 | 'weight' => -5, |
| 62 | 'callback' => 'system_admin_menu_block_page', |
| 63 | 'access' => $admin_access, |
| 64 | ); |
| 65 | $items[] = array( |
| 66 | 'path' => 'admin/rpg/game', |
| 67 | 'title' => t('RPG Game'), |
| 68 | 'description' => t('Configure RPG game settings.'), |
| 69 | 'callback' => 'drupal_get_form', |
| 70 | 'callback arguments' => 'rpg_admin_game', |
| 71 | 'access' => $admin_access, |
| 72 | ); |
| 73 | $items[] = array( |
| 74 | 'path' => 'admin/rpg/game/settings', |
| 75 | 'title' => t('Settings'), |
| 76 | 'description' => t('Configure RPG game settings.'), |
| 77 | 'weight' => -3, |
| 78 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 79 | ); |
| 80 | $items[] = array( |
| 81 | 'path' => 'admin/rpg/types', |
| 82 | 'title' => t('RPG Types'), |
| 83 | 'description' => t('Define and override RPG object types.'), |
| 84 | 'callback' => 'rpg_admin_types', |
| 85 | 'access' => $admin_access, |
| 86 | ); |
| 87 | $items[] = array( |
| 88 | 'path' => 'admin/rpg/types/add', |
| 89 | 'title' => t('Add RPG Type'), |
| 90 | 'description' => t('Create a new RPG type.'), |
| 91 | 'callback' => 'drupal_get_form', |
| 92 | 'callback arguments' => 'rpg_admin_type_add', |
| 93 | 'access' => $admin_access, |
| 94 | 'type' => MENU_CALLBACK, |
| 95 | ); |
| 96 | foreach(rpg_types() as $type) { |
| 97 | $items[] = array( |
| 98 | 'path' => 'admin/rpg/types/type/' . $type['type'], |
| 99 | 'title' => $type['name'], |
| 100 | 'description' => t('Configure the @type RPG type.', array('@type' => $type['name'])), |
| 101 | 'callback' => 'drupal_get_form', |
| 102 | 'callback arguments' => array('rpg_admin_type_edit', $type['type']), |
| 103 | 'access' => $admin_access, |
| 104 | 'type' => MENU_CALLBACK, |
| 105 | ); |
| 106 | $items[] = array( |
| 107 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/edit', |
| 108 | 'title' => t('Edit @type', array('@type' => $type['name'])), |
| 109 | 'description' => t('Configure the @type RPG type.', array('@type' => $type['name'])), |
| 110 | 'callback' => 'drupal_get_form', |
| 111 | 'callback arguments' => array('rpg_admin_type_edit', $type['type']), |
| 112 | 'access' => $admin_access, |
| 113 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 114 | 'weight' => -5, |
| 115 | ); |
| 116 | $items[] = array( |
| 117 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/attributes', |
| 118 | 'title' => t('Attributes'), |
| 119 | 'description' => t('Configure the attributes for the @type RPG type.', array('@type' => $type['name'])), |
| 120 | 'callback' => 'drupal_get_form', |
| 121 | 'callback arguments' => array('rpg_admin_type_attributes_form', $type['type']), |
| 122 | 'access' => $admin_access, |
| 123 | 'type' => MENU_LOCAL_TASK, |
| 124 | ); |
| 125 | $items[] = array( |
| 126 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/actions', |
| 127 | 'title' => t('Actions'), |
| 128 | 'description' => t('Configure the actions for the @type RPG type.', array('@type' => $type['name'])), |
| 129 | 'callback' => 'drupal_get_form', |
| 130 | 'callback arguments' => array('rpg_admin_type_actions', $type['type']), |
| 131 | 'access' => $admin_access, |
| 132 | 'type' => MENU_LOCAL_TASK, |
| 133 | ); |
| 134 | $items[] = array( |
| 135 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/events', |
| 136 | 'title' => t('Events'), |
| 137 | 'description' => t('Configure the events for the @type RPG type.', array('@type' => $type['name'])), |
| 138 | 'callback' => 'drupal_get_form', |
| 139 | 'callback arguments' => array('rpg_admin_type_events', $type['type']), |
| 140 | 'access' => $admin_access, |
| 141 | 'type' => MENU_LOCAL_TASK, |
| 142 | ); |
| 143 | $items[] = array( |
| 144 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/attributes/add', |
| 145 | 'title' => t('Add attribute'), |
| 146 | 'description' => t('Add an attribute for the @type RPG type.', array('@type' => $type['name'])), |
| 147 | 'callback' => 'drupal_get_form', |
| 148 | 'callback arguments' => array('rpg_admin_type_attribute_add', $type['type']), |
| 149 | 'access' => $admin_access, |
| 150 | 'type' => MENU_CALLBACK, |
| 151 | ); |
| 152 | $items[] = array( |
| 153 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit', |
| 154 | 'title' => t('Edit attribute'), |
| 155 | 'description' => t('Edit an attribute for the @type RPG type.', array('@type' => $type['name'])), |
| 156 | 'callback' => 'drupal_get_form', |
| 157 | 'callback arguments' => array('rpg_admin_type_attribute_edit', $type['type']), |
| 158 | 'access' => $admin_access, |
| 159 | 'type' => MENU_CALLBACK, |
| 160 | ); |
| 161 | $items[] = array( |
| 162 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/actions/add', |
| 163 | 'title' => t('Add action'), |
| 164 | 'description' => t('Add an action for the @type RPG type.', array('@type' => $type['name'])), |
| 165 | 'callback' => 'drupal_get_form', |
| 166 | 'callback arguments' => array('rpg_admin_type_action_add', $type['type']), |
| 167 | 'access' => $admin_access, |
| 168 | 'type' => MENU_CALLBACK, |
| 169 | ); |
| 170 | $items[] = array( |
| 171 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/actions/edit', |
| 172 | 'title' => t('Edit action'), |
| 173 | 'description' => t('Edit an action for the @type RPG type.', array('@type' => $type['name'])), |
| 174 | 'callback' => 'drupal_get_form', |
| 175 | 'callback arguments' => array('rpg_admin_type_action_edit', $type['type']), |
| 176 | 'access' => $admin_access, |
| 177 | 'type' => MENU_CALLBACK, |
| 178 | ); |
| 179 | $items[] = array( |
| 180 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/events/add', |
| 181 | 'title' => t('Add event'), |
| 182 | 'description' => t('Add an event for the @type RPG type.', array('@type' => $type['name'])), |
| 183 | 'callback' => 'drupal_get_form', |
| 184 | 'callback arguments' => array('rpg_admin_type_event_add', $type['type']), |
| 185 | 'access' => $admin_access, |
| 186 | 'type' => MENU_CALLBACK, |
| 187 | ); |
| 188 | $items[] = array( |
| 189 | 'path' => 'admin/rpg/types/type/' . $type['type'] . '/events/edit', |
| 190 | 'title' => t('Edit event'), |
| 191 | 'description' => t('Edit an event for the @type RPG type.', array('@type' => $type['name'])), |
| 192 | 'callback' => 'drupal_get_form', |
| 193 | 'callback arguments' => array('rpg_admin_type_event_edit', $type['type']), |
| 194 | 'access' => $admin_access, |
| 195 | 'type' => MENU_CALLBACK, |
| 196 | ); |
| 197 | } |
| 198 | return $items; |
| 199 | } |
| 200 | |
| 201 | function _rpg_admin_game() { |
| 202 | $form = array(); |
| 203 | $form['user'] = array( |
| 204 | '#type' => 'fieldset', |
| 205 | '#title' => t('RPG User Settings'), |
| 206 | '#collapsible' => true, |
| 207 | '#collapsed' => true, |
| 208 | '#description' => t('These settings affect how users are able to interact with the game. You will also need to modify the !access_rules for the site.', array('!access_rules' => l(t('RPG Module Access Rules'), 'admin/user/access'))), |
| 209 | ); |
| 210 | $form['user']['rpg_user_max_pc'] = array( |
| 211 | '#type' => 'textfield', |
| 212 | '#title' => t('Maximum Number of Player Characters (PC\'s) Allowed per User'), |
| 213 | '#default_value' => variable_get('rpg_user_max_pc', 0), |
| 214 | '#size' => 7, |
| 215 | '#description' => t('If this number is greater than 0, then users who have permission may only create up to that number of characters to play. This may be overridden per role below. Note that such users will also need to have enabled the \'play rpg\' access setting, and probably the appropriate create permissions for at least one rpg actor type of node (unless such characters are otherwise provided for them).'), |
| 216 | ); |
| 217 | $form['user']['user_max_pc_roles'] = array( |
| 218 | '#type' => 'fieldset', |
| 219 | '#title' => t('Maximum Number of PC\'s Allowed per User by Role'), |
| 220 | '#collapsible' => true, |
| 221 | '#collapsed' => true, |
| 222 | '#description' => t('If the number next to a role is greater than 0, then users with that role may only create up to that number of characters to play, overriding the above setting. A user with multiple roles will be assigned the largest number that overrides the global setting. Note that user roles with the access permission of \'Administer RPG Characters\' will always be able to create new characters, regardless of these settings.'), |
| 223 | ); |
| 224 | foreach (user_roles() as $rid => $role) { |
| 225 | $form['user']['user_max_pc_roles']['rpg_user_max_pc_role_' . $rid] = array( |
| 226 | '#type' => 'textfield', |
| 227 | '#title' => t('Maximum Number of PC\'s Allowed for @role Users', array('@role' => $role)), |
| 228 | '#default_value' => variable_get('rpg_user_max_pc_role_' . $rid, 0), |
| 229 | '#size' => 7, |
| 230 | ); |
| 231 | } |
| 232 | |
| 233 | $duration = variable_get('rpg_action_round_duration', RPG_ACTION_ROUND_DURATION); |
| 234 | $increment = variable_get('rpg_action_round_calendar_increment', RPG_ACTION_ROUND_CALENDAR_INCREMENT); |
| 235 | $max_points = variable_get('rpg_max_action_points', RPG_MAX_ACTION_POINTS); |
| 236 | $recharge = variable_get('rpg_action_recharge_rate', RPG_ACTION_RECHARGE_RATE); |
| 237 | $figured = (int)((24*60*60) / $duration / $recharge); |
| 238 | $suggested = (int)((24*60*60) / $duration / $max_points); |
| 239 | |
| 240 | $form['action'] = array( |
| 241 | '#type' => 'fieldset', |
| 242 | '#title' => t('RPG Action Round Settings'), |
| 243 | '#collapsible' => true, |
| 244 | '#collapsed' => true, |
| 245 | '#description' => t('These settings affect Action Rounds in the game. Players may generally only make one action per round of play.'), |
| 246 | ); |
| 247 | $form['action']['rpg_action_round_duration'] = array( |
| 248 | '#type' => 'textfield', |
| 249 | '#title' => t('Duration of Action Rounds'), |
| 250 | '#default_value' => $duration, |
| 251 | '#size' => 7, |
| 252 | '#description' => t('Specify how many real-time seconds that an Action Round will last. A player must make an action within this window for it to be considered. You must enter a minimum of one second.'), |
| 253 | ); |
| 254 | $form['action']['rpg_max_action_points'] = array( |
| 255 | '#type' => 'textfield', |
| 256 | '#title' => t('Maximum Character Action Points'), |
| 257 | '#default_value' => $max_points, |
| 258 | '#size' => 7, |
| 259 | '#description' => t('This will determine the base maximum number of actions that a character may perform before they must recharge their points. This may be further modified by character types or by in-game modifiers. '), |
| 260 | ); |
| 261 | $form['action']['rpg_action_recharge_rate'] = array( |
| 262 | '#type' => 'textfield', |
| 263 | '#title' => t('Action Point Recharge Rate'), |
| 264 | '#default_value' => $recharge, |
| 265 | '#size' => 7, |
| 266 | '#description' => t('This determines how many rounds must pass for an action point to recharge. This may be further modified by character types or by in-game modifiers. At the current duration of @duration per round, with the current recharge rate of @rate, a character will recharge approximately @figured per real-time day. To recharge @points in approximately a day, specify the recharge rate as @suggested.', array('@duration' => format_plural($duration, '1 second', '@count seconds'), '@points' => format_plural($max_points, '1 point', '@count points'), '@rate' => format_plural($recharge, '1 round', '@count rounds'), '@figured' => format_plural($figured, '1 point', '@count points'), '@suggested' => $suggested)), |
| 267 | ); |
| 268 | |
| 269 | $form['calendar'] = array( |
| 270 | '#type' => 'fieldset', |
| 271 | '#title' => t('RPG Calendar Settings'), |
| 272 | '#collapsible' => true, |
| 273 | '#collapsed' => true, |
| 274 | '#description' => t('These settings are for the in-game clock and calendar.'), |
| 275 | ); |
| 276 | $form['calendar']['rpg_action_round_calendar_increment'] = array( |
| 277 | '#type' => 'textfield', |
| 278 | '#title' => t('Increment of Game Calendar by Action Round'), |
| 279 | '#default_value' => $increment, |
| 280 | '#size' => 7, |
| 281 | '#description' => t('Specify how many game seconds pass per round of play in the game. Leave it at 0 for abstract or unspecified game time, or if the game calender will be incremented in some other method.'), |
| 282 | ); |
| 283 | |
| 284 | return $form; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * this is the included callback function for /rpg/admin/types/type/[type] |
| 289 | * this form is the edit type form |
| 290 | */ |
| 291 | function _rpg_admin_type_form($type) { |
| 292 | $form = array(); |
| 293 | $form['type'] = array( |
| 294 | '#type' => 'fieldset', |
| 295 | '#title' => t('Type Definition'), |
| 296 | '#description' => $type['shortdesc'], |
| 297 | '#collapsible' => true, |
| 298 | '#collapsed' => false, |
| 299 | ); |
| 300 | // if a module defines the type, then we lock the machine name |
| 301 | $form['type']['type'] = array( |
| 302 | '#type' => 'textfield', |
| 303 | '#title' => t('Machine-Readable Name'), |
| 304 | '#default_value' => $type['type'], |
| 305 | '#description' => t('This is the machine-readable name for the type. It is used only internally. Machine names for types defined by modules may not be modified.'), |
| 306 | '#disabled' => $type['lock'] ? true : false, |
| 307 | '#required' => true, |
| 308 | ); |
| 309 | $form['type']['name'] = array( |
| 310 | '#type' => 'textfield', |
| 311 | '#title' => t('Name'), |
| 312 | '#default_value' => $type['name'], |
| 313 | '#description' => t('This is the name of the type. It will be displayed during RPG object creation/editing, and on some object description screens.'), |
| 314 | ); |
| 315 | $form['type']['parents'] = array( |
| 316 | '#type' => 'fieldset', |
| 317 | '#title' => t('Parents'), |
| 318 | '#collapsible' => true, |
| 319 | '#collapsed' => true, |
| 320 | ); |
| 321 | $parents = array(); |
| 322 | foreach (rpg_types() as $parent) { |
| 323 | $parents[$parent['type']] = $parent['name']; |
| 324 | } |
| 325 | $form['type']['parents']['parents'] = array( |
| 326 | '#type' => 'select', |
| 327 | '#multiple' => true, |
| 328 | '#title' => t('Parents of @type', array('@type' => $type['name'])), |
| 329 | '#options' => $parents, |
| 330 | '#default_value' => $type['parents'], |
| 331 | '#description' => t('These are the parents for this type. The type will inherit any attributes, actions, and events of the parent types, which may be overridden.'), |
| 332 | ); |
| 333 | $form['type']['description'] = array( |
| 334 | '#type' => 'fieldset', |
| 335 | '#title' => t('Descriptions'), |
| 336 | '#description' => t('These descriptions appear in various help screens, for instance when creating or editing objects.'), |
| 337 | '#collapsible' => true, |
| 338 | '#collapsed' => false, |
| 339 | ); |
| 340 | $form['type']['description']['shortdesc'] = array( |
| 341 | '#type' => 'textfield', |
| 342 | '#title' => t('Short Description'), |
| 343 | '#default_value' => $type['shortdesc'], |
| 344 | ); |
| 345 | $form['type']['description']['longdesc'] = array( |
| 346 | '#type' => 'textarea', |
| 347 | '#title' => t('Long Description'), |
| 348 | '#default_value' => $type['longdesc'], |
| 349 | ); |
| 350 | |
| 351 | $form['submit'] = array( |
| 352 | '#type' => 'submit', |
| 353 | '#value' => t('Submit'), |
| 354 | ); |
| 355 | |
| 356 | //type, name, module, parents, shortdesc, longdesc, data |
| 357 | return $form; |
| 358 | } |
| 359 | |
| 360 | function _rpg_admin_attribute_add_form($type, $attribute) { |
| 361 | $form = array(); |
| 362 | |
| 363 | $form['type'] = array( |
| 364 | '#type' => 'value', |
| 365 | '#value' => $type['type'], |
| 366 | ); |
| 367 | |
| 368 | $form['attribute'] = array( |
| 369 | '#type' => 'textfield', |
| 370 | '#title' => t('Attribute'), |
| 371 | '#description' => t('This is the unique machine-readable name for the attribute, such as \'strength\' or \'hat_size\'. It may only contain alphanumeric characters and underscores.'), |
| 372 | '#required' => true, |
| 373 | ); |
| 374 | $form['name'] = array( |
| 375 | '#type' => 'textfield', |
| 376 | '#title' => t('Attribute name'), |
| 377 | '#description' => t('This is the name of the attribute, such as \'Strength\' or \'Hat size\'.'), |
| 378 | '#required' => true, |
| 379 | ); |
| 380 | |
| 381 | $classes = rpg_attribute_classes(); |
| 382 | // TODO: isn't there some php function to assign a subset of an array to another? |
| 383 | $options = array(); |
| 384 | foreach ($classes as $class) { |
| 385 | $options[$class['class']] = $class['label']; |
| 386 | } |
| 387 | $form['class'] = array( |
| 388 | '#type' => 'radios', |
| 389 | '#title' => t('Attribute class'), |
| 390 | '#description' => t('Please select the class of attribute to define'), |
| 391 | '#options' => $options, |
| 392 | '#required' => true, |
| 393 | ); |
| 394 | |
| 395 | $form['submit'] = array( |
| 396 | '#type' => 'submit', |
| 397 | '#value' => t('Submit'), |
| 398 | ); |
| 399 | return $form; |
| 400 | } |
| 401 | |
| 402 | function _rpg_admin_action_add_form($type, $action) { |
| 403 | $form = array(); |
| 404 | |
| 405 | $form['type'] = array( |
| 406 | '#type' => 'value', |
| 407 | '#value' => $type['type'], |
| 408 | ); |
| 409 | |
| 410 | $form['action'] = array( |
| 411 | '#type' => 'textfield', |
| 412 | '#title' => t('Action'), |
| 413 | '#description' => t('This is the unique machine-readable name for the action, such as \'take\' or \'throw_at\'. It may only contain alphanumeric characters and underscores.'), |
| 414 | '#required' => true, |
| 415 | ); |
| 416 | $form['name'] = array( |
| 417 | '#type' => 'textfield', |
| 418 | '#title' => t('Action name'), |
| 419 | '#description' => t('This is the name of the action, such as \'Take\' or \'Throw at\'.'), |
| 420 | '#required' => true, |
| 421 | ); |
| 422 | |
| 423 | $form['submit'] = array( |
| 424 | '#type' => 'submit', |
| 425 | '#value' => t('Submit'), |
| 426 | ); |
| 427 | return $form; |
| 428 | } |
| 429 | |
| 430 | function _rpg_admin_event_add_form($type, $event) { |
| 431 | $form = array(); |
| 432 | |
| 433 | $form['type'] = array( |
| 434 | '#type' => 'value', |
| 435 | '#value' => $type['type'], |
| 436 | ); |
| 437 | |
| 438 | $form['event'] = array( |
| 439 | '#type' => 'textfield', |
| 440 | '#title' => t('Event'), |
| 441 | '#description' => t('This is the unique machine-readable name for the event, such as \'on_destroy\' or \'on_enter\'. It may only contain alphanumeric characters and underscores.'), |
| 442 | '#required' => true, |
| 443 | ); |
| 444 | $form['name'] = array( |
| 445 | '#type' => 'textfield', |
| 446 | '#title' => t('Event name'), |
| 447 | '#description' => t('This is the name of the event, such as \'on exit\' or \'on create\'.'), |
| 448 | '#required' => true, |
| 449 | ); |
| 450 | |
| 451 | $form['submit'] = array( |
| 452 | '#type' => 'submit', |
| 453 | '#value' => t('Submit'), |
| 454 | ); |
| 455 | return $form; |
| 456 | } |
| 457 | |
| 458 | function _rpg_admin_attribute_edit_form($type, $attribute) { |
| 459 | $class = rpg_attribute_classes($attribute['class']); |
| 460 | $form = array(); |
| 461 | |
| 462 | $form['type'] = array( |
| 463 | '#type' => 'value', |
| 464 | '#value' => $type['type'], |
| 465 | ); |
| 466 | $form['attribute'] = array( |
| 467 | '#type' => 'value', |
| 468 | '#value' => $attribute['attribute'], |
| 469 | ); |
| 470 | $form['class'] = array( |
| 471 | '#type' => 'value', |
| 472 | '#value' => $attribute['class'], |
| 473 | ); |
| 474 | $form['definition'] = array( |
| 475 | '#type' => 'fieldset', |
| 476 | '#title' => t('Attribute definition'), |
| 477 | '#description' => t("The following items only affect the '%attribute' %class attribute of the %type type, and any types derived from it.", array('%attribute' => $attribute['name'], '%class' => $class['label'], '%type' => $type['name'])), |
| 478 | '#collapsible' => true, |
| 479 | '#collapsed' => false, |
| 480 | ); |
| 481 | $form['definition']['name'] = array( |
| 482 | '#type' => 'textfield', |
| 483 | '#title' => t('Name'), |
| 484 | '#default_value' => $attribute['name'], |
| 485 | ); |
| 486 | $form['definition']['description'] = array( |
| 487 | '#type' => 'textarea', |
| 488 | '#title' => t('Description'), |
| 489 | '#default_value' => $attribute['description'], |
| 490 | ); |
| 491 | $form['definition']['get'] = array( |
| 492 | '#type' => 'textfield', |
| 493 | '#title' => t('Get'), |
| 494 | '#description' => t("If it exists, this function will be called when the system attempts to get an object's value for this attribute. As the value returned will override the value stored in the database, this is generally used only for figured class attributes, but may be used on other occassions, or as a general way to override an inherited attribute with a figured value."), |
| 495 | '#default_value' => $attribute['get'], |
| 496 | ); |
| 497 | $form['definition']['verify'] = array( |
| 498 | '#type' => 'textfield', |
| 499 | '#title' => t('Verify'), |
| 500 | '#description' => t("If it exists, this function will be called before setting an object's value for this attribute. If the function returns false, the value will not be set."), |
| 501 | '#default_value' => $attribute['verify'], |
| 502 | ); |
| 503 | $form['definition']['set'] = array( |
| 504 | '#type' => 'textfield', |
| 505 | '#title' => t('Set'), |
| 506 | '#description' => t("If it exists, this function will be called after setting an object's value for this attribute. It is generally used to set other attributes dependent on this one, or to fire new events."), |
| 507 | '#default_value' => $attribute['set'], |
| 508 | ); |
| 509 | $form['definition']['default_value'] = array( |
| 510 | '#type' => 'textfield', |
| 511 | '#title' => t('Default value'), |
| 512 | '#description' => t("If given, then this is the default value that this attribute will be set for new objects."), |
| 513 | '#default_value' => $attribute['default_value'], |
| 514 | ); |
| 515 | $form['definition']['form_display'] = array( |
| 516 | '#type' => 'textfield', |
| 517 | '#title' => t('Form display'), |
| 518 | '#description' => t("If given, then this function will be called to determine whether to display the attribute in the object add/edit form."), |
| 519 | '#default_value' => $attribute['form_display'], |
| 520 | ); |
| 521 | $form['definition']['settings'] = module_invoke($class['module'], 'rpg_attribute_class_settings', 'settings form', $class['class'], $attribute, $type); |
| 522 | $form['submit'] = array( |
| 523 | '#type' => 'submit', |
| 524 | '#value' => t('Submit'), |
| 525 | ); |
| 526 | return $form; |
| 527 | } |
| 528 | |
| 529 | function _rpg_admin_action_edit_form($type, $action) { |
| 530 | $form = array(); |
| 531 | |
| 532 | $form['type'] = array( |
| 533 | '#type' => 'value', |
| 534 | '#value' => $type['type'], |
| 535 | ); |
| 536 | $form['action'] = array( |
| 537 | '#type' => 'value', |
| 538 | '#value' => $action['action'], |
| 539 | ); |
| 540 | $form['definition'] = array( |
| 541 | '#type' => 'fieldset', |
| 542 | '#title' => t('Action definition'), |
| 543 | '#description' => t("The following items only affect the '%action' action of the %type type, and any types derived from it.", array('%action' => $action['name'], '%type' => $type['name'])), |
| 544 | '#collapsible' => true, |
| 545 | '#collapsed' => false, |
| 546 | ); |
| 547 | $form['definition']['name'] = array( |
| 548 | '#type' => 'textfield', |
| 549 | '#title' => t('Name'), |
| 550 | '#default_value' => $action['name'], |
| 551 | ); |
| 552 | $form['definition']['description'] = array( |
| 553 | '#type' => 'textarea', |
| 554 | '#title' => t('Description'), |
| 555 | '#default_value' => $action['description'], |
| 556 | ); |
| 557 | $form['definition']['script'] = array( |
| 558 | '#type' => 'fieldset', |
| 559 | '#title' => t('Action script'), |
| 560 | '#collapsible' => true, |
| 561 | '#collapsed' => false, |
| 562 | '#description' => t('Insert the functions to be called here. Please follow the suggested guidelines for programming action scripts. If not, not only might you break your game, you might inadvertantly compromise the security of the rest of your site.'), |
| 563 | ); |
| 564 | $form['definition']['script']['php'] = array( |
| 565 | '#type' => 'textfield', |
| 566 | '#title' => t('Action'), |
| 567 | '#default_value' => $action['php'], |
| 568 | '#description' => t('This function will be called when an action is performed.'), |
| 569 | ); |
| 570 | $form['definition']['script']['expose'] = array( |
| 571 | '#type' => 'textfield', |
| 572 | '#title' => t('Expose'), |
| 573 | '#default_value' => $action['expose'], |
| 574 | '#description' => t('This function will be called to see whether to display an action as available to a character.'), |
| 575 | ); |
| 576 | |
| 577 | $form['submit'] = array( |
| 578 | '#type' => 'submit', |
| 579 | '#value' => t('Submit'), |
| 580 | ); |
| 581 | return $form; |
| 582 | } |
| 583 | |
| 584 | function _rpg_admin_event_edit_form($type, $event) { |
| 585 | $form = array(); |
| 586 | |
| 587 | $form['type'] = array( |
| 588 | '#type' => 'value', |
| 589 | '#value' => $type['type'], |
| 590 | ); |
| 591 | $form['event'] = array( |
| 592 | '#type' => 'value', |
| 593 | '#value' => $event['event'], |
| 594 | ); |
| 595 | $form['definition'] = array( |
| 596 | '#type' => 'fieldset', |
| 597 | '#title' => t('Event definition'), |
| 598 | '#description' => t("The following items only affect the '%event' event of the %type type, and any types derived from it.", array('%event' => $event['name'], '%type' => $type['name'])), |
| 599 | '#collapsible' => true, |
| 600 | '#collapsed' => false, |
| 601 | ); |
| 602 | $form['definition']['name'] = array( |
| 603 | '#type' => 'textfield', |
| 604 | '#title' => t('Name'), |
| 605 | '#default_value' => $event['name'], |
| 606 | ); |
| 607 | $form['definition']['description'] = array( |
| 608 | '#type' => 'textarea', |
| 609 | '#title' => t('Description'), |
| 610 | '#default_value' => $event['description'], |
| 611 | ); |
| 612 | $form['definition']['script'] = array( |
| 613 | '#type' => 'fieldset', |
| 614 | '#title' => t('Event script'), |
| 615 | '#collapsible' => true, |
| 616 | '#collapsed' => false, |
| 617 | '#description' => t('Insert the functions to be called here. Please follow the suggested guidelines for programming event scripts. If not, not only might you break your game, you might inadvertantly compromise the security of the rest of your site.'), |
| 618 | ); |
| 619 | $form['definition']['script']['php'] = array( |
| 620 | '#type' => 'textfield', |
| 621 | '#title' => t('Event'), |
| 622 | '#default_value' => $event['php'], |
| 623 | '#description' => t('This function will be called when an event is performed.'), |
| 624 | ); |
| 625 | |
| 626 | $form['submit'] = array( |
| 627 | '#type' => 'submit', |
| 628 | '#value' => t('Submit'), |
| 629 | ); |
| 630 | return $form; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Build the form of defined & inherited attributes for a type. |
| 635 | * |
| 636 | * This creates a form with two field sets, for defined and inherited attributes of a type. |
| 637 | * Each lists a short description and actions available from this screen (edit, delete, override, etc.). |
| 638 | * Underneath is a link to add a new attribute to the type. |
| 639 | * |
| 640 | * @param $type |
| 641 | * The RPG Type array for the desired type. |
| 642 | * @return $form |
| 643 | * The form to display. |
| 644 | */ |
| 645 | function _rpg_admin_type_attributes_form($type) { |
| 646 | $form = array(); |
| 647 | $form['inherited'] = array( |
| 648 | '#type' => 'fieldset', |
| 649 | '#title' => t('Inherited Attributes'), |
| 650 | '#collapsible' => true, |
| 651 | '#collapsed' => true, |
| 652 | '#description' => t('These attributes are inherited in the %type type. Attributes surrounded with \'(parentheses)\' are overridden in the Defined Attributes section below.', array('%type' => $type['type'])), |
| 653 | ); |
| 654 | $header = array(t('Attribute'), t('Parent Type'), t('Description'), t('Actions')); |
| 655 | $rows = array(); |
| 656 | foreach ($type['attributes']['inherited'] as $attribute) { |
| 657 | $cells = array(); |
| 658 | |
| 659 | // if an inherited type is overruled by a defined type, put parentheses around it. otherwise, just have a link |
| 660 | if (isset($type['attributes']['defined'][$attribute['attribute']])) { |
| 661 | $cells[] = t('(!attribute)', array('!attribute' => l($attribute['name'], 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']))); |
| 662 | } |
| 663 | else { |
| 664 | $cells[] = l($attribute['name'], 'admin/rpg/types/type/' . $type['type'] . '/attributes/add/' . $attribute['attribute']); |
| 665 | } |
| 666 | $parent = rpg_types($attribute['inherited']); |
| 667 | $cells[] = l($parent['name'], 'admin/rpg/types/type/' . $parent['type']); |
| 668 | $cells[] = check_plain($attribute['description']); |
| 669 | $actions = array(); |
| 670 | |
| 671 | // if we have an override in place, call the edit link edit. otherwise, have an add link called override |
| 672 | if (isset($type['attributes']['defined'][$attribute['attribute']])) { |
| 673 | $actions[] =l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']); |
| 674 | } |
| 675 | else { |
| 676 | $actions[] = l(t('override'), 'admin/rpg/types/type/' . $type['type'] . '/attributes/add/' . $attribute['attribute']); |
| 677 | } |
| 678 | $cells[] = implode(', ', $actions); |
| 679 | $rows[] = $cells; |
| 680 | } |
| 681 | $form['inherited']['attributes'] = array( |
| 682 | '#type' => 'markup', |
| 683 | '#value' => theme('table', $header, $rows), |
| 684 | ); |
| 685 | |
| 686 | $form['attributes'] = array( |
| 687 | '#type' => 'fieldset', |
| 688 | '#title' => t('Defined Attributes'), |
| 689 | '#collapsible' => true, |
| 690 | '#collapsed' => true, |
| 691 | '#description' => t('These attributes are defined for the %type type. Attributes marked with \'*\' are overridden over their inherited values. If deleted from this section, overridden attributes will be reverted to their inherited value.', array('%type' => $type['type'])), |
| 692 | ); |
| 693 | $header = array(t('Attribute'), t('Description'), t('Actions')); |
| 694 | $rows = array(); |
| 695 | foreach ($type['attributes']['defined'] as $attribute) { |
| 696 | $cells = array(); |
| 697 | if (isset($type['attributes']['inherited'][$attribute['attribute']])) { |
| 698 | $cells[] = t('!attribute *', array('!attribute' => l($attribute['name'], 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']))); |
| 699 | } |
| 700 | else { |
| 701 | $cells[] = l($attribute['name'], 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']); |
| 702 | } |
| 703 | $cells[] = check_plain($attribute['description']); |
| 704 | $actions = array(); |
| 705 | $actions[] = l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']); |
| 706 | $actions[] = l(t('delete'), 'admin/rpg/types/type/' . $type['type'] . '/attributes/delete/' . $attribute['attribute']); |
| 707 | $cells[] = implode(', ', $actions); |
| 708 | $rows[] = $cells; |
| 709 | } |
| 710 | $form['attributes']['attributes'] = array( |
| 711 | '#type' => 'markup', |
| 712 | '#value' => theme('table', $header, $rows), |
| 713 | ); |
| 714 | $form['add'] = array( |
| 715 | '#type' => 'markup', |
| 716 | '#value' => l('Add new attribute', 'admin/rpg/types/type/' . $type['type'] . '/attributes/add'), |
| 717 | ); |
| 718 | return $form; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Build the form of defined & inherited actions for a type. |
| 723 | * |
| 724 | * This creates a form with two field sets, for defined and inherited actions of a type. |
| 725 | * Each lists a short description and actions available from this screen (edit, delete, override, etc.). |
| 726 | * Underneath is a link to add a new attribute to the type. |
| 727 | * |
| 728 | * @param $type |
| 729 | * The RPG Type array for the desired type. |
| 730 | * @return $form |
| 731 | * The form to display. |
| 732 | */ |
| 733 | function _rpg_admin_type_actions_form($type) { |
| 734 | $form = array(); |
| 735 | $form['inherited'] = array( |
| 736 | '#type' => 'fieldset', |
| 737 | '#title' => t('Inherited actions'), |
| 738 | '#collapsible' => true, |
| 739 | '#collapsed' => true, |
| 740 | '#description' => t('These actions are inherited in the %type type. Actions surrounded with \'(parentheses)\' are overridden in the Defined Actions section below.', array('%type' => $type['type'])), |
| 741 | ); |
| 742 | $header = array(t('Action'), t('Parent Type'), t('Description'), t('Actions')); |
| 743 | $rows = array(); |
| 744 | foreach ($type['actions']['inherited'] as $action) { |
| 745 | $cells = array(); |
| 746 | if (isset($type['actions']['defined'][$action['action']])) { |
| 747 | $cells[] = t('(!action)', array('!action' => l($action['name'], 'admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['action']))); |
| 748 | } |
| 749 | else { |
| 750 | $cells[] = l($action['name'], 'admin/rpg/types/type/' . $type['type'] . '/actions/add/' . $action['action']); |
| 751 | } |
| 752 | $parent = rpg_types($action['inherited']); |
| 753 | $cells[] = l($parent['name'], 'admin/rpg/types/type/' . $parent['type']); |
| 754 | $cells[] = check_plain($action['description']); |
| 755 | $actions = array(); |
| 756 | if (isset($type['actions']['defined'][$action['attribute']])) { |
| 757 | $actions[] =l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['attribute']); |
| 758 | } |
| 759 | else { |
| 760 | $actions[] = l(t('override'), 'admin/rpg/types/type/' . $type['type'] . '/actions/add/' . $action['attribute']); |
| 761 | } |
| 762 | $cells[] = implode(', ', $actions); |
| 763 | $rows[] = $cells; |
| 764 | } |
| 765 | $form['inherited']['actions'] = array( |
| 766 | '#type' => 'markup', |
| 767 | '#value' => theme('table', $header, $rows), |
| 768 | ); |
| 769 | |
| 770 | $form['actions'] = array( |
| 771 | '#type' => 'fieldset', |
| 772 | '#title' => t('Defined actions'), |
| 773 | '#collapsible' => true, |
| 774 | '#collapsed' => true, |
| 775 | '#description' => t('These actions are defined for the %type type. Actions marked with \'*\' are overridden over their inherited values. If deleted from this section, overridden actions will be reverted to their inherited value.', array('%type' => $type['type'])), |
| 776 | ); |
| 777 | $header = array(t('Action'), t('Description'), t('Actions')); |
| 778 | $rows = array(); |
| 779 | foreach ($type['actions']['defined'] as $action) { |
| 780 | $cells = array(); |
| 781 | if (isset($type['actions']['inherited'][$action['action']])) { |
| 782 | $cells[] = t('!action *', array('!action' => l($action['name'], 'admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['action']))); |
| 783 | } |
| 784 | else { |
| 785 | $cells[] = l($action['name'], 'admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['action']); |
| 786 | } |
| 787 | $cells[] = check_plain($action['description']); |
| 788 | $actions = array(); |
| 789 | $actions[] = l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['action']); |
| 790 | $actions[] = l(t('delete'), 'admin/rpg/types/type/' . $type['type'] . '/actions/delete/' . $action['action']); |
| 791 | $cells[] = implode(', ', $actions); |
| 792 | $rows[] = $cells; |
| 793 | } |
| 794 | $form['actions']['actions'] = array( |
| 795 | '#type' => 'markup', |
| 796 | '#value' => theme('table', $header, $rows), |
| 797 | ); |
| 798 | $form['add'] = array( |
| 799 | '#type' => 'markup', |
| 800 | '#value' => l('Add new action', 'admin/rpg/types/type/' . $type['type'] . '/actions/add'), |
| 801 | ); |
| 802 | return $form; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * Build the form of defined & inherited events for a type. |
| 807 | * |
| 808 | * This creates a form with two field sets, for defined and inherited events of a type. |
| 809 | * Each lists a short description and events available from this screen (edit, delete, override, etc.). |
| 810 | * Underneath is a link to add a new attribute to the type. |
| 811 | * |
| 812 | * @param $type |
| 813 | * The RPG Type array for the desired type. |
| 814 | * @return $form |
| 815 | * The form to display. |
| 816 | */ |
| 817 | function _rpg_admin_type_events_form($type) { |
| 818 | $form = array(); |
| 819 | $form['inherited'] = array( |
| 820 | '#type' => 'fieldset', |
| 821 | '#title' => t('Inherited events'), |
| 822 | '#collapsible' => true, |
| 823 | '#collapsed' => true, |
| 824 | '#description' => t('These events are inherited in the %type type. Events surrounded with \'(parentheses)\' are overridden in the Defined Events section below.', array('%type' => $type['type'])), |
| 825 | ); |
| 826 | $header = array(t('Event'), t('Parent Type'), t('Description'), t('Events')); |
| 827 | $rows = array(); |
| 828 | foreach ($type['events']['inherited'] as $event) { |
| 829 | $cells = array(); |
| 830 | if (isset($type['events']['defined'][$event['event']])) { |
| 831 | $cells[] = t('(!event)', array('!event' => l($event['name'], 'admin/rpg/types/type/' . $type['type'] . '/events/edit/' . $event['event']))); |
| 832 | } |
| 833 | else { |
| 834 | $cells[] = l($event['name'], 'admin/rpg/types/type/' . $type['type'] . '/events/add/' . $event['event']); |
| 835 | } |
| 836 | $parent = rpg_types($event['inherited']); |
| 837 | $cells[] = l($parent['name'], 'admin/rpg/types/type/' . $parent['type']); |
| 838 | $cells[] = check_plain($event['description']); |
| 839 | $events = array(); |
| 840 | if (isset($type['events']['defined'][$event['attribute']])) { |
| 841 | $events[] =l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/events/edit/' . $event['attribute']); |
| 842 | } |
| 843 | else { |
| 844 | $events[] = l(t('override'), 'admin/rpg/types/type/' . $type['type'] . '/events/add/' . $event['attribute']); |
| 845 | } |
| 846 | $cells[] = implode(', ', $events); |
| 847 | $rows[] = $cells; |
| 848 | } |
| 849 | $form['inherited']['events'] = array( |
| 850 | '#type' => 'markup', |
| 851 | '#value' => theme('table', $header, $rows), |
| 852 | ); |
| 853 | |
| 854 | $form['events'] = array( |
| 855 | '#type' => 'fieldset', |
| 856 | '#title' => t('Defined events'), |
| 857 | '#collapsible' => true, |
| 858 | '#collapsed' => true, |
| 859 | '#description' => t('These events are defined for the %type type. Events marked with \'*\' are overridden over their inherited values. If deleted from this section, overridden events will be reverted to their inherited value.', array('%type' => $type['type'])), |
| 860 | ); |
| 861 | $header = array(t('Event'), t('Description'), t('Events')); |
| 862 | $rows = array(); |
| 863 | foreach ($type['events']['defined'] as $event) { |
| 864 | $cells = array(); |
| 865 | if (isset($type['events']['inherited'][$event['event']])) { |
| 866 | $cells[] = t('!event *', array('!event' => l($event['name'], 'admin/rpg/types/type/' . $type['type'] . '/events/edit/' . $event['event']))); |
| 867 | } |
| 868 | else { |
| 869 | $cells[] = l($event['name'], 'admin/rpg/types/type/' . $type['type'] . '/events/edit/' . $event['event']); |
| 870 | } |
| 871 | $cells[] = check_plain($event['description']); |
| 872 | $events = array(); |
| 873 | $events[] = l(t('edit'), 'admin/rpg/types/type/' . $type['type'] . '/events/edit/' . $event['event']); |
| 874 | $events[] = l(t('delete'), 'admin/rpg/types/type/' . $type['type'] . '/events/delete/' . $event['event']); |
| 875 | $cells[] = implode(', ', $events); |
| 876 | $rows[] = $cells; |
| 877 | } |
| 878 | $form['events']['events'] = array( |
| 879 | '#type' => 'markup', |
| 880 | '#value' => theme('table', $header, $rows), |
| 881 | ); |
| 882 | $form['add'] = array( |
| 883 | '#type' => 'markup', |
| 884 | '#value' => l('Add new event', 'admin/rpg/types/type/' . $type['type'] . '/events/add'), |
| 885 | ); |
| 886 | return $form; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Build the form to add (or override) an attribute for an RPG type. |
| 891 | * |
| 892 | * This form will include all the elements for an attribute of the given class. If overriding a type, then the elements |
| 893 | * will be prepopulated with the inherited values. |
| 894 | * |
| 895 | * @param $type |
| 896 | * The RPG type array to add the array to, as called by rpg_types($type); |
| 897 | * @param $attribute |
| 898 | * An optional string. If given, then we will override the attribute defined by the type's parent(s). |
| 899 | */ |
| 900 | function _rpg_admin_type_attribute_add($type, $attribute = NULL) { |
| 901 | // allow a type to override an inherited attribute, or define an attribute from outside its tree |
| 902 | if (isset($attribute)) { |
| 903 | $attribute = rpg_attributes($attribute); |
| 904 | if (!isset($attribute['attribute'])) { |
| 905 | drupal_not_found(); |
| 906 | } |
| 907 | // add the attribute to be added or overridden |
| 908 | if (!isset($type['attributes']['defined'][$attribute['attribute']])) { |
| 909 | if (isset($type['attributes']['inherited'][$attribute['attribute']])) { |
| 910 | $override = true; |
| 911 | drupal_set_message(t('Overriding the existing %attribute attribute for the %type type. You may edit it below.', array('%attribute' => $attribute['name'], '%type' => $type['name']))); |
| 912 | } |
| 913 | else { |
| 914 | $override = false; |
| 915 | drupal_set_message(t('Added new %attribute attribute to the %type type. You may edit it below.', array('%attribute' => $attribute['name'], '%type' => $type['name']))); |
| 916 | } |
| 917 | // include rpg_attribute_add |
| 918 | rpg_include_loadcache(); |
| 919 | |
| 920 | $attribute = rpg_attribute_add($type['type'], $attribute); |
| 921 | } |
| 922 | else { |
| 923 | drupal_set_message(t('The %attribute attribute is already defined for the %type type. However, you may edit it below.', array('%attribute' => $attribute['name'], '%type' => $type['name'])), 'error'); |
| 924 | } |
| 925 | // redirect to the attribute's new edit screen |
| 926 | drupal_goto('admin/rpg/types/type/' . $type['type'] . '/attributes/edit/' . $attribute['attribute']); |
| 927 | } |
| 928 | else { |
| 929 | $attribute = array(); |
| 930 | $attribute['is_new'] = true; |
| 931 | } |
| 932 | |
| 933 | return _rpg_admin_attribute_add_form($type, $attribute); |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Build the form to add (or override) an action for an RPG type. |
| 938 | * |
| 939 | * This form will include all the elements for an action of the given class. If overriding a type, then the elements |
| 940 | * will be prepopulated with the inherited values. |
| 941 | * |
| 942 | * @param $type |
| 943 | * The RPG type array to add the action to, as called by rpg_types($type); |
| 944 | * @param $action |
| 945 | * An optional string. If given, then we will override the action defined by the type's parent(s). |
| 946 | */ |
| 947 | function _rpg_admin_type_action_add($type, $action = NULL) { |
| 948 | // allow a type to override an inherited action, or define an action from outside its tree |
| 949 | if (isset($action)) { |
| 950 | $action = rpg_actions($action); |
| 951 | if (!isset($action['action'])) { |
| 952 | drupal_not_found(); |
| 953 | } |
| 954 | // add the action to be added or overridden |
| 955 | if (!isset($type['actions']['defined'][$attribute['action']])) { |
| 956 | if (isset($type['actions']['inherited'][$attribute['action']])) { |
| 957 | $override = true; |
| 958 | drupal_set_message(t('Overriding the existing %action action for the %type type. You may edit it below.', array('%action' => $action['name'], '%type' => $type['name']))); |
| 959 | } |
| 960 | else { |
| 961 | $override = false; |
| 962 | drupal_set_message(t('Added new %action action to the %type type. You may edit it below.', array('%action' => $action['name'], '%type' => $type['name']))); |
| 963 | } |
| 964 | // include rpg_action_add |
| 965 | rpg_include_loadcache(); |
| 966 | |
| 967 | $action = rpg_action_add($type['type'], $action['action'], $action['name']); |
| 968 | } |
| 969 | else { |
| 970 | drupal_set_message(t('The %action action is already defined for the %type type. However, you may edit it below.', array('%action' => $action['name'], '%type' => $type['name'])), 'error'); |
| 971 | } |
| 972 | // redirect to the action's new edit screen |
| 973 | drupal_goto('admin/rpg/types/type/' . $type['type'] . '/actions/edit/' . $action['action']); |
| 974 | } |