Gradually adding support for all features
This commit is contained in:
parent
34eb73a20e
commit
df2827cbaf
|
@ -80,6 +80,12 @@ function _add_twig_support(\Twig\Environment $twig)
|
|||
return $v;
|
||||
}
|
||||
));
|
||||
$twig->addFunction(new \Twig\TwigFunction('get_all_fields',
|
||||
function($meta, $o)
|
||||
{
|
||||
return \mtg_get_all_fields($meta, $o);
|
||||
}
|
||||
));
|
||||
$twig->addFilter(new \Twig\TwigFilter('go_type',
|
||||
function($type, $tokens)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% macro decl_units(meta) %}
|
||||
{%- for u in meta.getunits ~%}
|
||||
{%- if u.object is instanceof('\\mtgMetaStruct') ~%}
|
||||
{{ _self.decl_struct(u.object) }}
|
||||
{{ _self.decl_struct(meta, u.object) }}
|
||||
{%- elseif u.object is instanceof('\\mtgMetaEnum') ~%}
|
||||
{{ _self.decl_enum(u.object) }}
|
||||
{%- elseif u.object is instanceof('\\mtgMetaRPC') ~%}
|
||||
|
@ -10,7 +10,7 @@
|
|||
{%- endfor ~%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro decl_struct(o) %}
|
||||
{% macro decl_struct(meta, o) %}
|
||||
|
||||
//==============================
|
||||
type {{o.name}} struct {
|
||||
|
@ -20,13 +20,11 @@ type {{o.name}} struct {
|
|||
|
||||
{{_self.decl_struct_fields(o)}}
|
||||
}
|
||||
var _{{o.name}}_class_props map[string]string
|
||||
var _{{o.name}}_class_fields []string = %fields_names%
|
||||
var _{{o.name}}_fields_props meta.ClassFieldsProps
|
||||
func init() {
|
||||
_{{o.name}}_class_props = %class_props%
|
||||
_{{o.name}}_fields_props = %fields_props%
|
||||
}
|
||||
|
||||
var _{{o.name}}_class_props map[string]string = {{_self.props_map(o.tokens)}}
|
||||
var _{{o.name}}_class_fields []string = {{_self.struct_fields_names(meta, o)}}
|
||||
var _{{o.name}}_fields_props meta.ClassFieldsProps = {{_self.struct_fields_props(meta, o)}}
|
||||
|
||||
func {{o.name}}_CLASS_ID() uint32 {
|
||||
return {{o.classid}}
|
||||
}
|
||||
|
@ -88,10 +86,39 @@ func (self *{{o.name}}) WriteFields(writer meta.Writer) error {
|
|||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro props_map(tokens) %}
|
||||
map[string]string{
|
||||
{% for k,v in tokens %}
|
||||
"{{k}}" : "{{v|replace({'"' : '\\"'})}}",
|
||||
{%- endfor ~%}
|
||||
}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro struct_fields_names(meta, o) %}
|
||||
[]string{
|
||||
{% for f in get_all_fields(meta, o) ~%}
|
||||
"{{f.name}}",
|
||||
{%- endfor ~%}
|
||||
}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro struct_fields_props(meta, o) %}
|
||||
map[string]map[string]string{
|
||||
{% for f in get_all_fields(meta, o) ~%}
|
||||
"{{f.name|ucfirst}}" : {{_self.props_map(f.tokens)}},
|
||||
{%- endfor ~%}
|
||||
}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro decl_struct_fields(o) %}
|
||||
{%- for f in o.fields ~%}
|
||||
{{f.name|ucfirst}} {{f.type|go_type(f.tokens)}} {{f.name|first != '_' ? '`json:"' ~ f.name ~ '"`'}}
|
||||
{%- endfor ~%}
|
||||
|
||||
{%if has_token(o, 'bitfields') %}
|
||||
fieldsMask meta.FieldsMask //@bitfields support
|
||||
{%- endif ~%}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro decl_enum(o) %}
|
||||
|
|
Loading…
Reference in New Issue