Game Development Community

dev|Pro Game Development Curriculum

Datablock Organization in World Editor for T3D

by Paul Weston · 02/27/2014 (11:49 am) · 7 comments

Thought I'd post this since it's been a nice feature for us, what with having so many datablock types cluttering up the World Editor tree window.

This resource lets you use category names for your datablocks such as "Weapons/Ammo" or "Destroyables/Exploding_Crate", and then in the World Editor you will be able to drill down through a folder hierarchy to find those datablocks.

Ported from this resource for TGE by Daniel Buckmaster:
http://www.garagegames.com/community/resources/view/18959

In tools/worldeditor/scripts/editors/creator.ed.cs, find this conditional around line 291:

if ( %this.tab $= "Scripted" )
   {
      %category = getWord( %address, 1 );                  
      %dataGroup = "DataBlockGroup";
      
      for ( %i = 0; %i < %dataGroup.getCount(); %i++ )
      {
         %obj = %dataGroup.getObject(%i);
         // echo ("Obj: " @ %obj.getName() @ " - " @ %obj.category );
         
         if ( %obj.category $= "" && %obj.category == 0 )
            continue;
            
         // Add category to popup menu if not there already
         if ( CreatorPopupMenu.findText( %obj.category ) == -1 )
            CreatorPopupMenu.add( %obj.category );
         
         if ( %address $= "" )
         {         
            %ctrl = %this.findIconCtrl( %obj.category );
            if ( %ctrl == -1 )
            {
               %this.addFolderIcon( %obj.category );
            }    
         }
         else if ( %address $= %obj.category )
         {            
            %ctrl = %this.findIconCtrl( %obj.getName() );
            if ( %ctrl == -1 )
               %this.addShapeIcon( %obj );
         }
      }
   }


... and replace with this code:

if ( %this.tab $= "Scripted" )
   {
      %category = getWord( %address, 1 );  
      %itemcount = %dataGroup.getCount();      
      
      for ( %i = 0; %i < %dataGroup.getCount(); %i++ )
      {
         %obj = %dataGroup.getObject(%i);
         //echo ("Obj: " @ %obj.getName() @ " - " @ %obj.category );
         
         if ( %obj.category $= "" && %obj.category == 0 )
            continue;
         
         // this is a bit of a low-tech hack to store some variables we will need:
         %myTokens = %obj.category;
            %myTokens = nextToken( %myTokens , "theToken" , "/" ); 
            %first_level = %theToken;
            %myTokens = nextToken( %myTokens , "theToken" , "/" ); 
            %second_level = %theToken;
         
         %myTokens = %address;
            %myTokens = nextToken( %myTokens , "theToken" , " " ); 
            %first_address = %theToken;
            %myTokens = nextToken( %myTokens , "theToken" , " " ); 
            %second_address = %theToken;

         // AT ROOT LEVEL                                 
         if ( %address $= "" && %category $= "")
         {         
            %ctrl = %this.findIconCtrl( %first_level );
            if ( %ctrl == -1 )
            {
               %this.addFolderIcon( %first_level );
            }    
         }

         // ONE LEVEL DOWN WITH SUBS       
         else if ( (%address $= %first_level) && (%second_level !$= "") )
         {         
            %ctrl = %this.findIconCtrl( %second_level );
            if ( %ctrl == -1 )
            {
               %this.addFolderIcon( %second_level );
            }    
         }

         // ONE LEVEL DOWN WITH NO-SUBS 
         else if ( (%address $= %first_level) && (%second_level $= "") )
         {            
            %ctrl = %this.findIconCtrl( %obj.getName() );
            if ( %ctrl == -1 ) {
               %this.addShapeIcon( %obj );
            }
         }
         
         // TWO LEVELS DOWN
         else if ( (%second_address $= %second_level) && (%second_level !$= "") )
         {
            %ctrl = %this.findIconCtrl( %obj.getName() );
            if ( %ctrl == -1 ) {
               %this.addShapeIcon( %obj );
            }
         }
         
      }
   }

That's it!

Mind you, this is only set up for one sub-level because that's all we needed - it hasn't been tested with any further depth... But one extra level per category should be more than enough to clean up your tree window clutter.

Hope this helps someone out there... And this was a bit of a quick post, if anyone finds any bugs please let me know.

Cheers!

#1
02/27/2014 (4:38 pm)
Sounds awesome! Could you post a picture or two to show off the difference?
#2
02/28/2014 (6:33 am)
Sure no problem, here you go...

This first image shows our datablocks before the fix was applied. Note that the category names have already been edited to fit into the new scheme - I wasn't about to go back and change all the categories to what they were before the fix, I just swapped out the tools quickly to take these caps.

All the ones with DESTROYABLES/ as a prefix were originally displayed at the root level as categories, as seen below just without the prefix on the name which was edited into the datablock files:

riversidefantasy.ca/NCC1701/new-tools-1.jpg

Now this next image shows the same root level with the fix applied. Note that all the destroyable stuff is gone, just the main DESTROYABLES category is displayed:

riversidefantasy.ca/NCC1701/new-tools-2.jpg

Finally, this third image shows what happens when you drill down to the DESTROYABLES folder, and all the explosive datablocks are there instead of the root now:

riversidefantasy.ca/NCC1701/new-tools-3.jpg

Been using this fix steadily since last yesterday without issue, can still create all objects in the editor OK and nothing seems amiss. So hopefully it will help others who have a lot of datablocks to manage :)

Cheers
P
#3
03/01/2014 (8:06 am)
Looks nifty!
#4
03/03/2014 (8:02 am)
nice!
#5
03/03/2014 (11:53 am)
Anybody try it out yet?

Maybe I'm the only one who had so many datablocks in their game that they needed this resource lol.

FYI - no bugs have appeared in the World Editor since implementing this 4 days ago... So it appears to be solid.

P
#6
03/07/2014 (4:42 am)
Hai i will test it because i have a batshit amount of models....
#7
03/29/2014 (3:11 pm)
Thanks for porting this up!