a
230
Cube4Fun/Animations.swift
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
//
|
||||||
|
// Animations.swift
|
||||||
|
// Cube4Fun
|
||||||
|
//
|
||||||
|
// Created by Nik on 07.04.15.
|
||||||
|
// Copyright (c) 2015 DerNik. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
let AnimName = "AnimName"
|
||||||
|
let AnimKey = "AnimKey"
|
||||||
|
let AnimDuration = "AnimDur"
|
||||||
|
let AnimSpeed = "AnimSpeed"
|
||||||
|
let AnimFrames = "AnimData"
|
||||||
|
|
||||||
|
class Animations: NSObject {
|
||||||
|
|
||||||
|
let _emptyFrame: [UInt8] = [
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255,
|
||||||
|
255,255,255,255]
|
||||||
|
|
||||||
|
var _displayedFrame: Int = 1;
|
||||||
|
// var _frameCount: UInt32 = 1;
|
||||||
|
// var _oneFrame: NSMutableData = NSMutableData() // == byte[] array
|
||||||
|
// var _emptyAnimation: NSMutableDictionary = NSMutableDictionary()
|
||||||
|
var _animationArray: [NSMutableDictionary] = [NSMutableDictionary]()
|
||||||
|
var _animationSelected: Int = 0
|
||||||
|
let _minSendDelay: NSTimeInterval = 0.200 // fastes speed 200 milliseconds
|
||||||
|
let maxFrameSpeed = 3000 // the lowest possible speed allowed
|
||||||
|
let minFrameSpeed = 200 // the fastest possible speed allowed
|
||||||
|
let frameSpeedStep = 100 // how fast increase or decrease speed
|
||||||
|
// var _playSendDelay: NSTimeInterval = 0.5 // 500 milliseconds as default
|
||||||
|
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
// Show the first frame
|
||||||
|
_displayedFrame = 1
|
||||||
|
// Append empty animation
|
||||||
|
self.addAnimation()
|
||||||
|
// Set visible animation
|
||||||
|
_animationSelected = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// How much animations do we have
|
||||||
|
func count() -> (Int) {
|
||||||
|
return _animationArray.count
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimation(id: Int) -> (NSDictionary) {
|
||||||
|
let myAnimation = _animationArray[id] as NSDictionary
|
||||||
|
return myAnimation
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimationName(id: Int) -> (String) {
|
||||||
|
let value = (self.getAnimation(id)).objectForKey(AnimName) as! String
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
func setAnimationName(id: Int, value: String) {
|
||||||
|
(self.getAnimation(id)).setValue(value, forKey: AnimName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimationKey(id: Int) -> (String) {
|
||||||
|
let value = (self.getAnimation(id)).objectForKey(AnimKey) as! String
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
func setAnimationKey(id: Int, value: String) {
|
||||||
|
(self.getAnimation(id)).setValue(value, forKey: AnimKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimationDuration(id: Int) -> (Int) {
|
||||||
|
let value = (self.getAnimation(id)).objectForKey(AnimDuration) as! Int
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
func setAnimationDuration(id: Int, value: Int) {
|
||||||
|
(self.getAnimation(id)).setValue(value, forKey: AnimDuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimationSpeed(id: Int) -> (Int) {
|
||||||
|
let value = (self.getAnimation(id)).objectForKey(AnimSpeed) as! Int
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
func setAnimationSpeed(id: Int, value: Int) {
|
||||||
|
(self.getAnimation(id)).setValue(value, forKey: AnimSpeed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimationFrameCount() -> (Int) {
|
||||||
|
return self.getAnimationFrameCount(_animationSelected)
|
||||||
|
}
|
||||||
|
func getAnimationFrameCount(id: Int) -> (Int) {
|
||||||
|
let myFrames: NSMutableData = (self.getAnimation(id)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
return myFrames.length / 64
|
||||||
|
//let value = (self.getAnimation(id)).objectForKey("AnimFrames") as Int
|
||||||
|
//return value
|
||||||
|
}
|
||||||
|
func getAnimationFrameID() -> Int {
|
||||||
|
return _displayedFrame
|
||||||
|
}
|
||||||
|
func setAnimationFrameID(id: Int) {
|
||||||
|
_displayedFrame = id
|
||||||
|
}
|
||||||
|
|
||||||
|
func setSelectedAnimationID(id: Int) {
|
||||||
|
if id >= 0 {
|
||||||
|
_animationSelected = id
|
||||||
|
_displayedFrame = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func getSelectedAnimationID() -> (Int) {
|
||||||
|
return _animationSelected
|
||||||
|
}
|
||||||
|
func deleteSelected() {
|
||||||
|
_animationArray.removeAtIndex(_animationSelected)
|
||||||
|
if ( _animationSelected == 0 && _animationArray.count == 0 ) { // last Frame
|
||||||
|
self.addAnimation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func moveUpSelected() {
|
||||||
|
if ( _animationSelected > 0 ) {
|
||||||
|
_animationArray.insert(_animationArray[_animationSelected], atIndex: _animationSelected-1)
|
||||||
|
_animationArray.removeAtIndex(_animationSelected+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func moveDownSelected() {
|
||||||
|
if (_animationSelected < _animationArray.count - 1) {
|
||||||
|
_animationArray.insert(_animationArray[_animationSelected+1], atIndex: _animationSelected)
|
||||||
|
_animationArray.removeAtIndex(_animationSelected+2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAnimation() {
|
||||||
|
_animationArray.append(self.newAnimation())
|
||||||
|
println("append Animation count: \(_animationArray.count)")
|
||||||
|
}
|
||||||
|
func newAnimation() -> (NSMutableDictionary) {
|
||||||
|
println("create new animation")
|
||||||
|
return [AnimName: "Animation1", AnimKey: "1=anim1", AnimDuration: 1, AnimSpeed: 500, AnimFrames: self.newFrame()]
|
||||||
|
}
|
||||||
|
func newFrame() -> (NSMutableData) {
|
||||||
|
println("create new frame")
|
||||||
|
return NSMutableData(bytes: _emptyFrame, length: 64)
|
||||||
|
}
|
||||||
|
func addFrame() {
|
||||||
|
let myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
myData.appendBytes(_emptyFrame, length: 64)
|
||||||
|
}
|
||||||
|
func removeFrame() {
|
||||||
|
if self.getAnimationFrameCount() > 1 {
|
||||||
|
let myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
let myLength = myData.length
|
||||||
|
myData.length = myLength - 64 // remove one frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func animationSpeedInt() -> Int {
|
||||||
|
let frameSpeed: Int = (self.getAnimation(_animationSelected)).objectForKey(AnimSpeed) as! Int
|
||||||
|
return frameSpeed
|
||||||
|
}
|
||||||
|
func animationSpeedFloat() -> NSTimeInterval {
|
||||||
|
let frameSpeed: Int = (self.getAnimation(_animationSelected)).objectForKey(AnimSpeed) as! Int
|
||||||
|
let mySpeed: NSTimeInterval = NSTimeInterval(Float(frameSpeed)/1000)
|
||||||
|
return mySpeed
|
||||||
|
}
|
||||||
|
func increaseSpeed() {
|
||||||
|
let frameSpeed: Int = (self.getAnimation(_animationSelected)).objectForKey(AnimSpeed) as! Int
|
||||||
|
if frameSpeed < maxFrameSpeed {
|
||||||
|
(self.getAnimation(_animationSelected)).setValue(frameSpeed+frameSpeedStep, forKey: AnimSpeed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func decreaseSpeed() {
|
||||||
|
let frameSpeed: Int = (self.getAnimation(_animationSelected)).objectForKey(AnimSpeed) as! Int
|
||||||
|
if frameSpeed > minFrameSpeed {
|
||||||
|
(self.getAnimation(_animationSelected)).setValue(frameSpeed-frameSpeedStep, forKey: AnimSpeed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gotoLastFrame() {
|
||||||
|
self.setAnimationFrameID(self.getAnimationFrameCount())
|
||||||
|
}
|
||||||
|
func gotoFirstFrame() {
|
||||||
|
self.setAnimationFrameID(1)
|
||||||
|
}
|
||||||
|
func gotoNextFrame() {
|
||||||
|
if self.getAnimationFrameID() < self.getAnimationFrameCount() {
|
||||||
|
self.setAnimationFrameID(self.getAnimationFrameID()+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func gotoPrevFrame() {
|
||||||
|
if self.getAnimationFrameID() > 1 {
|
||||||
|
self.setAnimationFrameID(self.getAnimationFrameID()-1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func getMinSendDelay() -> (NSTimeInterval) {
|
||||||
|
return _minSendDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAnimData() -> (UnsafePointer<UInt8>) {
|
||||||
|
let myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
let byteArray = UnsafePointer<UInt8>(myData.bytes)
|
||||||
|
return byteArray
|
||||||
|
}
|
||||||
|
|
||||||
|
func setLEDColor(color: UInt8, led: Int) {
|
||||||
|
var myByte: [UInt8] = [color]
|
||||||
|
let myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
myData.replaceBytesInRange(NSMakeRange(((self.getAnimationFrameID()-1)*64)+led, 1), withBytes: myByte)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearLEDColor() {
|
||||||
|
var myByte: [UInt8] = [255]
|
||||||
|
let myData: NSMutableData = (self.getAnimation(_animationSelected)).objectForKey(AnimFrames) as! NSMutableData
|
||||||
|
myData.replaceBytesInRange(NSMakeRange((self.getAnimationFrameID()-1)*64, 64), withBytes: _emptyFrame)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
//let _emptyAnimation: NSMutableDictionary = ["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 1]
|
//let _emptyAnimation: NSMutableDictionary = ["AnimName": "Animation1", "AnimKey": "1=anim1", "AnimDur": 1, "AnimSpeed": 500, "AnimFrames": 1]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -21,48 +20,47 @@ var dataArray: [NSMutableDictionary] = [["AnimName": "Animation1", "AnimKey": "1
|
|||||||
["AnimName": "Animation6", "AnimKey": "1=anim6", "AnimDur": 2, "AnimSpeed": 1000, "AnimFrames": 52]];
|
["AnimName": "Animation6", "AnimKey": "1=anim6", "AnimDur": 2, "AnimSpeed": 1000, "AnimFrames": 52]];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var _animationArray: [NSMutableDictionary] = [NSMutableDictionary]();
|
//var _animationArray: [NSMutableDictionary] = [NSMutableDictionary]();
|
||||||
|
//var _selectedAnimation: Int = 0;
|
||||||
|
|
||||||
|
|
||||||
class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
|
class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate {
|
||||||
|
|
||||||
@IBOutlet weak var myTableView: NSTableView!
|
@IBOutlet weak var myTableView: NSTableView!
|
||||||
|
|
||||||
var _selectedRow: Int = -1
|
|
||||||
|
|
||||||
override func awakeFromNib() {
|
|
||||||
_animationArray.append(_emptyAnimation)
|
|
||||||
}
|
|
||||||
|
|
||||||
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
|
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
|
||||||
let numberOfRows:Int = _animationArray.count
|
let numberOfRows:Int = __animations.count() // _animationArray.count
|
||||||
return numberOfRows
|
return numberOfRows
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
|
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
|
||||||
//println("Display: \(row)")
|
//let object: NSDictionary = __animations.getAnimation(row) //_animationArray[row] as NSDictionary
|
||||||
let object: NSDictionary = _animationArray[row] as NSDictionary
|
|
||||||
//println(object)
|
//println(object)
|
||||||
let column: String = tableColumn?.identifier as String!
|
let column: String = tableColumn?.identifier as String!
|
||||||
if column == "AnimName" {
|
if column == "AnimName" {
|
||||||
let value = object.objectForKey(column) as String
|
return __animations.getAnimationName(row)
|
||||||
return value
|
//let value = object.objectForKey(column) as String
|
||||||
|
//return value
|
||||||
}
|
}
|
||||||
if column == "AnimKey" {
|
if column == "AnimKey" {
|
||||||
let value = object.objectForKey(column) as String
|
return __animations.getAnimationKey(row)
|
||||||
return value
|
//let value = object.objectForKey(column) as String
|
||||||
|
//return value
|
||||||
}
|
}
|
||||||
if column == "AnimDur" {
|
if column == "AnimDur" {
|
||||||
let value = object.objectForKey(column) as Int
|
return __animations.getAnimationDuration(row)
|
||||||
return value
|
//let value = object.objectForKey(column) as Int
|
||||||
|
//return value
|
||||||
}
|
}
|
||||||
if column == "AnimSpeed" {
|
if column == "AnimSpeed" {
|
||||||
let value = object.objectForKey(column) as Int
|
return __animations.getAnimationSpeed(row)
|
||||||
return value
|
//let value = object.objectForKey(column) as Int
|
||||||
|
//return value
|
||||||
}
|
}
|
||||||
if column == "AnimFrames" {
|
if column == "AnimFrames" {
|
||||||
let value = object.objectForKey(column) as Int
|
return __animations.getAnimationFrameCount(row)
|
||||||
return value
|
//let value = object.objectForKey(column) as Int
|
||||||
|
//return value
|
||||||
}
|
}
|
||||||
|
|
||||||
return column
|
return column
|
||||||
@@ -70,8 +68,15 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
|
|||||||
|
|
||||||
|
|
||||||
func tableViewSelectionDidChange(notification: NSNotification) {
|
func tableViewSelectionDidChange(notification: NSNotification) {
|
||||||
let view: NSTableView = notification.object as NSTableView
|
let view: NSTableView = notification.object as! NSTableView
|
||||||
_selectedRow = view.selectedRow
|
__animations.setSelectedAnimationID(view.selectedRow)
|
||||||
|
|
||||||
|
_gameView.resetView()
|
||||||
|
//let myCubeController: GameViewController = _animationsWindow.contentViewController as! GameViewController
|
||||||
|
//let myCubeView: GameView = myCubeController.view as! GameView
|
||||||
|
//myCubeView.resetView()
|
||||||
|
|
||||||
|
//_selectedAnimation = view.selectedRow
|
||||||
|
|
||||||
//println("klicked \(view.selectedRow)")
|
//println("klicked \(view.selectedRow)")
|
||||||
}
|
}
|
||||||
@@ -80,54 +85,54 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
|
|||||||
let column: String = tableColumn?.identifier as String!
|
let column: String = tableColumn?.identifier as String!
|
||||||
//println("Object: \(object) Key: \((tableColumn?.identifier)!)" )
|
//println("Object: \(object) Key: \((tableColumn?.identifier)!)" )
|
||||||
|
|
||||||
let value = object! as NSString
|
let value = object! as! NSString
|
||||||
if column == "AnimName" {
|
if column == "AnimName" {
|
||||||
_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
|
__animations.setAnimationName(row, value: value as String)
|
||||||
|
//_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
|
||||||
}
|
}
|
||||||
if column == "AnimKey" {
|
if column == "AnimKey" {
|
||||||
_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
|
__animations.setAnimationKey(row, value: value as String)
|
||||||
|
//_animationArray[row].setObject(value, forKey: (tableColumn?.identifier)!)
|
||||||
}
|
}
|
||||||
if column == "AnimDur" {
|
if column == "AnimDur" {
|
||||||
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
__animations.setAnimationDuration(row, value: value.integerValue)
|
||||||
|
//_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
||||||
}
|
}
|
||||||
if column == "AnimSpeed" {
|
if column == "AnimSpeed" {
|
||||||
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
__animations.setAnimationSpeed(row, value: value.integerValue)
|
||||||
}
|
//_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
||||||
if column == "AnimFrames" {
|
|
||||||
_animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_gameView.resetView()
|
||||||
|
|
||||||
|
//if column == "AnimFrames" {
|
||||||
|
// _animationArray[row].setObject(value.integerValue, forKey: (tableColumn?.identifier)!)
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func addNewAnimation(sender: AnyObject) {
|
@IBAction func addNewAnimation(sender: AnyObject) {
|
||||||
_animationArray.append(_emptyAnimation)
|
__animations.addAnimation()
|
||||||
myTableView.reloadData()
|
myTableView.reloadData()
|
||||||
// println("Adding new Item")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func delNewAnimation(sender: AnyObject) {
|
@IBAction func delNewAnimation(sender: AnyObject) {
|
||||||
if ( _selectedRow >= 0 ) {
|
__animations.deleteSelected()
|
||||||
_animationArray.removeAtIndex(_selectedRow)
|
|
||||||
myTableView.reloadData()
|
myTableView.reloadData()
|
||||||
}
|
}
|
||||||
// println("Deleting selected Item")
|
|
||||||
}
|
|
||||||
|
|
||||||
@IBAction func moveUpItem(send: AnyObject) {
|
@IBAction func moveUpItem(send: AnyObject) {
|
||||||
if ( _selectedRow > 0 ) {
|
if ( __animations.getSelectedAnimationID() > 0 ) {
|
||||||
_animationArray.insert(_animationArray[_selectedRow], atIndex: _selectedRow-1)
|
__animations.moveUpSelected()
|
||||||
_animationArray.removeAtIndex(_selectedRow+1)
|
|
||||||
myTableView.reloadData()
|
myTableView.reloadData()
|
||||||
myTableView.selectRowIndexes(NSIndexSet(index: _selectedRow-1), byExtendingSelection: false)
|
myTableView.selectRowIndexes(NSIndexSet(index: __animations.getSelectedAnimationID()-1), byExtendingSelection: false)
|
||||||
// let save: NSMutableDictionary = dataArray.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func moveDownItem(send: AnyObject) {
|
@IBAction func moveDownItem(send: AnyObject) {
|
||||||
if (_selectedRow < _animationArray.count - 1) {
|
if (__animations.getSelectedAnimationID() < __animations.count() - 1) {
|
||||||
_animationArray.insert(_animationArray[_selectedRow+1], atIndex: _selectedRow)
|
__animations.moveDownSelected()
|
||||||
_animationArray.removeAtIndex(_selectedRow+2)
|
|
||||||
myTableView.reloadData()
|
myTableView.reloadData()
|
||||||
myTableView.selectRowIndexes(NSIndexSet(index: _selectedRow+1), byExtendingSelection: false)
|
myTableView.selectRowIndexes(NSIndexSet(index: __animations.getSelectedAnimationID()+1), byExtendingSelection: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
var _animationsWindow: NSWindow = NSWindow()
|
var _animationsWindow: NSWindow = NSWindow()
|
||||||
|
var _cubeWindow: NSWindow = NSWindow()
|
||||||
|
var __animations: Animations = Animations()
|
||||||
|
|
||||||
@NSApplicationMain
|
@NSApplicationMain
|
||||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
@@ -19,6 +21,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||||
// Insert code here to initialize your application
|
// Insert code here to initialize your application
|
||||||
_animationsWindow = animationsWindow
|
_animationsWindow = animationsWindow
|
||||||
|
_cubeWindow = window
|
||||||
|
//__animations.initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
|
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="14C1514" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6751"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/>
|
||||||
<plugIn identifier="com.apple.SceneKitIBPlugin" version="6751"/>
|
<plugIn identifier="com.apple.SceneKitIBPlugin" version="7531"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||||
@@ -684,10 +684,10 @@
|
|||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" headerView="cQF-Rb-Xe4" id="iWG-Dg-mvn">
|
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" headerView="cQF-Rb-Xe4" id="iWG-Dg-mvn">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="440" height="19"/>
|
<rect key="frame" x="0.0" y="0.0" width="533" height="19"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<size key="intercellSpacing" width="3" height="2"/>
|
<size key="intercellSpacing" width="3" height="2"/>
|
||||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
|
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
|
||||||
<tableColumns>
|
<tableColumns>
|
||||||
<tableColumn identifier="AnimName" width="127" minWidth="40" maxWidth="1000" id="Gck-HS-Squ">
|
<tableColumn identifier="AnimName" width="127" minWidth="40" maxWidth="1000" id="Gck-HS-Squ">
|
||||||
@@ -842,7 +842,7 @@
|
|||||||
<connections>
|
<connections>
|
||||||
<outlet property="delegate" destination="zTF-MA-6NT" id="VOO-Mo-r6f"/>
|
<outlet property="delegate" destination="zTF-MA-6NT" id="VOO-Mo-r6f"/>
|
||||||
</connections>
|
</connections>
|
||||||
<point key="canvasLocation" x="-381.5" y="-123.5"/>
|
<point key="canvasLocation" x="624.5" y="-80.5"/>
|
||||||
</window>
|
</window>
|
||||||
<customObject id="494" customClass="AppDelegate" customModule="Cube4Fun" customModuleProvider="target">
|
<customObject id="494" customClass="AppDelegate" customModule="Cube4Fun" customModuleProvider="target">
|
||||||
<connections>
|
<connections>
|
||||||
|
|||||||
@@ -10,12 +10,20 @@ import SceneKit
|
|||||||
|
|
||||||
var lastMousePos: NSPoint = NSPoint()
|
var lastMousePos: NSPoint = NSPoint()
|
||||||
var startAngle: CGFloat = CGFloat()
|
var startAngle: CGFloat = CGFloat()
|
||||||
var klickedColor: Byte = Byte(1)
|
var klickedColor: UInt8 = UInt8(1)
|
||||||
let relativeBarPosition: CGFloat = 500.0
|
let relativeBarPosition: CGFloat = 500.0
|
||||||
|
|
||||||
|
|
||||||
class GameView: SCNView {
|
class GameView: SCNView {
|
||||||
|
|
||||||
|
func resetView() {
|
||||||
|
// goto first frame
|
||||||
|
self.firstButtonPressed()
|
||||||
|
|
||||||
|
// Update speed
|
||||||
|
self.updateSpeedText()
|
||||||
|
}
|
||||||
|
|
||||||
func updateButtonVisibility() {
|
func updateButtonVisibility() {
|
||||||
// init
|
// init
|
||||||
var nextFrame = false;
|
var nextFrame = false;
|
||||||
@@ -26,7 +34,7 @@ class GameView: SCNView {
|
|||||||
|
|
||||||
// first Frame, only one Frame
|
// first Frame, only one Frame
|
||||||
// -> no button visible
|
// -> no button visible
|
||||||
if myFrameCount == 1 && myMaxFrameCount == 1 {
|
if __animations.getAnimationFrameID() == 1 && __animations.getAnimationFrameCount() == 1 {
|
||||||
nextFrame = false;
|
nextFrame = false;
|
||||||
lastFrame = false;
|
lastFrame = false;
|
||||||
prevFrame = false;
|
prevFrame = false;
|
||||||
@@ -35,7 +43,7 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// first Frame, second exists.
|
// first Frame, second exists.
|
||||||
if myFrameCount == 1 && myMaxFrameCount > 1 {
|
if __animations.getAnimationFrameID() == 1 && __animations.getAnimationFrameCount() > 1 {
|
||||||
// Visible:
|
// Visible:
|
||||||
nextFrame = true;
|
nextFrame = true;
|
||||||
lastFrame = true;
|
lastFrame = true;
|
||||||
@@ -46,7 +54,7 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// previous Frame exists, no more Frames
|
// previous Frame exists, no more Frames
|
||||||
if myFrameCount > 1 && myFrameCount == myMaxFrameCount {
|
if __animations.getAnimationFrameID() > 1 && __animations.getAnimationFrameID() == __animations.getAnimationFrameCount() {
|
||||||
// Visible:
|
// Visible:
|
||||||
prevFrame = true;
|
prevFrame = true;
|
||||||
firstFrame = true;
|
firstFrame = true;
|
||||||
@@ -57,7 +65,7 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// previous Frame exists and next Frame exists {
|
// previous Frame exists and next Frame exists {
|
||||||
if myFrameCount > 1 && myFrameCount < myMaxFrameCount {
|
if __animations.getAnimationFrameID() > 1 && __animations.getAnimationFrameID() < __animations.getAnimationFrameCount() {
|
||||||
// Visible:
|
// Visible:
|
||||||
prevFrame = true;
|
prevFrame = true;
|
||||||
firstFrame = true;
|
firstFrame = true;
|
||||||
@@ -68,7 +76,7 @@ class GameView: SCNView {
|
|||||||
|
|
||||||
if let rootNode = self.scene?.rootNode {
|
if let rootNode = self.scene?.rootNode {
|
||||||
for childNode in rootNode.childNodes {
|
for childNode in rootNode.childNodes {
|
||||||
let buttonNode: SCNNode = childNode as SCNNode
|
let buttonNode: SCNNode = childNode as! SCNNode
|
||||||
if buttonNode.name == "myNextFrameButton" {
|
if buttonNode.name == "myNextFrameButton" {
|
||||||
buttonNode.hidden = !nextFrame;
|
buttonNode.hidden = !nextFrame;
|
||||||
}
|
}
|
||||||
@@ -85,8 +93,8 @@ class GameView: SCNView {
|
|||||||
buttonNode.hidden = !delFrame
|
buttonNode.hidden = !delFrame
|
||||||
}
|
}
|
||||||
if buttonNode.name == "myFrameText" {
|
if buttonNode.name == "myFrameText" {
|
||||||
let geometry:SCNText = buttonNode.geometry as SCNText
|
let geometry:SCNText = buttonNode.geometry as! SCNText
|
||||||
geometry.string = "Frame: \(myFrameCount)/\(myMaxFrameCount)"
|
geometry.string = "Frame: \(__animations.getAnimationFrameID())/\(__animations.getAnimationFrameCount())"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -97,7 +105,8 @@ class GameView: SCNView {
|
|||||||
func updateLEDFrame() {
|
func updateLEDFrame() {
|
||||||
// get actuall frame data
|
// get actuall frame data
|
||||||
|
|
||||||
let data : UnsafePointer<Byte> = UnsafePointer<Byte>(myFrames.mutableBytes)
|
// let data : UnsafePointer<Byte> = UnsafePointer<Byte>(myFrames.mutableBytes)
|
||||||
|
let data = __animations.getAnimData()
|
||||||
//NSMutableData
|
//NSMutableData
|
||||||
if let rootNode = self.scene?.rootNode {
|
if let rootNode = self.scene?.rootNode {
|
||||||
if let cubeNode = rootNode.childNodeWithName("cubeNode", recursively: true) {
|
if let cubeNode = rootNode.childNodeWithName("cubeNode", recursively: true) {
|
||||||
@@ -108,8 +117,8 @@ class GameView: SCNView {
|
|||||||
let ledID: Int = Int(name.integerValue)
|
let ledID: Int = Int(name.integerValue)
|
||||||
if let material: SCNMaterial = geometry.firstMaterial {
|
if let material: SCNMaterial = geometry.firstMaterial {
|
||||||
var color: NSColor = NSColor()
|
var color: NSColor = NSColor()
|
||||||
let colorPosition: Int = ((myFrameCount-1)*64) + ledID
|
let colorPosition: Int = ((__animations.getAnimationFrameID()-1)*64) + ledID
|
||||||
let savedColor: Byte = data[colorPosition]
|
let savedColor: UInt8 = data[colorPosition]
|
||||||
if data[colorPosition] == 255 {
|
if data[colorPosition] == 255 {
|
||||||
color = NSColor.grayColor()
|
color = NSColor.grayColor()
|
||||||
}else{
|
}else{
|
||||||
@@ -130,13 +139,15 @@ class GameView: SCNView {
|
|||||||
|
|
||||||
func plusButtonPressed() {
|
func plusButtonPressed() {
|
||||||
// Extend the data array with one frame
|
// Extend the data array with one frame
|
||||||
myFrames.appendBytes(emptyFrame, length: 64)
|
//myFrames.appendBytes(emptyFrame, length: 64)
|
||||||
|
__animations.addFrame()
|
||||||
|
|
||||||
// Add frame
|
// Add frame
|
||||||
myMaxFrameCount++;
|
//myMaxFrameCount++;
|
||||||
|
|
||||||
// Goto new frame
|
// Goto new frame
|
||||||
myFrameCount = myMaxFrameCount;
|
//myFrameCount = __animations.getAnimationFrameCount();
|
||||||
|
__animations.gotoLastFrame()
|
||||||
|
|
||||||
// Update LEDs
|
// Update LEDs
|
||||||
updateLEDFrame()
|
updateLEDFrame()
|
||||||
@@ -150,21 +161,24 @@ class GameView: SCNView {
|
|||||||
// TODO!
|
// TODO!
|
||||||
|
|
||||||
// Remove frame
|
// Remove frame
|
||||||
if myMaxFrameCount > 1 {
|
__animations.removeFrame()
|
||||||
myMaxFrameCount--;
|
// if __animations.getAnimationFrameCount() > 1 {
|
||||||
}
|
// myMaxFrameCount--;
|
||||||
if myFrameCount > 1 {
|
// }
|
||||||
myFrameCount--;
|
// if myFrameCount > 1 {
|
||||||
}
|
// myFrameCount--;
|
||||||
|
// }
|
||||||
|
|
||||||
// Update control button visibility
|
// Update control button visibility
|
||||||
updateButtonVisibility()
|
updateButtonVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
func prevButtonPressed() {
|
func prevButtonPressed() {
|
||||||
if myFrameCount > 1 {
|
// if myFrameCount > 1 {
|
||||||
myFrameCount--
|
// myFrameCount--
|
||||||
}
|
// }
|
||||||
|
__animations.gotoPrevFrame()
|
||||||
|
|
||||||
// Update LEDs
|
// Update LEDs
|
||||||
updateLEDFrame()
|
updateLEDFrame()
|
||||||
|
|
||||||
@@ -173,9 +187,10 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func nextButtonPressed() {
|
func nextButtonPressed() {
|
||||||
if myFrameCount < myMaxFrameCount {
|
// if myFrameCount < myMaxFrameCount {
|
||||||
myFrameCount++
|
// myFrameCount++
|
||||||
}
|
// }
|
||||||
|
__animations.gotoNextFrame()
|
||||||
|
|
||||||
// Update LEDs
|
// Update LEDs
|
||||||
updateLEDFrame()
|
updateLEDFrame()
|
||||||
@@ -185,7 +200,8 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func firstButtonPressed() {
|
func firstButtonPressed() {
|
||||||
myFrameCount = 1;
|
//myFrameCount = 1;
|
||||||
|
__animations.gotoFirstFrame()
|
||||||
|
|
||||||
// Update LEDs
|
// Update LEDs
|
||||||
updateLEDFrame()
|
updateLEDFrame()
|
||||||
@@ -195,7 +211,7 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func lastButtonPressed() {
|
func lastButtonPressed() {
|
||||||
myFrameCount = myMaxFrameCount
|
__animations.gotoLastFrame()
|
||||||
|
|
||||||
// Update LEDs
|
// Update LEDs
|
||||||
updateLEDFrame()
|
updateLEDFrame()
|
||||||
@@ -205,27 +221,29 @@ class GameView: SCNView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func plusSpeedButtonPressed() {
|
func plusSpeedButtonPressed() {
|
||||||
if ( _playSendDelay <= 3 ) { // 3 seconds slowest fps
|
__animations.increaseSpeed()
|
||||||
_playSendDelay = _playSendDelay + 0.1
|
// if ( _playSendDelay <= 3 ) { // 3 seconds slowest fps
|
||||||
|
// _playSendDelay = _playSendDelay + 0.1
|
||||||
updateSpeedText()
|
updateSpeedText()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusSpeedButtonPressed() {
|
func minusSpeedButtonPressed() {
|
||||||
println(_playSendDelay)
|
//println(_playSendDelay)
|
||||||
if ( _playSendDelay > 0.2 ) { // 100ms fastest fps
|
__animations.decreaseSpeed()
|
||||||
_playSendDelay = _playSendDelay - 0.1
|
// if ( _playSendDelay > 0.2 ) { // 100ms fastest fps
|
||||||
|
// _playSendDelay = _playSendDelay - 0.1
|
||||||
updateSpeedText()
|
updateSpeedText()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSpeedText() {
|
func updateSpeedText() {
|
||||||
if let rootNode = self.scene?.rootNode {
|
if let rootNode = self.scene?.rootNode {
|
||||||
for childNode in rootNode.childNodes {
|
for childNode in rootNode.childNodes {
|
||||||
let buttonNode: SCNNode = childNode as SCNNode
|
let buttonNode: SCNNode = childNode as! SCNNode
|
||||||
if buttonNode.name == "mySpeedText" {
|
if buttonNode.name == "mySpeedText" {
|
||||||
let geometry:SCNText = buttonNode.geometry as SCNText
|
let geometry:SCNText = buttonNode.geometry as! SCNText
|
||||||
geometry.string = "Speed: \(Int(_playSendDelay*1000)) ms"
|
geometry.string = "Speed: \(__animations.animationSpeedInt()) ms"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -272,14 +290,14 @@ class GameView: SCNView {
|
|||||||
if let geom = node.geometry {
|
if let geom = node.geometry {
|
||||||
if let name:NSString = geom.name {
|
if let name:NSString = geom.name {
|
||||||
if name.integerValue >= 0 && name.integerValue < 64 { // LED lamps
|
if name.integerValue >= 0 && name.integerValue < 64 { // LED lamps
|
||||||
let color: NSColor = geom.firstMaterial?.diffuse.contents as NSColor
|
let color: NSColor = geom.firstMaterial?.diffuse.contents as! NSColor
|
||||||
if color != NSColor.grayColor() {
|
if color != NSColor.grayColor() {
|
||||||
// Make sure we are in range of 0...255
|
// Make sure we are in range of 0...255
|
||||||
let ledColor = (color.hueComponent * 255) % 255
|
let ledColor = (color.hueComponent * 255) % 255
|
||||||
if ( ledColor >= 0 && ledColor < 255 ) {
|
if ( ledColor >= 0 && ledColor < 255 ) {
|
||||||
klickedColor = Byte(ledColor)
|
klickedColor = UInt8(ledColor)
|
||||||
}
|
}
|
||||||
klickedColor = Byte (color.hueComponent * 255)
|
klickedColor = UInt8 (color.hueComponent * 255)
|
||||||
moveArrows(Int(klickedColor))
|
moveArrows(Int(klickedColor))
|
||||||
//println(klickedColor)
|
//println(klickedColor)
|
||||||
}
|
}
|
||||||
@@ -314,7 +332,7 @@ class GameView: SCNView {
|
|||||||
if clickedNode.name == "myBox" {
|
if clickedNode.name == "myBox" {
|
||||||
anim = false
|
anim = false
|
||||||
}
|
}
|
||||||
if clickedNode.name == "myPlayButton" && myMaxFrameCount > 1 {
|
if clickedNode.name == "myPlayButton" && __animations.getAnimationFrameCount() > 1 {
|
||||||
playButtonPressed()
|
playButtonPressed()
|
||||||
anim = false
|
anim = false
|
||||||
}
|
}
|
||||||
@@ -357,7 +375,7 @@ class GameView: SCNView {
|
|||||||
if colorInt > 253 {
|
if colorInt > 253 {
|
||||||
klickedColor = 253 // Maximum value
|
klickedColor = 253 // Maximum value
|
||||||
}else{
|
}else{
|
||||||
klickedColor = Byte(colorInt)
|
klickedColor = UInt8(colorInt)
|
||||||
println(klickedColor)
|
println(klickedColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,11 +394,11 @@ class GameView: SCNView {
|
|||||||
if let node = result.node {
|
if let node = result.node {
|
||||||
if let geom = node.geometry {
|
if let geom = node.geometry {
|
||||||
if let name:NSString = geom.name {
|
if let name:NSString = geom.name {
|
||||||
let myGeometry:SCNText = self.scene!.rootNode.childNodeWithName("myDescr", recursively: true)?.geometry as SCNText
|
let myGeometry:SCNText = self.scene!.rootNode.childNodeWithName("myDescr", recursively: true)?.geometry as! SCNText
|
||||||
// Show touched led
|
// Show touched led
|
||||||
myGeometry.string = name
|
myGeometry.string = name
|
||||||
// Check for previously color
|
// Check for previously color
|
||||||
let prevColor = geom.firstMaterial?.diffuse.contents as NSColor
|
let prevColor = geom.firstMaterial?.diffuse.contents as! NSColor
|
||||||
if prevColor != NSColor.grayColor() {
|
if prevColor != NSColor.grayColor() {
|
||||||
geom.firstMaterial?.diffuse.contents = NSColor.grayColor()
|
geom.firstMaterial?.diffuse.contents = NSColor.grayColor()
|
||||||
ledColorOn = false
|
ledColorOn = false
|
||||||
@@ -443,13 +461,14 @@ class GameView: SCNView {
|
|||||||
SCNTransaction.commit()
|
SCNTransaction.commit()
|
||||||
|
|
||||||
// Update the LED frame
|
// Update the LED frame
|
||||||
var myByte: [Byte]
|
var myByte: UInt8
|
||||||
if ledColorOn {
|
if ledColorOn {
|
||||||
myByte = [klickedColor]
|
myByte = klickedColor
|
||||||
}else{
|
}else{
|
||||||
myByte = [255] // Off
|
myByte = 255 // Off
|
||||||
}
|
}
|
||||||
myFrames.replaceBytesInRange(NSMakeRange(((myFrameCount-1)*64)+ledPressed, 1), withBytes: myByte)
|
__animations.setLEDColor(myByte, led: ledPressed)
|
||||||
|
//myFrames.replaceBytesInRange(NSMakeRange(((myFrameCount-1)*64)+ledPressed, 1), withBytes: myByte)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +537,8 @@ class GameView: SCNView {
|
|||||||
break;
|
break;
|
||||||
case 17: // t - Key
|
case 17: // t - Key
|
||||||
// Reset the frame color on the Cube
|
// Reset the frame color on the Cube
|
||||||
myFrames.replaceBytesInRange(NSMakeRange(myFrameCount-1, 64), withBytes: emptyFrame)
|
//myFrames.replaceBytesInRange(NSMakeRange(myFrameCount-1, 64), withBytes: emptyFrame)
|
||||||
|
__animations.clearLEDColor()
|
||||||
|
|
||||||
// Reset the frame color in 3D
|
// Reset the frame color in 3D
|
||||||
if let rootNode = self.scene?.rootNode {
|
if let rootNode = self.scene?.rootNode {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
import SceneKit
|
import SceneKit
|
||||||
import QuartzCore
|
import QuartzCore
|
||||||
|
|
||||||
|
/*
|
||||||
var myFrameCount: UInt32 = 1;
|
var myFrameCount: UInt32 = 1;
|
||||||
var myMaxFrameCount: UInt32 = 1;
|
var myMaxFrameCount: UInt32 = 1;
|
||||||
var myFrames: NSMutableData = NSMutableData() // == byte[] array
|
var myFrames: NSMutableData = NSMutableData() // == byte[] array
|
||||||
@@ -33,12 +33,15 @@ let emptyFrame: [Byte] = [
|
|||||||
255,255,255,255,
|
255,255,255,255,
|
||||||
255,255,255,255]
|
255,255,255,255]
|
||||||
|
|
||||||
var _previousUpdateTime: NSTimeInterval = NSTimeInterval()
|
|
||||||
var _deltaTime: NSTimeInterval = NSTimeInterval()
|
|
||||||
let _minSendDelay: NSTimeInterval = 0.200 // 200 milliseconds
|
let _minSendDelay: NSTimeInterval = 0.200 // 200 milliseconds
|
||||||
let _frameSendDelay: NSTimeInterval = 0.2 // one second
|
let _frameSendDelay: NSTimeInterval = 0.2 // one second
|
||||||
var _playSendDelay: NSTimeInterval = 0.5 // 500 milliseconds as default
|
var _playSendDelay: NSTimeInterval = 0.5 // 500 milliseconds as default
|
||||||
|
*/
|
||||||
|
|
||||||
|
var _previousUpdateTime: NSTimeInterval = NSTimeInterval()
|
||||||
|
var _deltaTime: NSTimeInterval = NSTimeInterval()
|
||||||
var _playAllFrames = false
|
var _playAllFrames = false
|
||||||
|
var _gameView: GameView = GameView();
|
||||||
|
|
||||||
class GameViewController: NSViewController { // SCNSceneRendererDelegate
|
class GameViewController: NSViewController { // SCNSceneRendererDelegate
|
||||||
|
|
||||||
@@ -73,18 +76,18 @@ class GameViewController: NSViewController { // SCNSceneRendererDelegate
|
|||||||
|
|
||||||
//var ms = Int((time % 1) * 1000)
|
//var ms = Int((time % 1) * 1000)
|
||||||
if ( _playAllFrames ) {
|
if ( _playAllFrames ) {
|
||||||
if ( _deltaTime >= _playSendDelay ){
|
if ( _deltaTime >= __animations.animationSpeedFloat() ){
|
||||||
if myFrameCount >= myMaxFrameCount {
|
if (__animations.getAnimationFrameID() >= __animations.getAnimationFrameCount()) {
|
||||||
self.gameView!.firstButtonPressed()
|
self.gameView!.firstButtonPressed()
|
||||||
}else{
|
}else{
|
||||||
self.gameView!.nextButtonPressed()
|
self.gameView!.nextButtonPressed()
|
||||||
}
|
}
|
||||||
CubeNetworkObj.updateFrame(UnsafePointer<UInt8>(myFrames.bytes), count: myFrameCount)
|
CubeNetworkObj.updateFrame(__animations.getAnimData(), count: UInt32(__animations.getAnimationFrameID()))
|
||||||
_previousUpdateTime = time;
|
_previousUpdateTime = time;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if ( _deltaTime >= _minSendDelay ) {
|
if ( _deltaTime >= __animations.getMinSendDelay() ) {
|
||||||
CubeNetworkObj.updateFrame(UnsafePointer<UInt8>(myFrames.bytes), count: myFrameCount)
|
CubeNetworkObj.updateFrame(__animations.getAnimData(), count: UInt32(__animations.getAnimationFrameID()))
|
||||||
//println("SendFrame: \(_deltaTime)")
|
//println("SendFrame: \(_deltaTime)")
|
||||||
_previousUpdateTime = time;
|
_previousUpdateTime = time;
|
||||||
}
|
}
|
||||||
@@ -94,18 +97,19 @@ class GameViewController: NSViewController { // SCNSceneRendererDelegate
|
|||||||
|
|
||||||
override func awakeFromNib(){
|
override func awakeFromNib(){
|
||||||
|
|
||||||
|
_gameView = gameView;
|
||||||
//NSTimer.scheduledTimerWithTimeInterval(_frameSendDelay, invocation: CubeNetworkObj.initObjects(), repeats: true)
|
//NSTimer.scheduledTimerWithTimeInterval(_frameSendDelay, invocation: CubeNetworkObj.initObjects(), repeats: true)
|
||||||
// CubeNetworkObj.initObjects();
|
// CubeNetworkObj.initObjects();
|
||||||
|
|
||||||
// Init first frame
|
// Init first frame
|
||||||
|
|
||||||
myFrames = NSMutableData(bytes: emptyFrame, length: 64)
|
// myFrames = NSMutableData(bytes: emptyFrame, length: 64)
|
||||||
myFrameCount = 1
|
// myFrameCount = 1
|
||||||
// Open connection to the LED cube
|
// Open connection to the LED cube
|
||||||
CubeNetworkObj.openConnection()
|
CubeNetworkObj.openConnection()
|
||||||
|
|
||||||
// Fallback timer if nothing render at the moment
|
// Fallback timer if nothing render at the moment
|
||||||
NSTimer.scheduledTimerWithTimeInterval(_frameSendDelay, target: self, selector: Selector("sendFrame"), userInfo: nil, repeats: true)
|
NSTimer.scheduledTimerWithTimeInterval(__animations.getMinSendDelay(), target: self, selector: Selector("sendFrame"), userInfo: nil, repeats: true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,43 +3,43 @@
|
|||||||
{
|
{
|
||||||
"size" : "16x16",
|
"size" : "16x16",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-16.png",
|
"filename" : "Cube6-16j.png",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "16x16",
|
"size" : "16x16",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-32.png",
|
"filename" : "Cube6-32j-1.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "32x32",
|
"size" : "32x32",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-32-1.png",
|
"filename" : "Cube6-32j.png",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "32x32",
|
"size" : "32x32",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-64.png",
|
"filename" : "Cube6-64j.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "128x128",
|
"size" : "128x128",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-128.png",
|
"filename" : "Cube6-128j.png",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "128x128",
|
"size" : "128x128",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-256.png",
|
"filename" : "Cube6-256j-1.png",
|
||||||
"scale" : "2x"
|
"scale" : "2x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"size" : "256x256",
|
"size" : "256x256",
|
||||||
"idiom" : "mac",
|
"idiom" : "mac",
|
||||||
"filename" : "Cube4Fun-Icon-256-1.png",
|
"filename" : "Cube6-256j.png",
|
||||||
"scale" : "1x"
|
"scale" : "1x"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-128j.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-16j.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-256j-1.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-256j.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-32j-1.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-32j.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
Cube4Fun/Images.xcassets/AppIcon.appiconset/Cube6-64j.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
@@ -31,7 +31,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
pauseImageNode.name = "myPauseButton"
|
pauseImageNode.name = "myPauseButton"
|
||||||
pauseImageNode.position = SCNVector3(x:0, y:14, z:0)
|
pauseImageNode.position = SCNVector3(x:0, y:14, z:0)
|
||||||
pauseImageNode.hidden = true
|
pauseImageNode.hidden = true
|
||||||
if myFrameCount == 1 && myMaxFrameCount == 1 {
|
if __animations.getAnimationFrameID() == 1 && __animations.getAnimationFrameCount() == 1 {
|
||||||
pauseImageNode.hidden = true
|
pauseImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(pauseImageNode)
|
self.rootNode.addChildNode(pauseImageNode)
|
||||||
@@ -42,7 +42,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
let nextFrameImageNode = SCNNode(geometry: nextFrameImage)
|
let nextFrameImageNode = SCNNode(geometry: nextFrameImage)
|
||||||
nextFrameImageNode.name = "myNextFrameButton"
|
nextFrameImageNode.name = "myNextFrameButton"
|
||||||
nextFrameImageNode.position = SCNVector3(x:2, y:14, z:0)
|
nextFrameImageNode.position = SCNVector3(x:2, y:14, z:0)
|
||||||
if myFrameCount == 1 && myMaxFrameCount == 1 {
|
if __animations.getAnimationFrameID() == 1 && __animations.getAnimationFrameCount() == 1 {
|
||||||
nextFrameImageNode.hidden = true
|
nextFrameImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(nextFrameImageNode)
|
self.rootNode.addChildNode(nextFrameImageNode)
|
||||||
@@ -53,7 +53,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
let prevFrameImageNode = SCNNode(geometry: prevFrameImage)
|
let prevFrameImageNode = SCNNode(geometry: prevFrameImage)
|
||||||
prevFrameImageNode.name = "myPrevFrameButton"
|
prevFrameImageNode.name = "myPrevFrameButton"
|
||||||
prevFrameImageNode.position = SCNVector3(x:-2, y:14, z:0)
|
prevFrameImageNode.position = SCNVector3(x:-2, y:14, z:0)
|
||||||
if myFrameCount == 1 {
|
if __animations.getAnimationFrameID() == 1 {
|
||||||
prevFrameImageNode.hidden = true
|
prevFrameImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(prevFrameImageNode)
|
self.rootNode.addChildNode(prevFrameImageNode)
|
||||||
@@ -64,7 +64,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
let startFrameImageNode = SCNNode(geometry: startFrameImage)
|
let startFrameImageNode = SCNNode(geometry: startFrameImage)
|
||||||
startFrameImageNode.name = "myStartFrameButton"
|
startFrameImageNode.name = "myStartFrameButton"
|
||||||
startFrameImageNode.position = SCNVector3(x:-5, y:14, z:0)
|
startFrameImageNode.position = SCNVector3(x:-5, y:14, z:0)
|
||||||
if myFrameCount == 1 {
|
if __animations.getAnimationFrameID() == 1 {
|
||||||
startFrameImageNode.hidden = true
|
startFrameImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(startFrameImageNode)
|
self.rootNode.addChildNode(startFrameImageNode)
|
||||||
@@ -75,7 +75,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
let lastFrameImageNode = SCNNode(geometry: lastFrameImage)
|
let lastFrameImageNode = SCNNode(geometry: lastFrameImage)
|
||||||
lastFrameImageNode.name = "myLastFrameButton"
|
lastFrameImageNode.name = "myLastFrameButton"
|
||||||
lastFrameImageNode.position = SCNVector3(x:5, y:14, z:0)
|
lastFrameImageNode.position = SCNVector3(x:5, y:14, z:0)
|
||||||
if myFrameCount == myMaxFrameCount {
|
if __animations.getAnimationFrameID() == __animations.getAnimationFrameCount() {
|
||||||
lastFrameImageNode.hidden = true
|
lastFrameImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(lastFrameImageNode)
|
self.rootNode.addChildNode(lastFrameImageNode)
|
||||||
@@ -84,7 +84,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
|
|
||||||
func createSpeedButtons() {
|
func createSpeedButtons() {
|
||||||
// Frame
|
// Frame
|
||||||
let textSpeed = SCNText(string: "Speed: \(Int(_playSendDelay*1000)) ms", extrusionDepth: 0)
|
let textSpeed = SCNText(string: "Speed: \(__animations.animationSpeedInt()) ms", extrusionDepth: 0)
|
||||||
textSpeed.font = NSFont(name: "Arial", size: 1.2)
|
textSpeed.font = NSFont(name: "Arial", size: 1.2)
|
||||||
let textSpeedNode = SCNNode(geometry: textSpeed)
|
let textSpeedNode = SCNNode(geometry: textSpeed)
|
||||||
textSpeedNode.name = "mySpeedText"
|
textSpeedNode.name = "mySpeedText"
|
||||||
@@ -109,7 +109,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createFrameButtons() {
|
func createFrameButtons() {
|
||||||
let textFrame = SCNText(string: "Frame: \(myFrameCount)/\(myMaxFrameCount)", extrusionDepth: 0)
|
let textFrame = SCNText(string: "Frame: \(__animations.getAnimationFrameID())/\(__animations.getAnimationFrameCount())", extrusionDepth: 0)
|
||||||
textFrame.font = NSFont(name: "Arial", size: 1.2)
|
textFrame.font = NSFont(name: "Arial", size: 1.2)
|
||||||
let textFrameNode = SCNNode(geometry: textFrame)
|
let textFrameNode = SCNNode(geometry: textFrame)
|
||||||
textFrameNode.name = "myFrameText"
|
textFrameNode.name = "myFrameText"
|
||||||
@@ -131,7 +131,7 @@ class PrimitivesScene: SCNScene {
|
|||||||
delFrameImageNode.name = "myDelFrameButton"
|
delFrameImageNode.name = "myDelFrameButton"
|
||||||
delFrameImageNode.position = SCNVector3(x:-18.7, y:12, z:0)
|
delFrameImageNode.position = SCNVector3(x:-18.7, y:12, z:0)
|
||||||
// for first frame, there is nothing to delete
|
// for first frame, there is nothing to delete
|
||||||
if ( myFrameCount == 1 ) {
|
if ( __animations.getAnimationFrameID() == 1 ) {
|
||||||
delFrameImageNode.hidden = true
|
delFrameImageNode.hidden = true
|
||||||
}
|
}
|
||||||
self.rootNode.addChildNode(delFrameImageNode)
|
self.rootNode.addChildNode(delFrameImageNode)
|
||||||
|
|||||||