From 496c3cb0822f946b6ad46096fecbd0fe725d5d7f Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 7 Dec 2022 13:40:33 +0300 Subject: [PATCH] Gradually migrating to new metagen --- src/codegen.inc.php | 18 ++++++++++++++++++ tpl/codegen_bundle.twig | 18 +++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 9453924..77a5cd2 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -19,6 +19,24 @@ function get_twig(array $inc_path = []) return $twig; } +function supported_tokens() +{ + return [ + 'POD', + 'default', + 'optional', + 'cloneable', + 'virtual', + 'id', + 'owner', + 'pkey', + //TODO: + //'obscured', + //'bitfields', + //'diffable', + ]; +} + function _add_twig_support(\Twig\Environment $twig) { $twig->addTest(new \Twig\TwigTest('instanceof', diff --git a/tpl/codegen_bundle.twig b/tpl/codegen_bundle.twig index 55ef4b2..9f842d8 100644 --- a/tpl/codegen_bundle.twig +++ b/tpl/codegen_bundle.twig @@ -16,7 +16,11 @@ static public class AutogenBundle { switch(code) { - %create_rpc_by_id% +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaRPC') ~%} + case {{u.object.code}}: { return new {{u.object.name}}(); } +{%- endif ~%} +{%- endfor ~%} default: { return null; @@ -28,7 +32,11 @@ static public class AutogenBundle { switch(class_id) { - %create_struct_by_crc28% +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaEnum') or u.object is instanceof('\\mtgMetaStruct')~%} + case {{u.object.classid}}: { return new {{u.object.name}}(); } +{%- endif ~%} +{%- endfor ~%} default: { return null; @@ -40,7 +48,11 @@ static public class AutogenBundle { switch(class_id) { - %id2type% +{%- for u in meta.getunits ~%} +{%- if u.object is instanceof('\\mtgMetaEnum') or u.object is instanceof('\\mtgMetaStruct')~%} + case {{u.object.classid}}: { return typeof({{u.object.name}}); } +{%- endif ~%} +{%- endfor ~%} default: { return null;