Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*******************************/
- /* CFGTownGenerator PHP Parser */
- /* Created by Seven */
- /*******************************/
- function getClasses($file){
- $classes = array("position[]"=>null, "type"=>null, "direction"=>null);
- $class = array();
- $objects = array();
- $total = 0;
- $skippedJunk = false;
- $inZone = false;
- $inObject = false;
- $file = $file."/config.cpp";
- //Check if file exists.
- if(File_Exists($file)) {
- //Split into lines
- $contents = explode("\n",file_get_contents($file));
- }
- foreach ($contents as $line) {
- //Cleanup any spaces in each line
- $line = trim($line);
- $parts = array();
- //Remove blank lines
- if(empty($line) || $line == ""){
- continue;
- }
- //Find start of object
- if($line == 'class CfgTownGenerator {') {
- $skippedJunk = true;
- continue;
- }
- //Find the Zone
- if( $skippedJunk && preg_match("/class (?!object)/i", $line)) {
- $inZone = true;
- continue;
- }
- if( preg_match("/class object/i", $line)) {
- $class[$total] = array("position[]"=>"0,0,0", "type"=>"blank", "direction"=>"0");
- $inObject = true;
- continue;
- }
- //Don't Parse until we find the start string
- if(!$skippedJunk)
- continue;
- //Find end of Object and reset everything
- if($inObject && $line == "};") {
- $objects[count($objects)] = $class[$total];
- $total++;
- $inObject = false;
- continue;
- }
- if($inZone && $line == "};") {
- $inZone = false;
- continue;
- }
- if($skippedJunk && $line == "};") {
- $skippedJunk = false;
- continue;
- }
- //Split the var from the value
- if($inObject && strpos($line,"="))
- $parts = explode("=", $line);
- //Cleanup and add them to the class array
- if( count($parts) > 0 && array_key_exists(trim($parts[0]), $classes)) {
- if($parts[0] == "type")
- $parts[1] = substr($parts[1],2,-3);
- if($parts[0] == "position[] ")
- $parts[1] = substr($parts[1],2,-2);
- if($parts[0] == "direction")
- (float)$parts[1] = substr($parts[1],1,-2);
- $class[$total][ trim($parts[0]) ] = trim( $parts[1] );
- }
- }
- return $objects;
- }
- function GenerateCFGTown($zone) {
- //Loop through all the zone
- for($i=0;$i<count($zone);$i++) {
- //Check if there is a file for the zone
- if(File_Exists($zone[$i]."/config.cpp")) {
- //Start Generating class for zone
- $classes = getClasses($zone[$i]);
- for($j=0;$j<count($classes);$j++) {
- echo "class _vehicle_".$j."\n{<br>";
- echo " objectType=\"vehicle\";\n class Arguments\n {\n";
- echo " POSITION=\"[".$classes[$j]["position[]"]."]\";<br>";
- echo " TYPE=".$classes[$j]["type"]."<br>";
- echo " AZIMUT=\"".$classes[$j]["direction"]."\"<br>";
- echo " PARENT=\"\";\n };\n};<br>";
- }
- }
- }
- }
- $zones[0] = "cherno";
- /*Run The Generator*/
- echo "<pre>";
- ?>
- class _prefix_0
- {
- objectType="prefix";
- class Arguments
- {
- };
- };
- class _center_0
- {
- objectType="center";
- class Arguments
- {
- SIDE="west";
- };
- };
- class _group_0
- {
- objectType="group";
- class Arguments
- {
- CENTER="_center_0";
- };
- };
- class _unit_0
- {
- objectType="unit";
- class Arguments
- {
- POSITION="[8085.1489, 9379.293, -6.1035156e-005]";
- GROUP="_group_0";
- TYPE="Sniper1_DZ";
- AZIMUT="10.054947";
- SKILL="0.60000002";
- PLAYER="true";
- PLAYABLE="true";
- LEADER="true";
- };
- };
- <?php
- GenerateCFGTown($zones);
- ?>
- class _postfix_0
- {
- objectType="postfix";
- class Arguments
- {
- };
- };
- <?php
- echo "</pre>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment