Archive for January, 2009

Crayon Physics

This has got to be one of the coolest games I have ever seen.

I've always been a fan of puzzle games, but in this particular game, the puzzle of how to connect a ball to a star separated by distances and objects, is as dynamic as your imagination.

Players are presented with more than 70 different puzzles and its brilliance is found in the way it challenges you to use your imagination to envision and then implement your own unique solutions to each one.

In the PC version, players use the mouse to draw shapes and objects that react to the laws of physics. For example, if you draw a box in the air, it will fall because of gravity.

What's particularly clever about this game (as you'll see in the video below) is that you can be as creative as you want. Simple levers and inclined planes work, but then again, so will rockets, dragons, and trebuchets.

Watch the video to see what I'm talking about... Other really interesting demonstrations can be seen here and here.

[tags]crayon, game, petri+purho, physics[/tags]

New Drupal Module Released

Back in October, I released my first module for Drupal, the open-source content management system. These days, I seem to be developing exclusively for Drupal, and with a robust API and thriving community, I can only say how much fun it is to work with.

However, like any platforms, there are pieces missing. Fortunately, Drupal is one of those platforms that is very easily extended through modules. I came across one of those missing pieces while working on a project. I do all of my development in a sandbox, and when the work is complete, I QA the product in a staging environment before pushing the code and database changes to a production environment. I found that there was no way to manage user/role permissions in code; all management was a manual process via the web interface.

Having to repeat manual tasks like this across different environments increases the odds of errors. Steps can be omitted or performed improperly. In the case of permissions, I decided to correct that by writing a module called Permissions API. What this module allows you to do is to grant and revoke permissions to roles in code.

This is probably most useful in the context of programmatically creating CCK content types. The ability to import CCK content types through code is great until you decide that you want members of specific roles to be able to do something with this content type. Currently, the only way to grant the permissions is to navigate through the access control page in the admin interface, which is completely unusable if you have a lot of roles and a lot of modules. This module addresses that problem by providing two functions:

permissions_grant_permissions()
permissions_revoke_permissions()

Each function accepts a role id and an array of permissions. Sample usage would be:

PHP:
  1. <?php
  2. function mymodule_update_1(){
  3.   // Handle roles and permissions
  4.   $rid = db_result(db_query('SELECT r.rid FROM {role} r WHERE r.name = \'some custom role\''));
  5.   if($rid> 0){
  6.     $permissions = array(
  7.       'create some_content_type content',
  8.       'edit some_content_type content',
  9.       'edit own some_content_type content',
  10.     );
  11.     permissions_grant_permissions($rid, $permissions)
  12.   }
  13. }
  14. ?>

This module also provides functions for granting all permissions defined by a given module to a given role, as well as granting all defined permissions to a given role, which is useful for creating admin-type roles. Sample usage would be:

PHP:
  1. <?php
  2. function mymodule_update_2(){
  3.   // Create a "super-admin" role by granting all permissions
  4.   $rid = db_result(db_query('SELECT r.rid FROM {role} r WHERE r.name = \'some custom role\''));
  5.   if($rid> 0){
  6.     permissions_grant_all_permissions($rid);
  7.   }
  8. }
  9. ?>

The next example shows how to grant all permissions defined by a specific module to a specific role:

PHP:
  1. <?php
  2. function mymodule_update_3(){
  3.   // Grant all permissions defined by a module's hook_perm implementation
  4.   $rid = db_result(db_query('SELECT r.rid FROM {role} r WHERE r.name = \'some custom role\''));
  5.   if($rid> 0){
  6.     permissions_grant_all_permissions_by_module($rid, 'some module')
  7.   }
  8. }
  9. ?>

[tags]api, code, drupal, module, permissions[/tags]

Return top

INFORMATION

Drupal development since v4.7