Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Clippy Shared/CGImageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
// Clippy
//
// Created by Devran on 08.09.19.
// Updated by JordanE on 01.07.26.
// Copyright © 2019 Devran. All rights reserved.
//

import Foundation
import CoreGraphics

extension CGImage {
static func mergeImages(_ images: [CGImage]) -> CGImage? {
Expand Down
52 changes: 52 additions & 0 deletions Clippy macOS/AgentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// Clippy macOS
//
// Created by Devran on 07.09.19.
// Updated by JordanE on 01.07.26.
// Copyright © 2019 Devran. All rights reserved.
//


import Cocoa
import AVKit
import SpriteKit


class AgentController {
var isMuted = false
var player: AVPlayer = {
Expand All @@ -22,6 +25,17 @@ class AgentController {
var delegate: AgentControllerDelegate?
var isHidden = true

var randomAnimationsEnabled = false {
didSet {
if randomAnimationsEnabled {
scheduleNextRandomAnimation()
} else {
cancelRandomAnimations()
}
}
}
private var randomAnimationTimer: Timer?

init() {
}

Expand All @@ -37,6 +51,10 @@ class AgentController {
self.agent = agent
showInitialFrame()
delegate?.didLoadAgent(agent: agent)

if randomAnimationsEnabled {
scheduleNextRandomAnimation()
}
}

func audioActionForFrame(frame: AgentFrame) -> SKAction? {
Expand Down Expand Up @@ -96,4 +114,38 @@ class AgentController {
func show() {
delegate?.handleShow()
}

private func scheduleNextRandomAnimation() {
cancelRandomAnimations()

let randomInterval = TimeInterval.random(in: 30...300)

randomAnimationTimer = Timer.scheduledTimer(withTimeInterval: randomInterval, repeats: false) { [weak self] _ in
self?.performRandomAnimation()
}
}

private func performRandomAnimation() {
guard randomAnimationsEnabled, !isHidden else {
if randomAnimationsEnabled {
scheduleNextRandomAnimation()
}
return
}

animate()

if randomAnimationsEnabled {
scheduleNextRandomAnimation()
}
}

private func cancelRandomAnimations() {
randomAnimationTimer?.invalidate()
randomAnimationTimer = nil
}

deinit {
cancelRandomAnimations()
}
}
Loading