Created
June 2, 2025 12:01
-
-
Save jacobsapps/bb9982f29158398455a5395b9dc18c5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CardEntity { | |
static func from(_ card: Card) -> CardEntity { | |
CardEntity( | |
id: card.id, | |
title: card.stats.title, | |
emoji: card.stats.type.emoji, | |
hexColor: card.stats.type.hexClor, | |
rarity: String(describing: card.stats.rarity), | |
stats: card.stats.stats.map { StatEntity(name: $0.name, value: $0.value) }, | |
image: card.image | |
) | |
} | |
func toCard() -> Card? { | |
guard let image = UIImage(data: imageData) else { return nil } | |
let cardStats = CardStats( | |
title: title, | |
type: ElementalType(emoji: emoji, hexClor: hexColor), | |
stats: stats.map { Stat(name: $0.name, value: $0.value) }, | |
rarity: Rarity(rawValue: rarity) ?? .rare | |
) | |
return Card(id: id, image: image, stats: cardStats) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment