mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Keep calm: remember that the standard library has many more public exports than the average target, and that this contains ALL of them at once. I also deliberately tried to tag nearly every top-level decl, even if that was just to explicitly mark things @internal, to make sure I didn't miss something. This does export more than we might want to, mostly for protocol conformance reasons, along with our simple-but-limiting typealias rule. I tried to also mark things private where possible, but it's really going to be up to the standard library owners to get this right. This is also only validated against top-level access control; I haven't fully tested against member-level access control yet, and none of our semantic restrictions are in place. Along the way I also noticed bits of stdlib cruft; to keep this patch understandable, I didn't change any of them. Swift SVN r19145
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
|
|
}
|
|
}
|
|
|