Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing VortexSystem.Settings #29

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

disc0infern0
Copy link
Contributor

This commit looks large, but is essentially just an abstraction of the configuration settings from the VortexSystem into it's own Settings class, with those properties replaced in VortexSystem with a single property; vortexSettings.

The changes are documented in a the updated README. Settings enables an intuitive initialisation based on preset settings, enables autocomplete for each setting (rather than relying on specifying the required parameters of the init, and getting them all in the right order), and removes the need to ever call .makeUniqueCopy.

The change necessitates changes to VortexSystem of course, but also the VortexSystem-Behaviour to ensure that the configuration settings are accessed via vortexSettings. (dynamicLookup is also added to VortexSystem for convenience).

Included here are also changes to four presets, Confetti, Fire, Fireflies and Fireworks, showing how the settings would be used for each. (A new full width Fire preview is also included showing how preset settings can be tweaked). The others remain (at least for now) with the previous VortexSystem method of initialisation.
Changing the remainder of the presets would take a matter of moments, however I did not want to update too many files at once! (In the interim, some deprecation warnings will be generated by the compiler - see below)

Because of the changes, and in particular because secondary systems are now secondary settings, this could have been a breaking change. However in the interests of backward compatibility, the old inits have been preserved, although they are now marked as deprecated.
This will show warnings in the code, but everything will continue to work.

It is evisaged that after a suitable time, agreed by Paul, the deprecated inits could be removed, and some further code cleanup completed. One such change would be modifying the init of the VortexView to accept a Settings struct as an anonymous parameter, so that VortexView(.confetti) would call the VortexSystem.Settings.confetti preset, rather than the current VortexSystem.confetti preset, which would be removed.

This commit looks large, but is essentially just an abstraction of the configuration settings from the VortexSystem into it's own Settings class, with those properties replaced in VortexSystem with a single property; vortexSettings.
The changes are documented in an the updated README.
Settings enables an intuitive initialisation based on preset settings, enables autocomplete for each setting (rather than relying on specifying the required parameters of the init, and getting them all in the right order), and removes the need to ever call `.makeUniqueCopy`.

The change necessitates changes to VortexSystem of course, but also the VortexSystem behaviour to ensure that the configuration settings are accessed via vortexSettings. (dynamicLookup is also added for convenience).
Included here are also changes to four presets, Confetti, Fire, Fireflies and Fireworks, showing how the settings would be used for each. The others remain (at least for now) with the previous VortexSystem method of initialisation.
Changing the remainder of the presets would take a matter of moments, however I did not want to update too many files at once! (in the interim, some deprecation warnings will be generated by the compiler - see below)

Because of the changes, and in particular because secondary systems are now secondary settings, this could have been a breaking change. However in the interests of backward compatibility, the old inits have been preserved, although they are now marked as deprecated.
This will show warnings in the code, but everything will continue to work.
It is evisaged that after a suitable time, agreed by Paul, the deprecated inits could be removed, and some further code cleanup completed. One such change would be modifying  the init of the VortexView to accept a Settings struct as an anonymous parameter, so that
`VortexView(.confetti)` would call the `VortexSystem.Settings.confetti` preset, rather than the current `VortexSystem.confetti` preset, which would be removed.
@disc0infern0
Copy link
Contributor Author

Whether position is a configuration setting or not is a debatable point, because it is a property that gets modified by the 'moveTo' method in the proxy. Configuration parameters should arguably be unmodifiable. One could certainly argue that initialPosition could be a valid configuration setting, and it would then require a separate position property to be held and initialised within VortexSystem. No changes have been made in this regard.

/// ```
public init(
from base: VortexSystem.Settings = VortexSystem.Settings(),
_ modifiedBy: @escaping (_: inout VortexSystem.Settings) -> Void
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd shape for an initializer. What does it offer over code like this:

var settings = VortexSystem.Settings(from: .fire)
settings.idleDuration = 3
settings.angle = .whatever

}

/// The configuration settings for a VortexSystem
var vortexSettings: VortexSystem.Settings
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

README.md Outdated
.tag("circle")
struct ContentView: View {
var body: some View {
let fireSettings = VortexSystem.Settings(from: .fire ) { settings in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's generally not a good idea to mix up logic and layout in the body property, so I think for the README it might be a better idea to pull this settings object out into its own property.

/// - symbols: A closure that should return a tagged group of SwiftUI views to use as particles.
/// If not specified, a default group of three views tagged with `.circle`,`.confetti` and `.sparkle` will be used.
public init(
settings: VortexSystem.Settings = .init(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably use _ settings so that we get VortexView(.confetti). I'd be happy to rename the older one and mark it deprecated if it's causing confusion, but I want the newer, correct option to be the simplest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

targetFrameRate: Int = 60,
@ViewBuilder symbols: () -> Symbols = {
Group {
Image.circle
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the problem this is trying to solve, but I'm not sure it's really that practical – using images rather than shapes has a significant performance impact, and each system uses different variations. For example, .confetti adds a square shape and doesn't use plus lighter, .rain uses 32-point circles without plus lighter, fire adds a blur over 32-point circle, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove prebuilt symbols from the view init, and from any previews.


import SwiftUI

extension VortexSystem {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to move this whole struct outside VortexSystem and just call it VortexSettings; it's a bit wordy as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.

@twostraws
Copy link
Owner

Thank you for this! Broadly it looks fine, but I've added various notes and questions around the code.

Changing the remainder of the presets would take a matter of moments, however I did not want to update too many files at once! (In the interim, some deprecation warnings will be generated by the compiler - see below)

There are two independent things in this pull request, which is complicatings things slightly – the move to separate settings, and trying to share tagged particle views. The former seems very good; the latter I'm really not sure about.

Because of the changes, and in particular because secondary systems are now secondary settings, this could have been a breaking change. However in the interests of backward compatibility, the old inits have been preserved, although they are now marked as deprecated. This will show warnings in the code, but everything will continue to work.

Vortex already has a v1 tagged, so we could release a v2 with breaking changes just fine. I'd prefer to remove old code entirely rather than issuing deprecation warnings, or at least make the new approach the easier approach.

Whether position is a configuration setting or not is a debatable point, because it is a property that gets modified by the 'moveTo' method in the proxy. Configuration parameters should arguably be unmodifiable. One could certainly argue that initialPosition could be a valid configuration setting, and it would then require a separate position property to be held and initialised within VortexSystem. No changes have been made in this regard.

Why should configuration parameters be unmodifiable? If someone wants confetti rate to start fast then slow down, wants to make particle bursts grow in size each time a burst is created, or wants to make the angle move constantly like a sweeping motion, all those seem reasonable.

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 7, 2024 via email

@disc0infern0
Copy link
Contributor Author

disc0infern0 commented Dec 8, 2024 via email

disc0infern0 and others added 6 commits December 9, 2024 00:31
This commit is essentially  an abstraction of the configuration settings from the VortexSystem into it's own VortexSettings type, with those properties replaced in VortexSystem with a single property; settings. (Prebuilt/default symbols have been removed from the previous PR).
The changes are documented in an the updated README.
Settings enables an intuitive initialisation based on preset settings. Using type ahead, it enables  discovery of each setting, and does not  rely on specifying all the required parameters of the init, and getting them all in the right order, It also removes the need to ever call `.makeUniqueCopy`.

The change necessitates changes to VortexSystem of course, but also the VortexProxy, ViewReader and VortexSystem-Behaviour to ensure that the configuration settings are correctly accessed via settings. (dynamicLookup is also added to VortexSystem for convenience).
This commit is essentially  an abstraction of the configuration settings from the VortexSystem into it's own VortexSettings type, with those properties replaced in VortexSystem with a single property; settings. (Prebuilt/default symbols have been removed from the previous PR).
The changes are documented in an the updated README.
Settings enables an intuitive initialisation based on preset settings. Using type ahead, it enables  discovery of each setting, and does not  rely on specifying all the required parameters of the init, and getting them all in the right order, It also removes the need to ever call `.makeUniqueCopy`.

The change necessitates changes to VortexSystem of course, but also the VortexProxy, ViewReader and VortexSystem-Behaviour to ensure that the configuration settings are correctly accessed via settings. (dynamicLookup is also added to VortexSystem for convenience).
#Conflicts:
#	Sources/Vortex/Presets/Fire.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants