Adding @enum_replace support

This commit is contained in:
Pavel Shevaev 2023-11-09 17:47:36 +03:00
parent 90acee3b62
commit 7ac955a389
2 changed files with 20 additions and 1 deletions

View File

@ -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)

View File

@ -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));
}