-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 4.3 project update... apparently opening the project did this ¯\_(ツ)_/¯ * Simplified SimpleExtension. Moved manual registration example to ManualExtension.
- Loading branch information
Showing
7 changed files
with
144 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[configuration] | ||
entry_symbol = "swift_entry_point" | ||
compatibility_minimum = 4.2 | ||
|
||
|
||
[libraries] | ||
macos.debug = "res://bin/ManualExtension" | ||
macos.release = "res://bin/ManualExtension" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# ManualExtension | ||
|
||
This example extension shows how you can write custom registration code | ||
for your extension, to do more complicated things. | ||
|
||
For a simpler example, see SimpleExtension. | ||
|
||
The code is contained in ManualExtension.swift, the package definition | ||
is contained by ../Package.swift and you must copy the | ||
resulting binary (ManualExtension) into the bin directory | ||
of your Godot project and place the ManualExtension.gdextension file | ||
in the Godot project root. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Demo.swift | ||
// | ||
// Created by Miguel de Icaza on 4/4/23. | ||
// | ||
|
||
import Foundation | ||
import SwiftGodot | ||
|
||
var sequence = 0 | ||
|
||
@Godot | ||
class Rigid: RigidBody2D { | ||
override func _integrateForces(state: PhysicsDirectBodyState2D?) { | ||
guard let xform = state?.transform else { | ||
return | ||
} | ||
print (xform) | ||
} | ||
} | ||
|
||
@Godot | ||
class SwiftSprite: Sprite2D { | ||
var time_passed: Double = 0 | ||
var count: Int = 0 | ||
|
||
@Signal var pickedUpItem: SignalWithArguments<String, Bool, Int> | ||
@Signal var scored: SimpleSignal | ||
@Signal var livesChanged: SignalWithArguments<Int> | ||
|
||
@Callable | ||
public func computeGodot (x: String, y: Int) -> Double { | ||
return 1.0 | ||
} | ||
|
||
@Callable | ||
public func wink () { | ||
print ("Wink") | ||
} | ||
|
||
@Callable | ||
public func computerSimple (_ x: Int, _ y: Int) -> Double { | ||
return Double (x + y) | ||
} | ||
|
||
@Callable | ||
func returnNullable () -> String? { | ||
let x: Variant = Variant (1) | ||
if let y: Resource = x.asObject () { | ||
print ("Y is = \(y)") | ||
} | ||
return nil | ||
} | ||
|
||
@Export var resource: Resource? | ||
@Export(.dir) var directory: String? | ||
@Export(.file, "*txt") var file: String? | ||
@Export var demo: String = "demo" | ||
@Export var food: String = "none" | ||
|
||
var x: Rigid? | ||
|
||
override func _process (delta: Double) { | ||
time_passed += delta | ||
|
||
if x == nil { | ||
self.x = Rigid() | ||
} | ||
guard let imageVariant = ProjectSettings.getSetting(name: "shader_globals/heightmap", defaultValue: Variant(-1)) else { | ||
return | ||
} | ||
|
||
GD.print("Found this value IMAGE: \(imageVariant.gtype) variant: \(imageVariant) desc: \(imageVariant.description)") | ||
|
||
let dict2: GDictionary? = GDictionary(imageVariant) | ||
GD.print("dictionary2: \(String(describing: dict2)) \(dict2?["type"]?.description ?? "no type") \(dict2?["value"]?.description ?? "no value")") | ||
|
||
// part b | ||
if let result = dict2?.get(key: Variant("type"), default: Variant(-1)) { | ||
let value = String(result) ?? "No Result" | ||
GD.print("2 Found this value \(value)") | ||
} | ||
|
||
let lerp = Double(0.1).lerp(to: 10, weight: 1) | ||
print ("Lerp result from 0.1 to 10 weight:1 => \(lerp)") | ||
let newPos = Vector2(x: Float (10 + (10 * sin(time_passed * 2.0))), | ||
y: Float (10.0 + (10.0 * cos(time_passed * 1.5)))) | ||
|
||
self.position = newPos | ||
} | ||
} |