Splitting registration and setup phases in order to make these phases order independent

This commit is contained in:
Pavel Shevaev 2023-05-23 14:34:31 +03:00
parent 989900eafa
commit 9d9eee1ab3
2 changed files with 14 additions and 12 deletions

View File

@ -15,28 +15,27 @@ using {{imp}};
namespace bhl {
{%- for u in meta.units ~%}
{%- if u.object is instanceof('\\mtgMetaStruct') ~%}
{%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%}
static public class Types_{{u.object.name|norm_name}} {
static public IType Value;
}
{%- endif ~%}
{%- endfor ~%}
{% block declare %}
#if !BHL_FRONT
{{ macro.decl_units(meta.units) }}
#endif
{% endblock %}
static public class {{register_class}} {
public static void Register(Types types)
{
{% block register %}
{{ macro.call_reg_units(slice_units(meta.units, 20)) }}
{{ macro.call_reg_units(slice_units(meta.units, 20)) }}
}
{{ macro.assign_global_types(meta.units) }}
{% endblock %}
public static void Setup(Types types)
{
{{ macro.setup_global_types(meta.units) }}
}
{{ macro.decl_reg_units(slice_units(meta.units, 20)) }}

View File

@ -703,7 +703,6 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{% endfor %}
);
ifs.Setup();
{{scope}}.{{o.name|ns_prefix}}Define(ifs);
}
@ -1047,17 +1046,21 @@ public partial class Script_{{u.object.name}} {
{%- endfor ~%}
{%- endmacro -%}
{%- macro assign_global_types(units) ~%}
{%- macro setup_global_types(units) ~%}
//assign global static types
{%- for u in units -%}
{%- if u.object is instanceof('\\mtgMetaStruct') ~%}
{%- if u.object is instanceof('\\mtgMetaStruct') or u.object is instanceof('\\mtgMetaInterface') ~%}
{%- if not has_token(u.object, 'bhl_ecs_component') ~%}
{
var tmp = types.T("{{u.object.name}}").Get();
if(tmp == null)
throw new System.Exception("Type '{{u.object.name}}' not resolved");
if(tmp is ClassSymbol cs)
cs.Setup();
{%- if u.object is instanceof('\\mtgMetaStruct') ~%}
(tmp as ClassSymbolNative)?.Setup();
{%- endif ~%}
{%- if u.object is instanceof('\\mtgMetaInterface') ~%}
(tmp as InterfaceSymbolNative)?.Setup();
{%- endif ~%}
Types_{{u.object.name|norm_name}}.Value = tmp;
}
{%~ endif ~%}