propresenter7-php-lib/src/Macro.php
Thorsten Bus b30918af41 feat(macros): add reader for global Macros file
Importer for ProPresenter's protobuf-encoded `Macros` document. Exposes
each macro's UUID and name plus the collections that group them.

- src/MacroLibrary.php: top-level wrapper indexed by UUID and name
- src/Macro.php, src/MacroCollection.php: per-entry wrappers
- src/MacrosFileReader.php: file -> MacroLibrary entry point
- bin/parse-macros.php: CLI listing macros and collections
- tests/MacrosFileReaderTest.php: 10 tests against reference sample
- doc/api/macros.md: API reference, plus INDEX/keywords updates
2026-05-03 20:38:47 +02:00

96 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace ProPresenter\Parser;
use Rv\Data\MacrosDocument\Macro as MacroProto;
/**
* Wraps a protobuf Macro, exposing its identifying fields (UUID, name) plus
* convenience metadata (color, action count, image type, startup flag).
*
* Macros live in the global ProPresenter `Macros` document and may belong to
* one or more {@see MacroCollection}s. Membership is resolved by
* {@see MacroLibrary}, not by this wrapper.
*/
class Macro
{
public function __construct(
private readonly MacroProto $macro,
) {
}
/**
* Get the macro's UUID as an upper-case string (empty when unset).
*/
public function getUuid(): string
{
return $this->macro->getUuid()?->getString() ?? '';
}
/**
* Get the macro's display name.
*/
public function getName(): string
{
return $this->macro->getName();
}
/**
* Get the macro's color as an associative array, or null when unset.
*
* @return array{r: float, g: float, b: float, a: float}|null
*/
public function getColor(): ?array
{
if (!$this->macro->hasColor()) {
return null;
}
$color = $this->macro->getColor();
return [
'r' => $color->getRed(),
'g' => $color->getGreen(),
'b' => $color->getBlue(),
'a' => $color->getAlpha(),
];
}
/**
* Whether the macro is configured to fire on application startup.
*/
public function getTriggerOnStartup(): bool
{
return $this->macro->getTriggerOnStartup();
}
/**
* Number of action entries attached to this macro.
*
* Action payloads are not exposed by this wrapper; use {@see getProto()} to
* inspect them via the generated protobuf classes.
*/
public function getActionCount(): int
{
return count($this->macro->getActions());
}
/**
* Icon enum value (see {@see \Rv\Data\MacrosDocument\Macro\ImageType}).
*/
public function getImageType(): int
{
return $this->macro->getImageType();
}
/**
* Get the underlying protobuf Macro message.
*/
public function getProto(): MacroProto
{
return $this->macro;
}
}