#include "helper.h"
#include "c.h"
#include "ld.h"
#include "runner.h"
#include "tier1/utlstring.h"
#include "tier1/commandline.h"

void build_shader( const char *szName )
{
	IFileSystem2::MakeDirectory(CUtlString("build/funnygame/assets/gfx"));

	CUtlVector<CUtlString> slang_args = {
		CUtlString("funnyassets/gfx_shaders/%s.slang", szName),
		"-o",
		CUtlString("build/funnygame/assets/gfx/%s.spv", szName),
	};

	IRunner::Run("slangc", slang_args);
	
};

int assets_build()
{
	IFileSystem2::CopyDirectory("build", "tools");

	IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/maps");
	IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/gfx");
	IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/textures");
	IFileSystem2::CopyDirectory(CUtlString("build/funnygame/assets"), "funnyassets/materials");
	build_shader("mesh_frag");
	build_shader("mesh_vert");
	build_shader("agx_comp");
	build_shader("mesh_edge_detection_comp");
	CUtlVector<CUtlString> python_args = {
		"build/tools/makepak64.py",
		CUtlString("build/funnygame/assets"),
		bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "rtt") : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "rtt"),
	};
	V_printf("%s\n",
		bStaticBuild ? CUtlString("%s/bin/%s.pak", szOutputDir.GetString(), "rtt").GetString() : CUtlString("%s/funnygame/%s.pak", szOutputDir.GetString(), "rtt").GetString()
		);
	IRunner::Run("python3", python_args);
	return 0;
};
DECLARE_BUILD_STAGE(assets, assets_build);
