From d6b9d88e87c08723adba67960bc8060c1394523f Mon Sep 17 00:00:00 2001 From: wrenge Date: Fri, 27 Jan 2023 13:07:02 +0300 Subject: [PATCH] Fixed generation for bound structures --- src/codegen.inc.php | 35 ++++++++++++++++++++++++----------- tpl/macro_ecs.twig | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 491c59b..58bb66f 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -27,12 +27,18 @@ 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(); $gen_authorings = new \mtgMetaInfo(); $lock_file = "$gen_root/ecs.lock"; + if(!\taskman\need_to_regen($lock_file, get_meta_units_files($meta))) + { + return; + } + \taskman\ensure_rm($gen_root); + \taskman\ensure_write($lock_file, ""); + touch($lock_file); + foreach ($meta->getUnits() as $unit) { if(!($unit->object instanceof \mtgUserType)) @@ -42,15 +48,10 @@ function generate_ecs_components(\mtgMetaInfo $meta) if($unit->object->hasToken('ecs_gen_authoring')) $gen_authorings->addUnit($unit); } - - 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\ensure_rm($gen_root); - \taskman\ensure_write($lock_file, ""); - touch($lock_file); + + $twig = \metagen_cs\get_twig(array(get_twig_inc())); + _add_twig_support($twig); + $twig->setCache($GAME_ROOT . "/build/twig/metagen_cs_ecs"); foreach ($gen_components->getUnits() as $unit) { @@ -124,4 +125,16 @@ function get_meta_units_files(\mtgMetaInfo $meta) foreach($meta->getUnits() as $u) $files[$u->file] = true; return array_keys($files); +} + +function _add_twig_support(\Twig\Environment $twig) +{ + $twig->addFilter(new \Twig\TwigFilter('ecs_type', + function($type) + { + if(($type instanceof \mtgUserType) && $type->hasToken("bhl_native_class")) + return $type->getToken("bhl_native_class"); + return \metagen_cs\cs_type($type); + } + )); } \ No newline at end of file diff --git a/tpl/macro_ecs.twig b/tpl/macro_ecs.twig index 4e9dd7b..8f984cf 100644 --- a/tpl/macro_ecs.twig +++ b/tpl/macro_ecs.twig @@ -1,3 +1,3 @@ {%- macro ecs_component_field(obj, field) -%} - public {{field.type|cs_type}} {{field.name}}; + public {{field.type|ecs_type}} {{field.name}}; {%- endmacro -%} \ No newline at end of file