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

New Icons, Various other changes #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
22 changes: 20 additions & 2 deletions Ball.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
181A7D392C301E3A009240B0 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 181A7D382C301E3A009240B0 /* Settings.bundle */; };
181A7D3E2C317CC2009240B0 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181A7D3D2C317CC2009240B0 /* PreferencesViewController.swift */; };
5F4617B5297E1747005A09A6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4617B4297E1747005A09A6 /* AppDelegate.swift */; };
5F4617B7297E1747005A09A6 /* BallViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4617B6297E1747005A09A6 /* BallViewController.swift */; };
5F4617B9297E1748005A09A6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F4617B8297E1748005A09A6 /* Assets.xcassets */; };
Expand All @@ -29,6 +31,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
181A7D382C301E3A009240B0 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
181A7D3B2C301F26009240B0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
181A7D3D2C317CC2009240B0 /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
5F4617B1297E1747005A09A6 /* Ball.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Ball.app; sourceTree = BUILT_PRODUCTS_DIR; };
5F4617B4297E1747005A09A6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5F4617B6297E1747005A09A6 /* BallViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -64,6 +69,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
181A7D3C2C317C79009240B0 /* Preferences */ = {
isa = PBXGroup;
children = (
181A7D3D2C317CC2009240B0 /* PreferencesViewController.swift */,
);
path = Preferences;
sourceTree = "<group>";
};
5F4617A8297E1747005A09A6 = {
isa = PBXGroup;
children = (
Expand All @@ -83,6 +96,7 @@
5F4617B3297E1747005A09A6 /* Ball */ = {
isa = PBXGroup;
children = (
181A7D3C2C317C79009240B0 /* Preferences */,
5F4617C5297E2B8F005A09A6 /* Info.plist */,
5F4617B4297E1747005A09A6 /* AppDelegate.swift */,
5F4617D7297F6BFD005A09A6 /* AppController.swift */,
Expand All @@ -103,6 +117,7 @@
5F4617B8297E1748005A09A6 /* Assets.xcassets */,
5F4617BA297E1748005A09A6 /* Main.storyboard */,
5F4617BD297E1748005A09A6 /* Ball.entitlements */,
181A7D382C301E3A009240B0 /* Settings.bundle */,
);
path = Ball;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,6 +192,7 @@
5F4617E2297F8FA3005A09A6 /* pop_02.caf in Resources */,
5F4617BC297E1748005A09A6 /* Main.storyboard in Resources */,
5F4617E6297F9012005A09A6 /* pop_03.caf in Resources */,
181A7D392C301E3A009240B0 /* Settings.bundle in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -192,6 +208,7 @@
5F4617C7297E2C03005A09A6 /* DockUtils.swift in Sources */,
5F736CA5298214FE00997B93 /* InnerShadow.swift in Sources */,
5F4617D8297F6BFD005A09A6 /* AppController.swift in Sources */,
181A7D3E2C317CC2009240B0 /* PreferencesViewController.swift in Sources */,
5F4617B7297E1747005A09A6 /* BallViewController.swift in Sources */,
5F4617DA297F6E59005A09A6 /* MouseCatcherView.swift in Sources */,
5F4617C4297E17D8005A09A6 /* BallWindowController.swift in Sources */,
Expand All @@ -209,6 +226,7 @@
isa = PBXVariantGroup;
children = (
5F4617BB297E1748005A09A6 /* Base */,
181A7D3B2C301F26009240B0 /* en */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -338,7 +356,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VPN8ZW6EAC;
DEVELOPMENT_TEAM = N3296KDPFX;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Ball/Info.plist;
Expand Down Expand Up @@ -366,7 +384,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = VPN8ZW6EAC;
DEVELOPMENT_TEAM = N3296KDPFX;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Ball/Info.plist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"location" : "https://github.com/b3ll/Motion",
"state" : {
"branch" : "main",
"revision" : "6c9cd2a27b36483a8774370d382706257b6dfad1"
"revision" : "c9a57f9d2b9d0a1e1b905753175e75a422d381d5"
}
},
{
Expand Down
27 changes: 26 additions & 1 deletion Ball/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,33 @@ import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate {

private var prefsWindowController: NSWindowController?

let appController = AppController()

@IBAction func showAbout(_ sender: Any) {
NSLog("about clicky")
NSApp.activate(ignoringOtherApps: true)
NSApp.orderFrontStandardAboutPanel(
options: [NSApplication.AboutPanelOptionKey.credits: NSAttributedString(
string: "Created by Nate Parrot\nhttps://nateparrot.com\n",
attributes: [
NSAttributedString.Key.font: NSFont.boldSystemFont(
ofSize: NSFont.smallSystemFontSize),
]
)
]
)
}

@IBAction func openPreferences(_ sender: Any) {
if prefsWindowController == nil {
prefsWindowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "PreferencesWindowController") as? NSWindowController
}
NSApp.activate(ignoringOtherApps: true)
prefsWindowController?.showWindow(self)
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
Expand All @@ -29,4 +55,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
return true
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Ball/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"size" : "256x256"
},
{
"filename" : "Red (1).png",
"filename" : "AppIcon.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
Expand Down
Binary file removed Ball/Assets.xcassets/Ball.imageset/Red (1).png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Ball/Assets.xcassets/Balls/Blue.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Blue (1).png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Ball/Assets.xcassets/Balls/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
21 changes: 21 additions & 0 deletions Ball/Assets.xcassets/Balls/Green.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Green (1).png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Ball/Assets.xcassets/PutBack.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scale" : "1x"
},
{
"filename" : "putback (1).png",
"filename" : "PutBack.png",
"idiom" : "universal",
"scale" : "2x"
},
Expand Down
Binary file added Ball/Assets.xcassets/PutBack.imageset/PutBack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
24 changes: 5 additions & 19 deletions Ball/Ball.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class Ball: SKNode {

private let imgOffsetContainer = SKNode()
/**/ private let imgRotationContainer = SKNode()
/****/ private let img = SKSpriteNode(imageNamed: "Ball")
private let ballColour = UserDefaults.standard.string(forKey: "selectedBallColour")
private var img: SKSpriteNode

let radius: CGFloat

// let view: NSHostingView<BallView<Circle>>
private let shadowSprite = SKSpriteNode(imageNamed: "ContactShadow")
private let shadowContainer = SKNode() // For fading in/out

Expand All @@ -25,8 +25,8 @@ class Ball: SKNode {
}

init(radius: CGFloat, pos: CGPoint, id: String) {
// self.view = NSHostingView(rootView: BallView(shape: Circle(), radius: radius, color: Color(hex: 0xF84E35)))
// self.view.frame = CGRect(x: 0, y: 0, width: radius * 2, height: radius * 2)
img = SKSpriteNode(imageNamed: ballColour!)

self.id = id
self.radius = radius
super.init()
Expand All @@ -52,7 +52,6 @@ class Ball: SKNode {

img.size = CGSize(width: radius * 2, height: radius * 2)
imgRotationContainer.addChild(img)
// img.alpha = 0.01
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -72,7 +71,7 @@ class Ball: SKNode {
}

func update() {
shadowSprite.position = CGPoint(x: 0, y: radius * 0.3 - position.y)
shadowSprite.position = CGPoint(x: 0, y: (radius * 0.3) - position.y)
let distFromBottom = position.y - radius
shadowSprite.alpha = remap(x: distFromBottom, domainStart: 0, domainEnd: 200, rangeStart: 1, rangeEnd: 0)
imgRotationContainer.xScale = squish.value
Expand All @@ -83,17 +82,4 @@ class Ball: SKNode {
img.setScale(dragScale.value)
}

func didCollide(strength: Double, normal: CGVector) {
let angle = atan2(normal.dy, normal.dx)
imgRotationContainer.zRotation = angle
img.zRotation = -angle

let targetScale = remap(x: strength, domainStart: 0, domainEnd: 1, rangeStart: 1, rangeEnd: 0.8)
let velocity = remap(x: strength, domainStart: 0, domainEnd: 1, rangeStart: -5, rangeEnd: -10)
// squish.animate(toValue: targetScale, velocity: velocity, completion: nil)

// DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
// self.squish.animate(toValue: 1, velocity: self.squish.velocity, completion: nil)
// }
}
}
35 changes: 20 additions & 15 deletions Ball/BallViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class BallViewController: NSViewController {

let scene = SKScene(size: .init(width: 200, height: 200))
let sceneView = SKView()

var ballSize: CGFloat = 1.0

let collisionSounds: [NSSound] = ["pop_01", "pop_02", "pop_03"].map { id in
NSSound(contentsOf: Bundle.main.url(forResource: id, withExtension: "caf")!, byReference: true)!
Expand All @@ -29,10 +31,8 @@ class BallViewController: NSViewController {
didSet(old) {
old?.removeFromParent()
old?.physicsBody = nil
// old?.view.removeFromSuperview()
if let ball {
scene.addChild(ball)
// view.addSubview(ball.view)
}
}
}
Expand All @@ -53,6 +53,8 @@ class BallViewController: NSViewController {
sound.volume = 0
sound.play() // Ensure ready to play
}

ballSize = CGFloat(UserDefaults.standard.float(forKey: "ballSize")/100)
}


Expand Down Expand Up @@ -157,12 +159,16 @@ class BallViewController: NSViewController {
guard let screen = self.view.window?.screen else { return }
var targetRect = rect
targetRect = targetRect.byConstraining(withinBounds: screen.frame)

let ball = Ball(radius: Constants.radius, pos: .init(x: targetRect.midX, y: targetRect.midY), id: UUID().uuidString)

// we need to reload this here
ballSize = CGFloat(UserDefaults.standard.float(forKey: "ballSize")/100)
let ballRadius = Constants.radius * ballSize
NSLog("ballRadius: %f", ballRadius)
NSLog("ballSize: %f", ballSize)
let ball = Ball(radius: ballRadius, pos: .init(x: targetRect.midX, y: targetRect.midY), id: UUID().uuidString)
self.ball = ball

dragState = nil
// self.ball?.position = CGPoint(x: targetRect.midX, y: targetRect.midY)

// Add impulse to fling ball to center of screen
let strength: CGFloat = 2000
Expand All @@ -182,7 +188,6 @@ class BallViewController: NSViewController {
ball.setScale(rect.width / (ball.radius * 2))
let scaleUp = SKAction.scale(to: 1, duration: 0.5)
ball.run(scaleUp)
// ball.physicsBody?.applyImpulse(impulse)

ball.animateShadow(visible: true, duration: 0.5)

Expand Down Expand Up @@ -234,7 +239,6 @@ extension BallViewController: SKSceneDelegate {
func didFinishUpdate(for scene: SKScene) {
if let ball {
ball.update()
// ball.view.setCenter(CGPoint(x: ball.position.x, y: ball.position.y))
}
}
}
Expand All @@ -253,16 +257,17 @@ extension BallViewController: SKPhysicsContactDelegate {
let collisionStrength = remap(x: contact.collisionImpulse, domainStart: minImpulse, domainEnd: maxImpulse, rangeStart: 0, rangeEnd: 0.5)
guard collisionStrength > 0 else { return }

ball?.didCollide(strength: collisionStrength, normal: contact.contactNormal)

DispatchQueue.global().async {
var sounds = self.collisionSounds
sounds.shuffle()
guard let soundToUse = sounds.first(where: { !$0.isPlaying }) else {
return
if UserDefaults.standard.bool(forKey: "enableDisableSound") {
DispatchQueue.global().async {
var sounds = self.collisionSounds
sounds.shuffle()
guard let soundToUse = sounds.first(where: { !$0.isPlaying }) else {
return
}
soundToUse.volume = Float(collisionStrength)
soundToUse.play()
}
soundToUse.volume = Float(collisionStrength)
soundToUse.play()
}
}
}
Expand Down
Loading