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

trimmed whitespace #2

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion FoundationHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10360,4 +10360,4 @@ class URLSessionStreamTask : Foundation.URLSessionTask {
}
var NSURLErrorCannotCloseFile: Swift.Int {
get {}
}
}
4 changes: 2 additions & 2 deletions VPL/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Create canvas view controller
let canvasViewController = CanvasViewController()

// Create the window
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = canvasViewController
window!.makeKeyAndVisible()

return true
}

Expand Down
27 changes: 11 additions & 16 deletions VPL/Data/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@
// Copyright © 2018 Nathan Flurry. All rights reserved.
//

import Foundation

public enum NodeOutput {
case triggers([OutputTrigger]), value(OutputValue), none

/// Returns the triggers, if a triggers type.
public var triggers: [OutputTrigger]? {
if case let .triggers(triggers) = self {
return triggers
} else {
return nil
}
return nil
}

/// Returns the value, if a value type.
public var value: OutputValue? {
if case let .value(value) = self {
return value
} else {
return nil
}
return nil
}
}

Expand All @@ -37,9 +33,9 @@ public protocol Node: class {
var inputValues: [InputValue] { get }
var inputVariables: [InputVariable] { get }
var output: NodeOutput { get }

init()

func assemble() -> String
}

Expand All @@ -59,18 +55,17 @@ extension Node {
return trigger
} else if case let .value(value) = output {
return value.target?.owner.nearestControlNode
} else {
return nil
}
return nil
}

/// Variables that this node can use.
public var availableVariables: [NodeVariable] {
// Add variables available from all parent triggers
let trigger = nearestControlNode
return (trigger?.target?.exposedVariables ?? []) + (trigger?.target?.owner.availableVariables ?? [])
}

public func setupConnections() {
inputTrigger?.owner = self
for value in inputValues { value.owner = self }
Expand All @@ -84,7 +79,7 @@ extension Node {
break
}
}

public func destroy() {
inputTrigger?.reset()
for value in inputValues { value.reset() }
Expand All @@ -97,7 +92,7 @@ extension Node {
break
}
}

public func assembleOutputTrigger(id: String? = nil) -> String {
if case let .triggers(triggers) = output {
if let id = id {
Expand Down
44 changes: 21 additions & 23 deletions VPL/Data/NodeTrigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,39 @@
// Copyright © 2018 Nathan Flurry. All rights reserved.
//

import Foundation

public final class InputTrigger {
/// The node that owns this trigger.
public internal(set) weak var owner: Node!

/// The connected trigger.
public private(set) var target: OutputTrigger?

public init() {

}

/// Determines if two triggers can be connected.
public func canConnect(to newTarget: OutputTrigger) -> Bool {
return newTarget.canConnect(to: self)
}

/// Connects this trigger to another trigger.
public func connect(to newTarget: OutputTrigger) {
// Set the new target
target = newTarget

// Connect the other node
if newTarget.target !== self {
newTarget.connect(to: self)
}
}

/// Disconnects any targets this is connected to.
public func reset() {
// Remove the target
let tmpTarget = target
target = nil

// Remove other target if needed
if tmpTarget?.target != nil {
tmpTarget?.reset()
Expand All @@ -51,62 +49,62 @@ public final class InputTrigger {
public final class OutputTrigger {
/// The node that owns this trigger
public internal(set) weak var owner: Node!

/// An identifier for this trigger.
public let id: String

/// Name for this trigger.
public let name: String

/// The connected trigger.
public private(set) var target: InputTrigger?

/// Variables availables to any other nodes further along the control flow.
public let exposedVariables: [NodeVariable]

public init(id: String, name: String, exposedVariables: [NodeVariable] = []) {
self.id = id
self.name = name
self.exposedVariables = exposedVariables

// Set owner on variables
for variable in exposedVariables {
variable.owner = self
}
}

public convenience init(exposedVariables: [NodeVariable] = []) {
self.init(id: "next", name: "Next", exposedVariables: exposedVariables)
}

/// Determines if two triggers can be connected.
public func canConnect(to newTarget: InputTrigger) -> Bool {
return owner !== newTarget.owner && target == nil && newTarget.target == nil
}

/// Connects this trigger to another trigger.
public func connect(to newTarget: InputTrigger) {
// Set the new target
target = newTarget

// Connect the other node
if newTarget.target !== self {
newTarget.connect(to: self)
}
}

/// Disconnects any targets this is connected to.
public func reset() {
// Remove the target
let tmpTarget = target
target = nil

// Remove other target if needed
if tmpTarget?.target != nil {
tmpTarget?.reset()
}
}

/// Assembles the code.
public func assemble() -> String {
return target?.owner.assemble() ?? ""
Expand Down
40 changes: 19 additions & 21 deletions VPL/Data/NodeValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,56 @@
// Copyright © 2018 Nathan Flurry. All rights reserved.
//

import Foundation

public final class InputValue {
/// The node that owns this value.
public internal(set) weak var owner: Node!

/// An identifier for this value.
public let id: String

/// Name for this value.
public let name: String

/// The type of value this holds.
public let type: ValueType

/// The connected value.
public private(set) var target: OutputValue?

public init(id: String, name: String, type: ValueType) {
self.id = id
self.name = name
self.type = type
}

/// Determines if two values can be connected.
public func canConnect(to newTarget: OutputValue) -> Bool {
return newTarget.canConnect(to: self)
}

/// Connects this value to another value.
public func connect(to newTarget: OutputValue) {
// Set the new target
target = newTarget

// Connect the other node
if newTarget.target !== self {
newTarget.connect(to: self)
}
}

/// Disconnects any targets this is connected to.
public func reset() {
// Remove the target
let tmpTarget = target
target = nil

// Remove other target if needed
if tmpTarget?.target != nil {
tmpTarget?.reset()
}
}

/// Assembles the code.
public func assemble() -> String {
return target?.owner.assemble() ?? ""
Expand All @@ -67,39 +65,39 @@ public final class InputValue {
public final class OutputValue {
/// The node that owns this value
public internal(set) weak var owner: Node!

/// The type of value this holds.
public let type: ValueType

/// The connected value.
public private(set) var target: InputValue?

public init(type: ValueType) {
self.type = type
}

/// Determines if two values can be connected.
public func canConnect(to newTarget: InputValue) -> Bool {
return type.canCast(to: newTarget.type) && owner !== newTarget.owner && target == nil && newTarget.target == nil
}

/// Connects this value to another value.
public func connect(to newTarget: InputValue) {
// Set the new target
target = newTarget

// Connect the other node
if newTarget.target !== self {
newTarget.connect(to: self)
}
}

/// Disconnects any targets this is connected to.
public func reset() {
// Remove the target
let tmpTarget = target
target = nil

// Remove other target if needed
if tmpTarget?.target != nil {
tmpTarget?.reset()
Expand Down
Loading