Separate register into different methods
This commit is contained in:
parent
e4ab175143
commit
62f61e4674
|
@ -220,6 +220,44 @@ function add_twig_support(\Twig\Environment $twig)
|
|||
return $arr;
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('slice_units',
|
||||
function(array $units, $max)
|
||||
{
|
||||
$pages = paginate(sizeof($units), $max);
|
||||
|
||||
$sliced = array();
|
||||
|
||||
$units_keys = array_keys($units);
|
||||
|
||||
foreach($pages as $idx => $page)
|
||||
{
|
||||
$slice = array();
|
||||
for($i = $page[0];$i<$page[1];++$i)
|
||||
{
|
||||
$slice[] = $units[$units_keys[$i]];
|
||||
}
|
||||
$sliced[$idx] = $slice;
|
||||
}
|
||||
return $sliced;
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
function paginate($total, $step)
|
||||
{
|
||||
//pages are returned as an array where each element is in interval [N, Y)
|
||||
$pages = array();
|
||||
|
||||
$steps = (int)($total/$step);
|
||||
$rest = $total % $step;
|
||||
|
||||
for($i=1;$i<=$steps;++$i)
|
||||
$pages[] = array(($i-1)*$step, $i*$step);
|
||||
|
||||
if($rest != 0)
|
||||
$pages[] = array(($i-1)*$step, ($i-1)*$step + $rest);
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function ns_last($name)
|
||||
|
|
|
@ -27,10 +27,12 @@ public static void Register(Types types)
|
|||
BHL_Types.Type_GenericArray = new GenericArrayTypeSymbol(new Proxy<IType>());
|
||||
|
||||
{% block register %}
|
||||
{{ macro.reg_units(meta.units) }}
|
||||
{{ macro.call_reg_units(slice_units(meta.units, 20)) }}
|
||||
{% endblock %}
|
||||
}
|
||||
|
||||
{{ macro.decl_reg_units(slice_units(meta.units, 20)) }}
|
||||
|
||||
}
|
||||
|
||||
} //namespace bhl
|
||||
|
|
|
@ -977,6 +977,21 @@ public partial class Script_{{u.object.name}} {
|
|||
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro call_reg_units(sliced_units) ~%}
|
||||
{%- for idx,units in sliced_units -%}
|
||||
Register_{{idx}}(types);
|
||||
{%~ endfor -%}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro decl_reg_units(sliced_units) ~%}
|
||||
{%- for idx,units in sliced_units -%}
|
||||
public static void Register_{{idx}}(Types types)
|
||||
{
|
||||
{{ _self.reg_units(units) }}
|
||||
}
|
||||
{%~ endfor -%}
|
||||
{%- endmacro -%}
|
||||
|
||||
{%- macro reg_units(units) ~%}
|
||||
|
||||
{%- for u in units -%}
|
||||
|
|
Loading…
Reference in New Issue