Skip to content

Commit

Permalink
draft post-27
Browse files Browse the repository at this point in the history
  • Loading branch information
DandyLyons committed Dec 7, 2024
1 parent a0aabf0 commit 7474043
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
# themes/

# Ignore files generated by Hugo
/resources/
/resources/
# Local Netlify folder
.netlify
30 changes: 28 additions & 2 deletions content/en/posts/post-24/Selective Equality Checking in Swift.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ value(person1, isEqualTo: person2, by: \.firstName, \.lastName, \.age)
### How It Works
This solution uses a new Swift 6.0 feature called [Parameter Pack Iteration](https://www.swift.org/blog/pack-iteration/). First we declare that the function receives many types `V`, all of which conform to `Equatable`. Then we accept a pack of `KeyPath` values (notice the `repeat`). Each of these key paths goes from type `T` to `each V`, and each V type will be `Equatable`. Then we iterate through each keypath, and compare the values to each other.

Let's evaluate our function:
1. Pro: Now we can check multiple properties at the same time **even when they are different types**!
>**Note**: For some reason, this feature appears to work for me even when I am using Swift 5 language mode. So even though the blog says that it is a Swift 6 feature, it appears to not require the Swift 6 language mode. Make sure you read my post? "[Am I Using Swift 5 or 6?]({{< ref "Am I Using Swift 5 or 6" >}})" to understand the difference between Swift 6, **the tools** and Swift 6, **the language mode**.
Now, let's evaluate our function again:
1. Pro: Now we can check multiple properties at the same time **even when they are different types**!

### Room For Improvement
Our final function doesn't quite match up to our original API design. Remember we wanted to build something that could be used like this:
Expand All @@ -223,6 +225,30 @@ struct Person: Identifiable {
value(person1, isEqualTo: person2, by: \.firstName, \.lastName, \.age)
```

### Works Great With Reference Types
As we noted before, `Equatable` doesn't quite work for reference types. But our `value(isEqualTo:by:)` function works great with reference types! Look what happens if we change `Person` to a class:

```swift
class Person: Identifiable {
let firstName: String
let lastName: String
let age: Int
let id: UUID
let profileImage: UIImage
}
value(person1, isEqualTo: person2, by: \.firstName, \.lastName, \.age)
```

Here the code works exactly the same. The call site makes it very clear that we are not checking if two `Person` instances are the same instance. Instead we are checking if they have the same values for the same properties.

>**Note:** Don't forget that if we want to check if two class instances are the same instance, we can use the `===` operator like this:
```swift
person1 === person2
```


## Conclusion
Well there you have it, **Selective Equality Checking in Swift**. We can now easily and ergonomically check for equality on select properties and we don't need to conform our types to `Equatable`. Do you like this solution? Grab it for yourself from the [gist](https://gist.github.com/DandyLyons/d19c2b2444db743372fbe9f21d93c98a) here and don't forget to star it!

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: 'Am I Using Swift 5 or 6?'
slug: am-i-using-swift-5-or-6
date: 2024-11-19
topics: ["Swift 6"]
description:
description: What's the difference between the Swift "language modes" and "compiler"? How do I determine which version of Swift I am using? How do I opt in or out of Swift 5 or Swift 6 language mode?
---

Swift is in the middle of a transition from Swift 5 to Swift 6. This transition is not as simple as it may seem. In this post, we will discuss how to determine which version of Swift you are using. But first we need to clear up some misconceptions.
Expand Down
46 changes: 46 additions & 0 deletions content/en/posts/post-27/Godot Tween Deep Dive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 'A Deep Dive Into Godot Engine's Tween System'
slug: godot-tween-deep-dive
date: 2024-11-26
topics: ["Godot", "Game Development"]
description:
draft: true
---

Godot Engine's Tween system is a powerful tool for creating animations and interpolations in your games. In this article, we'll take a deep dive into how the Tween system works and how you can use it to create complex animations and effects in your games.

## The Many "Animation" Systems in Godot
What is animation? In the early 1900s Walt Disney brought animation to a mainstream audience. By drawing a series of still images and playing them back in rapid succession, Disney was able to create the illusion of smooth change over time. This is the essence of animation: creating the illusion of smooth change.

In game development, we are essentially doing the same process. The biggest difference however is that, typically, we are not drawing the frames ourselves. Instead, the game engine is responsible for rendering the frames for us. Instead, we are responsible for telling the game engine how to change the objects in our game.

The Godot game engine has several systems that allow you to create animations in your games. These include:
- The AnimationPlayer system
- The Tween system
- The Physics system

## Choosing The Right Animation System: When To Use The Tween System


## How The Tween System Works
Any time you learn a new API, it's important to understand the life cycle of the system. In particular you should seek to answer the following questions:
- What are the fundamental concepts that the API expects me to understand?
- How do you create a new instance of the system?
- Who is responsible for creating the instance?
- What are the various states that the system can be in?
- How do you transition between these states?
- How do you destroy an instance of the system?
- Who is responsible for destroying the instance?

### Fundamental Concepts of the Tween System


### The Life Cycle And States of a Tween

#### Pausing Tweens

#### Stopping Tweens

#### Killing Tweens

## Putting It All Together: Creating Complex Animations With The Tween System

0 comments on commit 7474043

Please sign in to comment.