Made generation of components and authorings separate
This commit is contained in:
parent
33c181038c
commit
a75a83702b
|
@ -16,27 +16,39 @@ function get_twig_inc()
|
|||
return __DIR__ ."/../tpl";
|
||||
}
|
||||
|
||||
function get_gen_root()
|
||||
{
|
||||
global $GAME_ROOT;
|
||||
return "$GAME_ROOT/unity/Assets/Scripts/autogen/ecs";
|
||||
}
|
||||
|
||||
function generate_ecs_components(\mtgMetaInfo $meta)
|
||||
{
|
||||
global $GAME_ROOT;
|
||||
|
||||
$gen_root = get_gen_root();
|
||||
$twig = \metagen_cs\get_twig(array(get_twig_inc()));
|
||||
$twig->setCache($GAME_ROOT . "/build/twig/metagen_cs_ecs");
|
||||
$gen_components = new \mtgMetaInfo();
|
||||
$lock_file = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/ecs.lock";
|
||||
$gen_authorings = new \mtgMetaInfo();
|
||||
$lock_file = "$gen_root/ecs.lock";
|
||||
|
||||
foreach ($meta->getUnits() as $unit)
|
||||
{
|
||||
if(!$unit->object->hasToken('ecs_gen_component') || !($unit->object instanceof \mtgUserType))
|
||||
if(!($unit->object instanceof \mtgUserType))
|
||||
continue;
|
||||
$gen_components->addUnit($unit);
|
||||
if($unit->object->hasToken('ecs_gen_component'))
|
||||
$gen_components->addUnit($unit);
|
||||
if($unit->object->hasToken('ecs_gen_authoring'))
|
||||
$gen_authorings->addUnit($unit);
|
||||
}
|
||||
|
||||
if(!\taskman\need_to_regen($lock_file, get_meta_units_files($gen_components)))
|
||||
if(!\taskman\need_to_regen($lock_file, get_meta_units_files($gen_components)) &&
|
||||
!\taskman\need_to_regen($lock_file, get_meta_units_files($gen_authorings)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
\taskman\rrmdir("$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/");
|
||||
\taskman\ensure_rm($gen_root);
|
||||
\taskman\ensure_write($lock_file, "");
|
||||
touch($lock_file);
|
||||
|
||||
|
@ -44,7 +56,7 @@ function generate_ecs_components(\mtgMetaInfo $meta)
|
|||
{
|
||||
$unit_name = $unit->object->getName();
|
||||
$filePath = str_replace(".", "/", $unit_name);
|
||||
$file = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/$filePath.cs";
|
||||
$file = "$gen_root/$filePath.cs";
|
||||
$name_components = explode('.', $unit_name);
|
||||
$class_name = end($name_components);
|
||||
if($class_name != $unit_name)
|
||||
|
@ -52,7 +64,7 @@ function generate_ecs_components(\mtgMetaInfo $meta)
|
|||
else
|
||||
$namespace = "";
|
||||
|
||||
// Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
// TODO: Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
if(empty($namespace))
|
||||
$namespace = "ecs";
|
||||
|
||||
|
@ -74,12 +86,28 @@ function generate_ecs_components(\mtgMetaInfo $meta)
|
|||
],
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($gen_authorings->getUnits() as $unit)
|
||||
{
|
||||
$unit_name = $unit->object->getName();
|
||||
$filePath = str_replace(".", "/", $unit_name);
|
||||
$file = "$gen_root/{$filePath}AuthoringComponent.cs";
|
||||
$name_components = explode('.', $unit_name);
|
||||
$class_name = end($name_components);
|
||||
if($class_name != $unit_name)
|
||||
$namespace = str_replace(".$class_name", "", $unit_name);
|
||||
else
|
||||
$namespace = "";
|
||||
|
||||
// TODO: Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
if(empty($namespace))
|
||||
$namespace = "ecs";
|
||||
|
||||
$file_authoring = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/{$filePath}AuthoringComponent.cs";
|
||||
if($unit->object->hasToken('ecs_gen_authoring'))
|
||||
{
|
||||
\taskman\ensure_write_if_differs(
|
||||
$file_authoring,
|
||||
$file,
|
||||
$twig->render('codegen_ecs_authoring.twig', [
|
||||
'namespace' => $namespace,
|
||||
'class_name' => $class_name,
|
||||
|
|
Loading…
Reference in New Issue