mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
- Change the parser to accept "objc" without an @ sign as a contextual keyword, including the dance to handle the general parenthesized case. - Update all comments to refer to "objc" instead of "@objc". - Update all diagnostics accordingly. - Update all tests that fail due to the diagnostics change. - Switch the stdlib to use the new syntax. This does not switch all tests to use the new syntax, nor does it warn about the old syntax yet. That will be forthcoming. Also, this needs a bit of refactoring, which will be coming up. Swift SVN r19555
198 lines
5.3 KiB
Swift
198 lines
5.3 KiB
Swift
@exported import SpriteKit
|
|
|
|
// SpriteKit defines SKColor using a macro.
|
|
|
|
#if os(OSX)
|
|
@public typealias SKColor = NSColor
|
|
#elseif os(iOS)
|
|
@public typealias SKColor = UIColor
|
|
#endif
|
|
|
|
#if os(OSX)
|
|
// this class only exists to allow AnyObject lookup of _copyImageData
|
|
// since that method only exists in a private header in SpriteKit, the lookup
|
|
// mechanism by default fails to accept it as a valid AnyObject call
|
|
objc class _SpriteKitMethodProvider : NSObject {
|
|
init() { _fatalError("don't touch me") }
|
|
objc func _copyImageData() -> NSData! { return nil }
|
|
}
|
|
|
|
// HACK - these four mirrors do the exact same thing, they should be one and the same
|
|
// and use an AnyObject, or some T : NSObject as their ivar type, but that causes
|
|
// the compiler to crash - as a result, four mirrors it is
|
|
struct _SKShapeNodeMirror : Mirror {
|
|
var _value : SKShapeNode
|
|
|
|
init(_ _v : SKShapeNode) {
|
|
_value = _v
|
|
}
|
|
|
|
var value : Any { return (_value as Any)}
|
|
|
|
var valueType: Any.Type { return (_value as Any).dynamicType }
|
|
|
|
var objectIdentifier: ObjectIdentifier? { return .None }
|
|
|
|
var count: Int { return 0 }
|
|
|
|
subscript(_: Int) -> (String,Mirror) { _fatalError("Mirror access out of bounds") }
|
|
|
|
var summary: String { return _value.description }
|
|
|
|
var quickLookObject: QuickLookObject? {
|
|
// this code comes straight from the quicklooks
|
|
|
|
if let data = (_value as AnyObject)._copyImageData?() {
|
|
// we could send a Raw, but I don't want to make a copy of the bytes for no good reason
|
|
// make an NSImage out of them and send that
|
|
let img = NSImage(data: data)
|
|
return .Some(.Sprite(img))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var disposition : MirrorDisposition { get { return .Aggregate } }
|
|
}
|
|
|
|
struct _SKSpriteNodeMirror : Mirror {
|
|
var _value : SKSpriteNode
|
|
|
|
init(_ _v : SKSpriteNode) {
|
|
_value = _v
|
|
}
|
|
|
|
var value : Any { return (_value as Any)}
|
|
|
|
var valueType: Any.Type { return (_value as Any).dynamicType }
|
|
|
|
var objectIdentifier: ObjectIdentifier? { return .None }
|
|
|
|
var count: Int { return 0 }
|
|
|
|
subscript(_: Int) -> (String,Mirror) { _fatalError("Mirror access out of bounds") }
|
|
|
|
var summary: String { return _value.description }
|
|
|
|
var quickLookObject: QuickLookObject? {
|
|
// this code comes straight from the quicklooks
|
|
|
|
if let data = (_value as AnyObject)._copyImageData?() {
|
|
// we could send a Raw, but I don't want to make a copy of the bytes for no good reason
|
|
// make an NSImage out of them and send that
|
|
let img = NSImage(data: data)
|
|
return .Some(.Sprite(img))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var disposition : MirrorDisposition { get { return .Aggregate } }
|
|
}
|
|
|
|
struct _SKTextureAtlasMirror : Mirror {
|
|
var _value : SKTextureAtlas
|
|
|
|
init(_ _v : SKTextureAtlas) {
|
|
_value = _v
|
|
}
|
|
|
|
var value : Any { return (_value as Any)}
|
|
|
|
var valueType: Any.Type { return (_value as Any).dynamicType }
|
|
|
|
var objectIdentifier: ObjectIdentifier? { return .None }
|
|
|
|
var count: Int { return 0 }
|
|
|
|
subscript(_: Int) -> (String,Mirror) { _fatalError("Mirror access out of bounds") }
|
|
|
|
var summary: String { return _value.description }
|
|
|
|
var quickLookObject: QuickLookObject? {
|
|
// this code comes straight from the quicklooks
|
|
|
|
if let data = (_value as AnyObject)._copyImageData?() {
|
|
// we could send a Raw, but I don't want to make a copy of the bytes for no good reason
|
|
// make an NSImage out of them and send that
|
|
let img = NSImage(data: data)
|
|
return .Some(.Sprite(img))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var disposition : MirrorDisposition { get { return .Aggregate } }
|
|
}
|
|
|
|
struct _SKTextureMirror : Mirror {
|
|
var _value : SKTexture
|
|
|
|
init(_ _v : SKTexture) {
|
|
_value = _v
|
|
}
|
|
|
|
var value : Any { return (_value as Any)}
|
|
|
|
var valueType: Any.Type { return (_value as Any).dynamicType }
|
|
|
|
var objectIdentifier: ObjectIdentifier? { return .None }
|
|
|
|
var count: Int { return 0 }
|
|
|
|
subscript(_: Int) -> (String,Mirror) { _fatalError("Mirror access out of bounds") }
|
|
|
|
var summary: String { return _value.description }
|
|
|
|
var quickLookObject: QuickLookObject? {
|
|
// this code comes straight from the quicklooks
|
|
|
|
if let data = (_value as AnyObject)._copyImageData?() {
|
|
// we could send a Raw, but I don't want to make a copy of the bytes for no good reason
|
|
// make an NSImage out of them and send that
|
|
let img = NSImage(data: data)
|
|
return .Some(.Sprite(img))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var disposition : MirrorDisposition { get { return .Aggregate } }
|
|
}
|
|
|
|
extension SKShapeNode : Reflectable {
|
|
@public func getMirror() -> Mirror {
|
|
return _SKShapeNodeMirror(self)
|
|
}
|
|
}
|
|
|
|
extension SKSpriteNode : Reflectable {
|
|
@public func getMirror() -> Mirror {
|
|
return _SKSpriteNodeMirror(self)
|
|
}
|
|
}
|
|
extension SKTextureAtlas : Reflectable {
|
|
@public func getMirror() -> Mirror {
|
|
return _SKTextureAtlasMirror(self)
|
|
}
|
|
}
|
|
extension SKTexture : Reflectable {
|
|
@public func getMirror() -> Mirror {
|
|
return _SKTextureMirror(self)
|
|
}
|
|
}
|
|
#elseif os(iOS)
|
|
// FIXME: we want to interop nicely with SpriteKit on iOS as well
|
|
#endif
|
|
|
|
extension SKNode {
|
|
@public subscript (name: String) -> [SKNode] {
|
|
var nodes = [SKNode]()
|
|
enumerateChildNodesWithName(name) { node, stop in
|
|
if let n = node { nodes.append(n) }
|
|
}
|
|
return nodes
|
|
}
|
|
}
|
|
|