diff --git a/metagen.inc.php b/metagen.inc.php index 0d7fd47..1ebb08e 100644 --- a/metagen.inc.php +++ b/metagen.inc.php @@ -853,6 +853,12 @@ class mtgMetaEnum extends mtgUserType $this->tokens = array_merge($this->tokens, $other->getTokens()); $this->values = array_merge($this->values, $other->getValues()); } + + function replace(mtgMetaEnum $other) + { + $this->tokens = $other->getTokens(); + $this->values = $other->getValues(); + } } function mtg_get_all_fields(mtgMetaStruct $struct) diff --git a/parser.inc.php b/parser.inc.php index 806c9f2..0f0a25b 100644 --- a/parser.inc.php +++ b/parser.inc.php @@ -94,6 +94,7 @@ class mtgMetaInfoParser $config['valid_tokens'][] = 'class_id'; $config['valid_tokens'][] = 'shared_tokens'; $config['valid_tokens'][] = 'enum_override'; + $config['valid_tokens'][] = 'enum_replace'; } function parse(mtgMetaInfo $meta, $raw_file) @@ -374,12 +375,24 @@ class mtgMetaInfoParser { $existing = $this->current_meta->findUnit($enum->getMetaId()); if(!$existing) - throw new Exception("Not found '{$name}' enum to override"); + throw new Exception("Not found '{$name}' enum to override values"); if(!($existing->object instanceof mtgMetaEnum)) throw new Exception("Not an enum struct '{$name}'"); $existing->object->override($enum); } + //NOTE: special case for enums when we allow to 'replace' the original one, + // with additional values + else if($enum->hasToken('enum_replace')) + { + $existing = $this->current_meta->findUnit($enum->getMetaId()); + if(!$existing) + throw new Exception("Not found '{$name}' enum to replace values"); + if(!($existing->object instanceof mtgMetaEnum)) + throw new Exception("Not an enum struct '{$name}'"); + + $existing->object->replace($enum); + } else $this->_addUnit(new mtgMetaInfoUnit($this->file, $enum)); }