Various improvements

This commit is contained in:
Ilya Laktyushin
2024-07-13 18:13:58 +04:00
parent 3134a4ef1b
commit 4216ee3933
125 changed files with 4969 additions and 1474 deletions

View File

@@ -24,6 +24,7 @@ public enum CodableDrawingEntity: Equatable {
case vector(DrawingVectorEntity)
case location(DrawingLocationEntity)
case link(DrawingLinkEntity)
case weather(DrawingWeatherEntity)
public init?(entity: DrawingEntity) {
if let entity = entity as? DrawingStickerEntity {
@@ -40,6 +41,8 @@ public enum CodableDrawingEntity: Equatable {
self = .location(entity)
} else if let entity = entity as? DrawingLinkEntity {
self = .link(entity)
} else if let entity = entity as? DrawingWeatherEntity {
self = .weather(entity)
} else {
return nil
}
@@ -61,6 +64,8 @@ public enum CodableDrawingEntity: Equatable {
return entity
case let .link(entity):
return entity
case let .weather(entity):
return entity
}
}
@@ -109,6 +114,14 @@ public enum CodableDrawingEntity: Equatable {
size = entitySize
}
}
case let .weather(entity):
position = entity.position
size = entity.renderImage?.size
rotation = entity.rotation
scale = entity.scale
if let size {
cornerRadius = 10.0 / (size.width * entity.scale)
}
default:
return nil
}
@@ -198,6 +211,7 @@ extension CodableDrawingEntity: Codable {
case vector
case location
case link
case weather
}
public init(from decoder: Decoder) throws {
@@ -218,6 +232,8 @@ extension CodableDrawingEntity: Codable {
self = .location(try container.decode(DrawingLocationEntity.self, forKey: .entity))
case .link:
self = .link(try container.decode(DrawingLinkEntity.self, forKey: .entity))
case .weather:
self = .weather(try container.decode(DrawingWeatherEntity.self, forKey: .entity))
}
}
@@ -245,6 +261,9 @@ extension CodableDrawingEntity: Codable {
case let .link(payload):
try container.encode(EntityType.link, forKey: .type)
try container.encode(payload, forKey: .entity)
case let .weather(payload):
try container.encode(EntityType.weather, forKey: .type)
try container.encode(payload, forKey: .entity)
}
}
}