Skip to content

Commit

Permalink
Final MVVM Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heestand-xyz committed Jan 14, 2022
1 parent 79ba392 commit 60aca53
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
36 changes: 36 additions & 0 deletions Sources/PixelKit/PIX/PIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,29 @@ open class PIX: NODE, ObservableObject, Equatable {
guard type.typeName == typeName else { continue }
switch type {
case .camera:
#if !os(tvOS)
return try encoder.encode(pixelModel as! CameraPixelModel)
#else
throw CodingError.badOS
#endif
case .image:
return try encoder.encode(pixelModel as! ImagePixelModel)
case .vector:
#if !os(tvOS)
return try encoder.encode(pixelModel as! VectorPixelModel)
#else
throw CodingError.badOS
#endif
case .video:
return try encoder.encode(pixelModel as! VideoPixelModel)
case .view:
return try encoder.encode(pixelModel as! ViewPixelModel)
case .web:
#if !os(tvOS)
return try encoder.encode(pixelModel as! WebPixelModel)
#else
throw CodingError.badOS
#endif
case .screenCapture:
#if os(macOS) && !targetEnvironment(macCatalyst)
return try encoder.encode(pixelModel as! ScreenCapturePixelModel)
Expand Down Expand Up @@ -727,17 +739,29 @@ open class PIX: NODE, ObservableObject, Equatable {
guard type.typeName == typeName else { continue }
switch type {
case .camera:
#if !os(tvOS)
return try decoder.decode(CameraPixelModel.self, from: data)
#else
throw CodingError.badOS
#endif
case .image:
return try decoder.decode(ImagePixelModel.self, from: data)
case .vector:
#if !os(tvOS)
return try decoder.decode(VectorPixelModel.self, from: data)
#else
throw CodingError.badOS
#endif
case .video:
return try decoder.decode(VideoPixelModel.self, from: data)
case .view:
return try decoder.decode(ViewPixelModel.self, from: data)
case .web:
#if !os(tvOS)
return try decoder.decode(WebPixelModel.self, from: data)
#else
throw CodingError.badOS
#endif
case .screenCapture:
#if os(macOS) && !targetEnvironment(macCatalyst)
return try decoder.decode(ScreenCapturePixelModel.self, from: data)
Expand Down Expand Up @@ -998,17 +1022,29 @@ open class PIX: NODE, ObservableObject, Equatable {
guard type.typeName == typeName else { continue }
switch type {
case .camera:
#if !os(tvOS)
return CameraPIX(model: pixelModel as! CameraPixelModel)
#else
throw CodingError.badOS
#endif
case .image:
return ImagePIX(model: pixelModel as! ImagePixelModel)
case .vector:
#if !os(tvOS)
return VectorPIX(model: pixelModel as! VectorPixelModel)
#else
throw CodingError.badOS
#endif
case .video:
return VideoPIX(model: pixelModel as! VideoPixelModel)
case .view:
return ViewPIX(model: pixelModel as! ViewPixelModel)
case .web:
#if !os(tvOS)
return WebPIX(model: pixelModel as! WebPixelModel)
#else
throw CodingError.badOS
#endif
case .screenCapture:
#if os(macOS) && !targetEnvironment(macCatalyst)
return ScreenCapturePIX(model: pixelModel as! ScreenCapturePixelModel)
Expand Down
24 changes: 20 additions & 4 deletions Sources/PixelKit/PIX/PIXType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,22 @@ public enum PIXType: Equatable, CaseIterable {
return generator.type.init(at: resolution)
case .resource(let resource):
if resource == .web {
#if !os(tvOS)
return WebPIX(at: resolution)
#else
return nil
#endif
}
if resource == .maps {
return EarthPIX(at: resolution)
}
#if os(iOS) && !targetEnvironment(simulator)
if resource == .paint {
#if os(iOS) && !targetEnvironment(simulator)
return PaintPIX(at: resolution)
#else
return nil
#endif
}
#endif
guard let pix = resource.type?.init() else { return nil }
precondition(pix is NODEResolution == false)
return pix
Expand Down Expand Up @@ -301,22 +307,32 @@ public enum PIXType: Equatable, CaseIterable {
return true
case .resource(let resource):
if resource == .web {
#if !os(tvOS)
guard let webPix = pix as? WebPIX else { return false }
webPix.resolution = resolution
return true
#else
return false
#endif
}
#if os(iOS) && !targetEnvironment(simulator)
if resource == .web {
#if os(iOS) && !targetEnvironment(simulator)
guard let paintPix = pix as? PaintPIX else { return false }
paintPix.resolution = resolution
return true
#else
return false
#endif
}
#endif
if resource == .camera {
#if !os(tvOS)
guard let cameraPix = pix as? CameraPIX else { return false }
guard let cameraResolution = CameraPIX.CameraResolution(resolution: resolution) else { return false }
cameraPix.cameraResolution = cameraResolution
return true
#else
return false
#endif
}
return false
case .sprite:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Created by Anton Heestand on 2021-12-21.
//

#if !os(tvOS)

import Foundation
import CoreGraphics
import RenderKit
Expand Down Expand Up @@ -91,3 +93,4 @@ extension CameraPixelModel {
}
}

#endif

0 comments on commit 60aca53

Please sign in to comment.