FGD API example
March 5th, 2010
Just a sample from the FGD code I wrote for the Hl2Parse library. This snippet loads the TF2 FGD file and then re-outputs the FGD format to show it has parsed everything. It also prints the “default” version and then the “combined” version which collapses all the inheritance.
final String fgdPath = "..."; FgdSpec spec = new FgdSpec(); spec.loadFrom(new File(fgd)); final String entName = "func_respawnroom"; FgdEntClass spawnroom = spec.getEntClass(entName); // Get normal version System.out.println(spawnroom.toText(entName)); // Print sparse form FgdEntClass combined = spawnroom.getInherited(spec); // Do inheritance System.out.println(combined.toText(entName)); // Print comnined formThe first print statement replicates the set-up in the original file, using the base(…) modifier to do inheritance.
@SolidClass base(Targetname,TeamNum,EnableDisable,Toggle) = func_respawnroom : "Designates a respawn room for a team." [ ]The second prints statement shows how it looks after the inheritance rules have been applied.
@SolidClass = func_respawnroom : "Designates a respawn room for a team." [ targetname(target_source) : "Name" : "" : "The name that other entities refer to this entity by." StartDisabled(choices) : "Start Disabled" : 0 : "" = [ 0:"No" 1:"Yes" ] TeamNum(choices) : "Team" : 0 : "Team" = [ 0:"Any" 2:"Red" 3:"Blue" ] input KillHierarchy(void) : "Removes this entity and all its children from the world." input Enable(void) : "Enable this entity." input Disable(void) : "Disable this entity." input SetTeam(integer) : "Changes the entity's team." input Kill(void) : "Removes this entity from the world." input FireUser4(void) : "Causes this entity's OnUser4 output to be fired." input FireUser3(void) : "Causes this entity's OnUser3 output to be fired." input FireUser2(void) : "Causes this entity's OnUser2 output to be fired." input AddOutput(string) : "Adds an entity I/O connection to this entity. Format: <output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire (-1 == infinite)>. Very dangerous, use with care." input FireUser1(void) : "Causes this entity's OnUser1 output to be fired." input Toggle(void) : "Toggle the enabled/disabled status of this entity." output OnUser1(void) : "Fired in response to FireUser1 input." output OnUser4(void) : "Fired in response to FireUser4 input." output OnUser2(void) : "Fired in response to FireUser2 input." output OnUser3(void) : "Fired in response to FireUser3 input." ]