Skip to content

Commit

Permalink
Merge branch '4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
migueldeicaza committed Sep 7, 2023
2 parents 94ebf26 + 3862d58 commit cf27141
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Generator/Generator/ClassGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func generateClasses (values: [JGodotExtensionAPIClass], outputDir: String) {

func generateSignalType (_ p: Printer, _ cdef: JGodotExtensionAPIClass, _ signal: JGodotSignal, _ name: String) -> String {
doc (p, cdef, "Signal support.\n")
doc (p, cdef, "Use the ``\(name)/connect`` method to connect to the signal on the container object, and ``\(name)/disconnect`` to drop the connection.\nYou can also await the ``\(name)/emitted`` property for waiting for a single emission of the signal.")
doc (p, cdef, "Use the ``\(name)/connect(flags:_:)`` method to connect to the signal on the container object, and ``\(name)/disconnect(_:)`` to drop the connection.\nYou can also await the ``\(name)/emitted`` property for waiting for a single emission of the signal.")

var lambdaFull = ""
p ("public class \(name)") {
Expand Down Expand Up @@ -498,7 +498,7 @@ func generateSignalType (_ p: Printer, _ cdef: JGodotExtensionAPIClass, _ signal
p ("return signalProxy")
}

doc (p, cdef, "Disconnects a signal that was previously connected, the return value from calling ``connect``")
doc (p, cdef, "Disconnects a signal that was previously connected, the return value from calling ``connect(flags:_:)``")
p ("public func disconnect (_ token: Object)") {
p ("target.disconnect(signal: signalName, callable: Callable (object: token, method: SignalProxy.proxyName))")
}
Expand Down
1 change: 1 addition & 0 deletions Generator/Generator/MethodGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func isRefParameterOptional (className: String, method: String, arg: String) ->
}
}


/// Generates a method definition
/// - Parameters:
/// - p: Our printer to generate the method
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/Core/ClassServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ClassInfo<T:Object> {
}

/// Registers a signal on this type with the specified name and with the specified arguments. To trigger
/// the signal, you need to invoke ``Object/emitSignal(signal:)`` with the matching arguments that
/// the signal, you need to invoke ``Object/emitSignal(signal:_:)`` with the matching arguments that
/// you registered here.
///
/// Users of your signal can then connect to the signal using the ``Object/connect(signal:callable:flags:)``
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/Core/SignalSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class SimpleSignal {
return signalProxy
}

/// Disconnects a signal that was previously connected, the return value from calling ``connect``
/// Disconnects a signal that was previously connected, the return value from calling ``connect(flags:_:)``
public func disconnect (_ token: Object) {
target.disconnect(signal: signalName, callable: Callable (object: token, method: SignalProxy.proxyName))
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/Core/Various.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public extension ProjectSettings {
}

public extension TextServer {
/// **Warning:** This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their ``CanvasItem.visible`` property. ``SwiftGodot``
/// **Warning:** This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their ``CanvasItem/visible`` property. ``SwiftGodot``
func demo () {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// main.swift
// SimpleGodotApp
//
// Created by Miguel de Icaza on 9/6/23.
//

import Foundation
import SwiftGodotKit
import SwiftGodot


func loadScene (scene: SceneTree) {
let rootNode = Node3D()
let camera = Camera3D ()
camera.current = true
camera.position = Vector3(x: 0, y: 0, z: 2)

rootNode.addChild(node: camera)

func makeCuteNode (_ pos: Vector3) -> Node {
let n = SpinningCube()
n.position = pos
return n
}
rootNode.addChild(node: makeCuteNode(Vector3(x: 1, y: 1, z: 1)))
rootNode.addChild(node: makeCuteNode(Vector3(x: -1, y: -1, z: -1)))
rootNode.addChild(node: makeCuteNode(Vector3(x: 0, y: 1, z: 1)))
scene.root?.addChild(node: rootNode)
}


class SpinningCube: Node3D {
required init (nativeHandle: UnsafeRawPointer) {
super.init (nativeHandle: nativeHandle)
}

required init () {
super.init ()
let meshRender = MeshInstance3D()
meshRender.mesh = BoxMesh()
addChild(node: meshRender)
}

override func _input (event: InputEvent) {
guard event.isPressed () && !event.isEcho () else { return }
print ("SpinningCube: event: isPressed ")
}

public override func _process(delta: Double) {
rotateY(angle: delta)
}
}

func registerTypes (level: GDExtension.InitializationLevel) {
switch level {
case .scene:
register (type: SpinningCube.self)
default:
break
}
}

runGodot(args: [], initHook: registerTypes, loadScene: loadScene, loadProjectSettings: { settings in })
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions Sources/SwiftGodot/SwiftGodot.docc/Signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In SwiftGodot, there is a convenient interface to connect to a signal, as well
as a low-level framework to manually connect to signals and a mechanism to
define your own signals.

Objects that emit signals typically do so by using the ``Object/emitSignal``
Objects that emit signals typically do so by using the ``Object/emitSignal(signal:_:)``
function which takes as a parameter the ``StringName`` of the signal as well
as an optional list of additional arguments. And users can connect to those
signals and direct a method to be invoked when they are raised.
Expand Down Expand Up @@ -65,7 +65,7 @@ One common idiom in Godot code is to wait for a signal to be raised before
continuing execution. For example, you might want to wait for a timeout
or an action.

In those cases, you can await the ``emitted`` property of the generated
In those cases, you can await the `emitted` property of the generated
signal, like this:

```
Expand Down Expand Up @@ -130,7 +130,7 @@ We start by declaring the ``StringName`` for the signal that we are
declaring, in this case `burp`. Since signals are registered for classes,
we use an idiom to initialize the class once. This will use ``ClassInfo``
to declare our signal, and we register it there. Since this is a signal
that takes no arguments, merely calling ``ClassInfo/registerSignal`` is enough.
that takes no arguments, merely calling ``ClassInfo/registerSignal(name:arguments:)`` is enough.

The method `emitBurp` shows what you need to do to emit the signal from
your code.
Expand Down Expand Up @@ -199,7 +199,7 @@ if you need to connect to objects that are not included in the binding
or you want to implement additional semantics, you can always use the
low-level API for connecting signals.

To connect a signal directly, you use the ``Object/connect``
To connect a signal directly, you use the ``Object/connect(signal:callable:flags:)``
method. The first parameter is the ``StringName`` describing the signal
and the second one is refenrece to the method to invoke. The ``Callable``
is a pair of the object instance and the ``StringName`` of the method to invoke.
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftGodot/SwiftGodot.docc/SwiftGodot Tutorials.tutorial
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@
@TutorialReference(tutorial: "doc:Your-First-Extension")
@TutorialReference(tutorial: "doc:Writing-Multiple-Scripts")
}

@Chapter(name: "Embedding Godot in Swift") {
If rather than embedding Swift into Godot, you want to embed Godot into
your Swift application or you prefer to prototype your code with
a code-first approach, you can use the companion SwiftGodotKit.

@Image(source: "Birdie2",
alt: "A pixel art sprite of a person wearing a bird costume similar to the Swift logo.")

@TutorialReference(tutorial: "doc:Using-Swift-Godot-Kit")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@Tutorial(time: 5) {
@Intro(title: "Using SwiftGodotKit") {
SwiftGodotKit lets you drive Godot entirely from Swift, and treat Godot as just another Swift framework you can call into.

@Image(source: "RunnerHeader.png",
alt: "A screenshot of the Simple Runner game. The player wears a bird costume and runs alongside boxes.")
}

@Section(title: "SwiftGodotKit from Xcode") {
@ContentAndMedia {
Using Godot as a library using SwiftGodotKit
}

@Steps {
@Step {
In Xcode, create a new project. In our example, we are going to create a new MacOS project and make this a command line tool. You can use other options, but this shows the most minimal project you can create.

@Image(source: "SwiftGodotKit-Xcode-1-MacOS-NewProject.png",
alt: "Xcode New MacOS Project dialog showing a Command Line Tool")
}
@Step {
You will now Add a dependency on the `SwiftGodotKit` library.
}

@Step {
To do this, after you create your project, select your project from the navigator, and go to "Package Dependencies". There click the "+" button and when the package selector comes up, enter the URL for the SwiftGodotKit package: https://github.com/migueldeicaza/SwiftGodotKit

@Image(source: "SwiftGodotKit-Xcode-2-AddPackage.png",
alt: "Adding the package to the project")
}

@Step {
The SwiftGodotKit package comes with various samples, you only need the SwiftGodotKit package to be added to your project, so you can safely set all the Package Products to "None" in the "Add to Target" column

@Image(source: "SwiftGodotKit-Xcode-3-AddTarget.png",
alt: "Dialog showing which package products are available from SwiftGodotKit")
}

@Step {
Since this contains a native library that has not been signed, go to your "Signing & Capabilities" tab for your target, and in the "Hardened Runtime" which is checked-in by default, enable the "Disable Library Validation". Alternatively, you can remove the "Hardened Runtime".

@Image(source: "SwiftGodotKit-Xcode-4-HardenedRuntime.png",
alt: "Two Finder windows that show the dynamic library files being copied to the game's files.")
}

@Step {
You can now enter a sample SwiftGodot project. This needs to import both the `SwiftGodotKit` API which provides one entry point: the `runGodot` method, and the `SwiftGodot` API, that contains the bulk of the code.

@Code(name: "SwiftGodotKit-Main.swift",
file: "SwiftGodotKit-Main.swift")
}
}
}

}
6 changes: 3 additions & 3 deletions Sources/SwiftGodot/SwiftGodot.docc/Variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Follow up on the fundamental building block of Godot's data types.

You will often find the type ``Variant`` in Godot source code. Variants are
Godot's way of passing around certain data types. They are similar to Swift's
``Any`` type, but they can only hold Godot types (most structures and classes
`Any` type, but they can only hold Godot types (most structures and classes
that derive from ``GodotObject``).

## Creating Variant values
Expand All @@ -27,7 +27,7 @@ let trueVaraint = Variant (true)
```

You can get a string representation of a variant by calling ``Variant``'s
``description`` method:
``Variant/description`` method:

```swift
print (trueVariant.description)
Expand Down Expand Up @@ -56,7 +56,7 @@ type of the variant by accessing the `.gtype` property of the variant.
## Extracting Godot-derived objects from Variants

Godot-derived objects are slightly different. If you know you have a
``GodotObject`` stored in the variant, you can call the ``Variant.asObject()``
``GodotObject`` stored in the variant, you can call the ``Variant/asObject()``
instead. This is a generic method, so you would invoke it like this:

```swift
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftGodot/Variant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Foundation
/// - Can be used for dictionaries, arrays, parsers, etc.
///
/// > Note: Containers (``GArray`` and ``Dictionary``): Both are implemented using variants.
/// A ``Dictionary`` can match any datatype used as key to any other datatype. An ``GArray`
/// A ``Dictionary`` can match any datatype used as key to any other datatype. An ``GArray``
/// just holds an array of Variants. A ``Variant`` can also hold a ``Dictionary`` and an ``Array``
/// inside.
///
Expand Down

0 comments on commit cf27141

Please sign in to comment.