Adding factory support
This commit is contained in:
parent
a0fd8af74b
commit
cf873df1e4
|
@ -18,19 +18,36 @@ var _ = sort.SearchInts
|
|||
|
||||
func CreateById(classId uint32) (meta.IMetaStruct, error) {
|
||||
switch classId {
|
||||
%create_struct_by_crc28%
|
||||
|
||||
{%- for u in meta.getunits ~%}
|
||||
{%- if u.object is instanceof('\\mtgMetaStruct')~%}
|
||||
case {{u.object.classid}}: { return New{{u.object.name}}(), nil }
|
||||
{%- endif ~%}
|
||||
{%- endfor ~%}
|
||||
|
||||
default : return nil, errors.Errorf("Can't find struct for class id %d", classId)
|
||||
}
|
||||
}
|
||||
func CreateByName(name string) (meta.IMetaStruct, error) {
|
||||
switch name {
|
||||
%create_struct_by_name%
|
||||
|
||||
{%- for u in meta.getunits ~%}
|
||||
{%- if u.object is instanceof('\\mtgMetaStruct')~%}
|
||||
case "{{u.object.name}}": { return New{{u.object.name}}(), nil }
|
||||
{%- endif ~%}
|
||||
{%- endfor ~%}
|
||||
|
||||
default : return nil, errors.Errorf("Can't find struct for name %s", name)
|
||||
}
|
||||
}
|
||||
func CreateRPC(code uint32)(meta.IRPC, error) {
|
||||
switch code {
|
||||
%create_rpc_by_code%
|
||||
|
||||
{%- for u in meta.getunits ~%}
|
||||
{%- if u.object is instanceof('\\mtgMetaRPC')~%}
|
||||
case {{u.object.code}}: { return New{{u.object.name}}(), nil }
|
||||
{%- endif ~%}
|
||||
{%- endfor ~%}
|
||||
default: return nil, errors.Errorf("Can't find rpc for code %d", code)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ map[string]map[string]string{
|
|||
|
||||
{% 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 ~ '"`'}}
|
||||
{{f.name|ucfirst}} {{f.type|go_type(f.tokens)}} {{_self.field_annotations(o, f)}}
|
||||
{%- endfor ~%}
|
||||
|
||||
{%if has_token(o, 'bitfields') %}
|
||||
|
@ -155,6 +155,12 @@ fieldsMask meta.FieldsMask //@bitfields support
|
|||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro field_annotations(o, f) %}
|
||||
{%- if f.name|first != '_' -%}
|
||||
`json:"{{f.name}}" {% if has_token(o, 'table') -%} db:"{{f.name}}"{%- endif -%}`
|
||||
{%- endif -%}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro struct_reset_fields(o) %}
|
||||
|
||||
{%- if o.parent ~%}
|
||||
|
|
Loading…
Reference in New Issue