<?php 
$filePath = "./allDesc.txt";
$myfile = fopen($filePath, "r") or die("Unable to open file!");
$allDesc = fread($myfile,filesize($filePath));
fclose($myfile);

$allDescByChar = explode("\n", $allDesc);
$allDescs = array();
for($i = 0; $i < count($allDescByChar); $i++){
	//if (is_numeric($allDescByChar[$i][0])){
		array_push($allDescs, str_replace("\r", '', $allDescByChar[$i]));
		//array_push($allDescs, $allDescByChar[$i]);
	//} else {
		//array_push($allDescs, str_replace("\r", '', $allDescByChar[$i]."\n".$allDescByChar[$i+1]));
		//$i++;
	//}
}

	
for ($i = 1; $i <= 270; $i++){
	// $race = $i <= 90 ? 'Guardian' : ($i <= 180 ? 'Human' : 'Demon');
	// $newAttributes = array(
		// 'trait_type' => 'Race',
		// 'value' => $race
	// );
	
	// $filePath = "./$i";
	// $myfile = fopen($filePath, "r") or die("Unable to open file!");
	// $json = fread($myfile,filesize($filePath));
	// fclose($myfile);
	
	// $metadata = json_decode($json);
	// array_push($metadata->attributes, $newAttributes);
	// file_put_contents($i, json_encode($metadata));
	
	$filePath = "./$i";
	$myfile = fopen($filePath, "r") or die("Unable to open file!");
	$json = fread($myfile,filesize($filePath));
	fclose($myfile);
	
	$metadata = json_decode($json);
	
	$data = array( 
		'name' => $metadata->name,
		'description' => $metadata->description,
		'image' => $metadata->image,
		'turntable' => 'http://miracledev.net/bog/turntable/'.$i.'.mp4',
		'promotionalImg' => 'http://miracledev.net/bog/promotionalImg/'.$i.'.png',
		'external_url' => $metadata->external_url,
		'attributes' => [
			$metadata->attributes[0],
			$metadata->attributes[1],
			$metadata->attributes[2],
			[
				'trait_type' => 'Attack',
				'value' => $allDescs[$i-1]
			],
			$metadata->attributes[4],
			$metadata->attributes[5],
			$metadata->attributes[6],
		]
	);
	file_put_contents($i, json_encode($data));
}
?>