From f4f4d3bf27c7a2e45021387243cf294f4dbdb7d3 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 19 May 2025 19:21:06 +0300 Subject: [PATCH] Services codegen is now a part of standard codegen --- src/codegen.inc.php | 2 ++ tpl/codegen_factory.twig | 6 ++---- tpl/service_macro.twig | 15 --------------- 3 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 997d04b..4fe5eeb 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -59,6 +59,8 @@ function codegen(?string $cache_dir, \mtgMetaInfo $meta, array $options = []) : $output['factory.cs'] = $twig->render('codegen_factory.twig', $options); + $output['services.cs'] = codegen_services($cache_dir, filter_services_meta($meta), $options); + return $output; } diff --git a/tpl/codegen_factory.twig b/tpl/codegen_factory.twig index 2c949d3..608bbf5 100644 --- a/tpl/codegen_factory.twig +++ b/tpl/codegen_factory.twig @@ -19,10 +19,8 @@ static public class AutogenBundle { switch(class_id) { -{%- for u in meta.getunits ~%} -{%- if u.object is instanceof('\\mtgMetaStruct')~%} - case {{u.object.classid}}: { return new {{u.object.name}}(); } -{%- endif ~%} +{%- for t in meta.factorytypes ~%} + case {{t.classid}}: { return new {{t.fullname}}(); } {%- endfor ~%} default: { diff --git a/tpl/service_macro.twig b/tpl/service_macro.twig index 4dbfb67..22f9e5c 100644 --- a/tpl/service_macro.twig +++ b/tpl/service_macro.twig @@ -21,21 +21,6 @@ public interface IRpc : metagen.IRpc public static class Factory { - public static IMetaStruct CreateById(uint class_id) - { - switch(class_id) - { -{%- for utype in obj.usertypes %} - {%- if utype is instanceof('\\mtgMetaStruct') ~%} - case {{utype.classid}}: - return new {{utype.name}}(); - {% endif %} -{%- endfor ~%} - } - //fallback to global factory - return AutogenBundle.createById(class_id); - } - public static IRpc CreateRPC(int code) { switch(code)