Skip to content

Commit

Permalink
Simplify media metadata renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Jul 31, 2023
1 parent 67d8f8e commit 72b1225
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
22 changes: 3 additions & 19 deletions src/metadata/media/MediaMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ import { VersionedContract } from "../../VersionedContract.sol";
/// @notice A DAO's artwork generator and renderer
/// @custom:repo github.com/ourzora/nouns-protocol
contract MediaMetadata is IMediaMetadata, VersionedContract, Initializable, UUPS, MediaMetadataStorageV1 {
/// ///
/// CONSTANTS ///
/// ///
uint8 public constant SELECTION_TYPE_SEQUENTIAL = 0;

uint8 public constant SELECTION_TYPE_RANDOM = 1;

uint8 public constant SELECTION_TYPE_LOOP = 2;

/// ///
/// IMMUTABLES ///
/// ///
Expand Down Expand Up @@ -153,7 +144,7 @@ contract MediaMetadata is IMediaMetadata, VersionedContract, Initializable, UUPS
// Ensure the caller is the token contract
if (msg.sender != settings.token) revert ONLY_TOKEN();

_generateMetadata(_tokenId);
return _generateMetadata(_tokenId);
}

/// @notice Generates attributes for a requested set of tokens
Expand All @@ -169,21 +160,14 @@ contract MediaMetadata is IMediaMetadata, VersionedContract, Initializable, UUPS
}

function _generateMetadata(uint256 _tokenId) internal returns (bool) {
// Compute some randomness for the token id
uint256 seed = _generateSeed(_tokenId);

// Cache the total number of properties available
uint256 numMediaItems = mediaItems.length;
uint8 selectionType = settings.selectionType;

if (numMediaItems == 0 || selectionType > 2 || (selectionType == SELECTION_TYPE_SEQUENTIAL && numMediaItems - 1 < _tokenId)) {
if (numMediaItems == 0 || numMediaItems - 1 < _tokenId) {
return false;
}

if (selectionType == SELECTION_TYPE_SEQUENTIAL) tokenIdToSelectedMediaItem[_tokenId] = _tokenId;
if (selectionType == SELECTION_TYPE_RANDOM) tokenIdToSelectedMediaItem[_tokenId] = seed % numMediaItems;
if (selectionType == SELECTION_TYPE_LOOP) tokenIdToSelectedMediaItem[_tokenId] = _tokenId % numMediaItems;

tokenIdToSelectedMediaItem[_tokenId] = _tokenId;
return true;
}

Expand Down
3 changes: 0 additions & 3 deletions src/metadata/media/interfaces/IMediaMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ interface IMediaMetadata is IBaseMetadata, MediaMetadataTypesV1 {
/// @dev Reverts if the caller does not include a media item during an artwork upload
error ONE_MEDIA_ITEM_REQUIRED();

/// @dev Reverts if the selection type is invalid
error INVALID_SELECTION_TYPE();

/// ///
/// FUNCTIONS ///
/// ///
Expand Down
1 change: 0 additions & 1 deletion src/metadata/media/types/MediaMetadataTypesV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface MediaMetadataTypesV1 {
string description;
string contractImage;
string rendererBase;
uint8 selectionType;
}

struct AdditionalTokenProperty {
Expand Down

0 comments on commit 72b1225

Please sign in to comment.