Don't explode when data contains invalid dye colour IDs

This commit is contained in:
Dylan K. Taylor
2021-04-28 13:39:03 +01:00
parent a44203a3d4
commit d5e5a81cff
6 changed files with 27 additions and 11 deletions

View File

@ -73,11 +73,11 @@ final class DyeColorIdMap{
return ~$this->toId($color) & 0xf;
}
public function fromId(int $id) : DyeColor{
return $this->idToEnum[$id]; //TODO: this might not be present (e.g. corrupted data)
public function fromId(int $id) : ?DyeColor{
return $this->idToEnum[$id];
}
public function fromInvertedId(int $id) : DyeColor{
public function fromInvertedId(int $id) : ?DyeColor{
return $this->fromId(~$id & 0xf);
}
}